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

Simplify calls to allowed_to? #24

Open
sauloperez opened this issue Sep 22, 2020 · 2 comments
Open

Simplify calls to allowed_to? #24

sauloperez opened this issue Sep 22, 2020 · 2 comments

Comments

@sauloperez
Copy link
Collaborator

sauloperez commented Sep 22, 2020

Due to Decidim::NeedsPermission#allowed_to?'s signature, we cannot pass in a user argument other than current_user without first passing extra_context and chain, even though we still want to use their defaults.

As a consequence, the calls to this method duplicate the permission_class_chain coupling views and other objects to it, which results in long lines and hampers changeability.

A potential solution could be to change #allowed_to? to use keyboard arguments instead so we can pass user only. If we do so, it needs to be a backward compatible-change for Decidim to accept it.

In the meantime, we could prepend somehow our own permissions class in https://github.com/decidim/decidim/blob/develop/decidim-consultations/app/controllers/decidim/consultations/application_controller.rb#L10-L13. If we go with the approach outlined in #19 of having our own controllers, we could just register a different chain that includes this new permissions class.

Originally posted by @microstudi in #15 (comment)

@sauloperez
Copy link
Collaborator Author

@sauloperez
Copy link
Collaborator Author

https://github.com/coopdevs/decidim-module-action_delegator/pull/49/files#diff-9b3fbee9f91d51262226647e0d00214b1abcc5942b5436639e514f3e62a1b460 is a great example of how this can be solved by having our own controller so we have control over the permissions chain.

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

No branches or pull requests

1 participant