Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike use of presenters during serialization #950

Conversation

solebared
Copy link
Collaborator

@solebared solebared commented Apr 24, 2021

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

  • Add a BasePresenter with some functionality useful across presenters
  • Add a present helper method for use in erb templates
  • Fix a bug in PersonPolicy that allowed guest users access to any other Person w/o an associated user
  • Simplify the display of person.name on /contributions by not trying to split the name
  • Add ContributionPresenter and thread it into the serialization process in ContributionsController#index
  • Add PersonPresenter, use it in ContributionPresenter and have it conditionally show the name based on PersonPolicy.

Probably easiest to review each commit individually.

Testing

Adds some specs for new code.

Next Steps

  • See thoughts below about how to support several conditional attribute.
  • ?

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 a visible_attributes method on the policy that could be used by the presenter to dynamically mask any disallowed attributes?

Pre-Merge Checklist

  • Security & accessibility have been considered
  • Tests have been added, or an explanation has been given why the features cannot be tested
  • Documentation and comments have been added to the codebase where required
  • Entry added to CHANGELOG.md if appropriate
  • Outstanding questions and concerns have been resolved
  • Any next steps have been turned into Issues or Discussions as appropriate

Experimenting with introducing presenters between controllers and
serializers. Already liking the way this simplifies the `view_path`
logic that was dispersed between the controller and serializer.
Instead of trying to split before parentheses.

We believe this was intended to hide any extra details entered by
the user, such as gender pronouns. But that format is not predictable,
and this simplifies the code.
And have ContributionPresenter decorate person with this presenter.
@solebared solebared force-pushed the spike-presenters-during-serialization branch from 8cd4b8a to c60af22 Compare April 28, 2021 23:42
@solebared solebared changed the base branch from JadeDickinson-show-contributor-name to spike-presenters-during-serialization-base April 28, 2021 23:45
@solebared
Copy link
Collaborator Author

Closing in favor of #953 .

@solebared solebared closed this May 3, 2021
@solebared solebared deleted the spike-presenters-during-serialization branch October 15, 2021 20:16
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.

1 participant