module Authorule::PermissionAccessors
Provides methods ‘may?’, ‘may_access?’ and their negative counterparts. You must make sure to implement method ‘has_permission?’ in your class.
Public Instance Methods
may?(action, target)
click to toggle source
Determines whether a holder in this group may perform the specified action on the specified target.
@param [#to_s] action
The action to perform. The available actions differ per permissions. The full list can be found in {UI::Permission}.
@param target
The target the holder wishes to operate on. This target may be any object and is passed to the UI permission checker as is, which will convert it into a permission path.
# File lib/authorule/permission_accessors.rb, line 15 def may?(action, target) permission = Authorule.resolve(target, action) unless permission.available_actions.try(:include?, action) raise ArgumentError, "action :#{action} not available for permission of kind :#{permission.class.kind}" end has_permission? permission end
may_access?(target)
click to toggle source
Checks a permission without querying a specific action. @see may?
# File lib/authorule/permission_accessors.rb, line 26 def may_access?(target) permission = Authorule.resolve(target) has_permission? permission end
may_not?(action, target)
click to toggle source
Determines whether a holder may not perform the specified action on the specified target. @see may?
# File lib/authorule/permission_accessors.rb, line 33 def may_not?(action, target) !may?(action, target) end