Skip to content

Never bind the read-only flags the admin panels set for a view - #1088

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/bind-never-server-flags
Nov 23, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/bind-never-server-flags

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

Some admin view models carry flags the server sets for the page, not values the user edits:

  • ContactAttributeModel.IsReadOnly, MessageTemplateModel.IsReadOnly — the Store panel may view a shared item but not change it;
  • AddressAttributeModel.IsGlobalAttribute, CustomerAttributeModel.IsGlobalAttribute — the same for attributes shared with other stores.

They were bindable, so a posted form or query string could set them. This is not a hole today — every write action checks access itself and the controllers set the flags again before showing a form — but ProductModel.IsReadOnly is already [BindNever] for this reason and the others were not.

ProductReviewsModel.CaptchaValid (storefront) was bindable and never read anywhere; the captcha is validated by CaptchaValidator from the settings.

Solution

  • [BindNever] on the four flags and on MessageTemplateModel.CanCopy, matching ProductModel.IsReadOnly.
  • The message template edit form shown again after a validation error sets CanCopy again from the stored template, so the Copy button no longer disappears.
  • The IsGlobalAttribute = false / IsReadOnly = false resets after a failed attribute save are removed: the flags are never bound, so they are already false there.
  • ProductReviewsModel.CaptchaValid removed.
  • ServerFlagBindingTests keeps the six flags unbound.

Breaking changes

None in this repository. ProductReviewsModel.CaptchaValid was a public property of a storefront view model; a custom theme or plugin reading it would no longer compile (no code in the repository uses it).

Testing

  1. Store panel → Content → Contact attributes (and Message templates, Address attributes, Customer attributes): open one shared with other stores — it opens read-only; open one of the store's own — it is editable and saves.
  2. Storefront: write a product review with the captcha on and off — it is validated as before.
  3. dotnet test src/Tests/Grand.Web.Admin.Tests passes.

IsReadOnly on contact attributes and message templates, and
IsGlobalAttribute on address and customer attributes, are decided by the
server from the caller's scope; every write already checks access on its
own. They are now [BindNever] like ProductModel.IsReadOnly, so a posted
form cannot set them. ProductReviewsModel.CaptchaValid was never read and
is removed.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…layed

CanCopy is decided by the server like IsReadOnly, but stayed bindable, and
the edit form shown again after a failed validation lost it, hiding the
Copy button. It is now never bound and is set again from the stored
template. The resets of IsGlobalAttribute and IsReadOnly after a failed
attribute save are gone: those flags are never bound, so they are already
false there.
var result = await controller.Edit(new MessageTemplateModel { Id = "mt-1" }, false) as ViewResult;

Assert.IsNotNull(result);
Assert.IsTrue(((MessageTemplateModel)result.Model).CanCopy);
var result = await controller.Edit(new MessageTemplateModel { Id = "mt-1" }, false) as ViewResult;

Assert.IsNotNull(result);
Assert.IsFalse(((MessageTemplateModel)result.Model).CanCopy);
@KrzysztofPajak
KrzysztofPajak merged commit 8940883 into develop Nov 23, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/bind-never-server-flags branch November 25, 2026 09:10
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.

2 participants