class ActiveAdmin::AuthorizationAdapter
To view an example subclass, check out ‘ActiveAdmin::CanCanAdapter`
implementing your own authorization adapter.
for all requests to `#authorized?`. It should be the starting point for
Active Admin’s default authorization adapter. This adapter returns true
def authorized?(action, subject = nil)
-
(Boolean)
-
Parameters:
-
subject
(any
) -- The subject the action is being performed on usually this -
action
(Symbol
) -- The name of the action to perform. Usually this will be
def authorized?(action, subject = nil) true end
def initialize(resource, user)
-
user
(any
) -- The current user. The user is set to whatever is returned -
resource
(ActiveAdmin::Resource, ActiveAdmin::Page
) -- The resource
def initialize(resource, user) @resource = resource @user = user end
def normalized(klass)
end
end
true
when normalized(Post)
case subject
def authorized?(action, subject = nil)
class MyAuthAdapter < ActiveAdmin::AuthorizationAdapter
The above now becomes:
which implements `===` to be matched in a case statement.
To handle this, the normalized method takes care of returning a object
end
end
end
end
true
if subject == Post
when Class
true
when Post
case subject
def authorized?(action, subject = nil)
class MyAuthAdapter < ActiveAdmin::AuthorizationAdapter
For example:
class level match and the instance level match.
case statements for authorization since you have to handle both the
as classes of objects. This can make it much difficult to create simple
The `#authorized?` method's subject can be set to both instances as well
def normalized(klass) NormalizedMatcher.new(klass) end
def scope_collection(collection, action = Auth::READ)
-
(ActiveRecord::Relation)
- A new collection, scoped to the
Parameters:
-
action
(Symbol
) -- The name of the action to perform. Usually this will be -
collection
(ActiveRecord::Relation
) -- The collection the user is
def scope_collection(collection, action = Auth::READ) collection end