Afform: Gate admin PriceFieldValues on Forms - #36434
Open
rbaugh wants to merge 2 commits into
Open
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
rbaugh
force-pushed
the
afform-visibility-pricefieldvalues
branch
from
August 7, 2026 16:02
c23f2b4 to
61cf026
Compare
…howing in form normalize field
rbaugh
force-pushed
the
afform-visibility-pricefieldvalues
branch
from
August 7, 2026 16:37
61cf026 to
f73d30b
Compare
Contributor
Author
|
retest this please |
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.
Overview
PriceFieldValuehas a property that specifies if the value should be public or admin. This is a core setting and the public/admin are defined by default. In QuickForm, these values are hidden on forms when the user does not haveedit contributionpermission. On Afform, these values are being leaked to the form regardless of the user's permissions.Before
All PriceFieldValues are shown for a PriceField.
After
PriceFieldValues are limited to the user based on their permission.
Technical Details
In PR #35572 we introduced the ability to use
af-ifstatements for each option, for option based fields. This PR leverages that work and injects anaf-ifcondition onPriceFieldValuesthat have thevisibility_id:name = 'admin'. It then uses thecivi.afform.prefillandcivi.api.respondto populate a property (has_all_price_options) on each entity, in which aPriceFieldcan be added. The property is only added if the current user has theedit contributionpermission. Theaf-iflogic then looks for the property from the prefill/response to determine if it should show the value to the user.While this does still expose the
PriceFieldValueto theaf-entityrendered to the browser, it is at least preventing the select option/radio/checkbox from being rendered if the user doesn't have the correct permission. If for some reason it is exposed or some user can force a submission with the value selected, the submission will enforce the validity of the value in use for the user.Currently this is also an issue with the base
OptionValue, but that is more complex in that we don't know what permission should be applied to each. The basicOptionValuerecords typically don't even have this field set as the core add/edit screen doesn't even expose the field to the UI. Normally this is only set through something that extends theOptionValue, likePriceFieldValue, or via some API/code generation in which it would be set. We likely need to look at patching those as well, but currently nothing in core is preventing these on any QuickForm either.cc: @mattwire @colemanw