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

add hook for action policy #917

Merged
merged 3 commits into from Nov 12, 2021

Conversation

lHydra
Copy link
Contributor

@lHydra lHydra commented Oct 29, 2021

Added a hook for Action Policy

The setup is similar to Pundit, so I decided not to split the README description into two sections

@lHydra
Copy link
Contributor Author

lHydra commented Oct 29, 2021

@palkan take a point about choosing a method to set current user method, i'm feeling embarrased that I call it with @controller.class.authorize

lib/ckeditor/hooks/action_policy.rb Outdated Show resolved Hide resolved
# action as a symbol (:create, :destroy, etc.). The second argument is the actual model
# instance if it is available.
def authorize(action, model_object = nil)
@controller.authorize!(model_object)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an action?

Suggested change
@controller.authorize!(model_object)
@controller.authorize!(model_object, to: :"#{action}?")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it’s necessary. We can get the name of the action dynamically

if action
@controller.allowed_to?(:"#{action}?",
model_object,
context: {user: @controller.current_user_for_action_policy})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use ckeditor_current_user directly? That would eliminate the need for ControllerExtension

Suggested change
context: {user: @controller.current_user_for_action_policy})
context: {user: @controller.ckeditor_current_user})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to repeat the adapter interface for Pundit. I think this is done if we may need additional user manipulation for a specific adapter. But I agree that now it looks redundant. Do I need to change it there too?

@lHydra
Copy link
Contributor Author

lHydra commented Nov 11, 2021

Hi @galetahub! Can you see the changes? Thanks!

@galetahub galetahub merged commit 44d6351 into galetahub:master Nov 12, 2021
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.

None yet

3 participants