Fix saving personal info on the Admin User page - #1469
Merged
Merged
Conversation
Saving name/email on /Admin/User failed with a raw JSON 400: - The form's hidden userId came from UserPersonalUpdateModel.UserId, which is only set once OnGetAsync reaches the member load. Anything failing earlier (e.g. the Stripe invoice search, swallowed by the catch-all) left it blank, so every save failed "userId is required". The page now captures UserId from the route first, and invoice lookup failures are isolated and logged. - Address/City/Country/PostalCode are [Required], so members without a shipping address could not be edited. On the admin page they are now only required once any address field is filled in, and the shipping address is left untouched when none is. - Validation failures redisplay the form with the submitted values and inline errors instead of returning BadRequest(ModelState). A missing member record is reported on the page instead of throwing. Supersedes draft #1423, which changed the shared model and would also have relaxed validation on members' own profile page. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment on lines
+108
to
+111
| catch (Exception exception) | ||
| { | ||
| _logger.LogError(exception, "Unable to load Stripe invoices for userId {UserId}", userId); | ||
| } |
…from user input' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Editing a new member's name and email on
/Admin/User?userId=...failed with a raw JSON 400 instead of saving:{"UserId":["The userId field is required."],"InvalidUserId":["Bad Data"], "UserPersonalUpdateModel.City":["The City field is required."], ... , "UserPersonalUpdateModel.LastName":["The LastName field is required."]}Root causes
userId. The Personal and Links forms postedUserPersonalUpdateModel.UserId/UserLinksUpdateModel.UserId. Those are only set afterOnGetAsyncloads the member. That happens after the Stripe invoice search, inside a catch-all that swallows exceptions. If anything earlier fails, the page still renders with an empty hiddenuserIdand every save fails.[Required]. New members have no shipping address, so an admin couldn't save a name or email change without inventing an address.BadRequest(ModelState)turned any validation error into raw JSON.Changes (Admin User page only)
UserIdpage property set from the route at the start ofOnGetAsync, and uses it for the Personal and Links hidden fields.OnPostUpdatePersonalInfoAsync:MemberNotFoundException.UserPersonalUpdateModelitself is unchanged, so validation on members' own My Profile → Personal page is unaffected. That's the difference from draft #1423, which this supersedes.LastNameis still required. Members with a single name will need something entered there. That's now shown as an inline error rather than a 400.Testing
dotnet build DevBetterWeb.slnxsucceeds.DevBetterWeb.Tests: 104/104 pass. 4 new tests forOnPostUpdatePersonalInfoAsync:🤖 Generated with Claude Code