elabs/pundit: Minimal authorization through OO design and pure Ruby classes - 0 views
-
The class implements some kind of query method
- ...49 more annotations...
-
in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scaleable authorization system
-
authorize would have done something like this: raise "not authorized" unless PostPolicy.new(current_user, @post).update?
-
pass a second argument to authorize if the name of the permission you want to check doesn't match the action name.
-
Instances of this class respond to the method resolve, which should return some kind of result which can be iterated over.
-
scope.where(published: true)
-
verify_policy_scoped to your controller. This will raise an exception in the vein of verify_authorized. However, it tracks if policy_scope is used instead of authorize
-
Having a mechanism that ensures authorization happens allows developers to thoroughly test authorization scenarios as units on the policy objects themselves.
-
Pundit doesn't do anything you couldn't have easily done yourself. It's a very small library, it just provides a few neat helpers.
-
Pundit strongly encourages you to model your application in such a way that the only context you need for authorization is a user object and a domain model that you want to check authorization for.
-
If you have defined an action-specific method on your policy for the current action, the permitted_attributes helper will call it instead of calling permitted_attributes on your controller
-
Given there is a policy without a corresponding model / ruby class, you can retrieve it by passing a symbol