Spike use of presenters during serialization #950
Closed
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
This is a spike on top of #917 (and #951, #952) experimenting with using Presenters to solve the problem of conditionally showing attributes based on authorization policies.
What, How
BasePresenter
with some functionality useful across presenterspresent
helper method for use in erb templatesPersonPolicy
that allowed guest users access to any other Person w/o an associated userperson.name
on/contributions
by not trying to split the nameContributionPresenter
and thread it into the serialization process inContributionsController#index
PersonPresenter
, use it inContributionPresenter
and have it conditionally show the name based onPersonPolicy
.Probably easiest to review each commit individually.
Testing
Adds some specs for new code.
Next Steps
Outstanding Questions, Concerns and Other Notes
This solution works and feels like the right place to put logic.
However i wonder how it would scale when we need to conditionally show more than one attribute. Feels like we may need something analogous to
permitted_attributes
which lists all attributes allowed to be submitted, but in this case, a listing of attributes allowed to be shown. Maybe avisible_attributes
method on the policy that could be used by the presenter to dynamically mask any disallowed attributes?Pre-Merge Checklist