Skip to content

Only validate the address on the Admin User page when it changes - #1479

Merged
ardalis merged 1 commit into
mainfrom
issue-1422-admin-address-validation
Nov 2, 2026
Merged

ardalis merged 1 commit into
mainfrom
issue-1422-admin-address-validation

Conversation

@ardalis

@ardalis ardalis commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1422. Replaces draft #1423, which should be closed rather than merged.

Why

#1469 fixed the blank userId, the raw JSON errors, and members with no address at all, but two parts of the issue were still open:

  • Address validation fired even when the address wasn't touched. A member with an incomplete stored address, or only the legacy Member.Address value, couldn't have just their name or email changed. The issue's payload, where only Address is missing, is this case.
  • Nothing validated on the client. The page never loaded the validation scripts.

Changes

Server (Pages/Admin/User.cshtml.cs)

  • The address is only validated and saved when it differs from the stored value, ignoring surrounding whitespace and line-ending style.
  • A blank State is stored as "". A null State made EF read the whole owned ShippingAddress back as null. This reproduced on SQLite with the same mapping, not on SQL Server.
  • Blanking every field on a member with a ShippingAddress leaves both addresses untouched. It used to clear only Member.Address.

Shared model (UserPersonalUpdateModel)

  • Adds [StringLength] limits matching the address columns, so over-length values get a validation error instead of a database exception. This also applies to the member profile page. [Required] stays, so that page's address rules are otherwise unchanged.

Client (Pages/Admin/User.cshtml, wwwroot/js/admin-user.js)

  • Loads jQuery Validate on the page, with address required rules matching the server's.
  • Adds StartDate messages to the subscription modals, which now also validate on the client.

Testing

  • Added 8 handler tests and the AddressFieldLengths tests.
  • All tests pass: 3 functional, 118 in DevBetterWeb.Tests, 154 unit.
  • dotnet format is clean for the changed C# files.
  • The client rules passed 9 scenarios in jsdom using the real jQuery Validation libraries. That script isn't committed because the repo has no JS test project.
  • Not tested end to end: the page wasn't run in a browser or against SQL Server. Please try a name-only save and a partial address edit on /Admin/User.

Known limitations

  • After the server rejects a save, the client compares against the submitted values rather than the stored ones. The server still decides, so nothing invalid is saved.
  • Blanking every address field can't remove an existing ShippingAddress. The save succeeds and the address reappears, same as before this PR.
  • An invalid stored Discord username still blocks saving, with an inline error.
  • MyProfile/Personal has the same null State bug. It's outside this issue and isn't fixed here.

Review

A separate agent reviewed the change; its findings and how each was handled are in the plan file. /codex:review, required by CLAUDE.md, was not run because neither the plugin nor the codex CLI was available.

🤖 Generated with Claude Code

Follows up #1469. Saving a member's name or email was still blocked when
their stored address was incomplete or held only the legacy Address
value, which is the case in the issue's error payload. The page also
never loaded the validation scripts, so nothing fired on the client.

- Skip address validation and updates when the submitted address matches
  the stored one, ignoring surrounding whitespace and line-ending style.
- Load jQuery Validate on the page, with address required rules matching
  the server's.
- Store a blank State as an empty string. A null State made EF read the
  whole owned ShippingAddress back as null.
- Leave the addresses untouched when every field is blanked on a member
  with a ShippingAddress, instead of clearing only Member.Address.
- Add length validation to the address fields so over-length values no
  longer reach the database.

Fixes #1422

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ardalis
ardalis force-pushed the issue-1422-admin-address-validation branch from 0eb11aa to 8e33bf7 Compare November 2, 2026 03:28
@ardalis
ardalis merged commit e56aa02 into main Nov 2, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Updating a user to try to set their name and email and the address validation fires

1 participant