Repository navigation
Never bind the read-only flags the admin panels set for a view - #1088
Merged
Merged
Conversation
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.
…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); |
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.
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.IsReadOnlyis already[BindNever]for this reason and the others were not.ProductReviewsModel.CaptchaValid(storefront) was bindable and never read anywhere; the captcha is validated byCaptchaValidatorfrom the settings.Solution
[BindNever]on the four flags and onMessageTemplateModel.CanCopy, matchingProductModel.IsReadOnly.CanCopyagain from the stored template, so the Copy button no longer disappears.IsGlobalAttribute = false/IsReadOnly = falseresets after a failed attribute save are removed: the flags are never bound, so they are already false there.ProductReviewsModel.CaptchaValidremoved.ServerFlagBindingTestskeeps the six flags unbound.Breaking changes
None in this repository.
ProductReviewsModel.CaptchaValidwas 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
dotnet test src/Tests/Grand.Web.Admin.Testspasses.