10000 Support default Pundit policy class. by seban · Pull Request #3323 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Support default Pundit policy class. #3323

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

Closed
wants to merge 1 commit into from
Closed

Support default Pundit policy class. #3323

wants to merge 1 commit into from

Conversation

seban
Copy link
Contributor
@seban seban commented Aug 11, 2014

There are situations where to have default Pundit policy defined which will handle all cases here dedicated policy could not be found. Some of those cases I described in issue #3319. This PR introduces new ActiveAdmin setting pundit_default_policy which handles authorization when Pundit can't find dedicated Policy class for resource.

@seanlinsley
Copy link
Contributor

Thanks for the pull request! I haven't actually used Pundit myself; what sort of scenario is this useful for? When would Pundit not be able to find the policy class?

@seban
Copy link
Contributor Author
seban commented Aug 11, 2014

Examples from my use case:

  1. I have Hit class which basically is responsible for counting views by path in application. In my active admin dashboard I show 10 most views pages. Since I don't have policy for Hit I got error. Default policy allow me to show hits.
  2. Also in dashboard I show last activities (provided by gem public_activity), without this patch I got error undefined policy for PublicActivity::Activity class which came from gem.

Basically it helps for such cases, when you don't bother to write dedicated policy class. When user has access to AA he can see last activities, hits etc, etc. By default behaviour with default policy is disabled so it is no security flow unless you use as default policy with bug.

@seanlinsley seanlinsley changed the title Support default Pundint policy class. Support default Pundit policy class. Aug 13, 2014
@dmitry
Copy link
Contributor
dmitry commented Aug 21, 2014

Looks nice. I've spotted today to the same issue. Hopefully it will be merged. 👍

@@ -79,6 +79,8 @@ def initialize
# The authorization adapter to use
inheritable_setting :authorization_adapter, ActiveAdmin::AuthorizationAdapter

inheritable_setting :pundit_default_policy, nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of being in application.rb, this should be at the top of pundit_adapter.rb similar to cancan_adapter.rb

@timoschilling
Copy link
Member

If you change the suggestion from @seanlinsley and me, I will merge it

@@ -66,6 +66,10 @@
expect(application.allow_comments).to eq true
end

it "should set default Pundit policy class" do
application.default_pundit_policy = policy_klass
end
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't only check the setting, you should check that is set too.

timoschilling pushed a commit that referenced this pull request Nov 3, 2014
@timoschilling
Copy link
Member

merged by hand with changes suggest above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0