Module: Authorule::PermissionAccessors

Included in:
PermissionHolder
Defined in:
lib/authorule/permission_accessors.rb

Overview

Provides methods ‘may?’, ‘may_access?’ and their negative counterparts. You must make sure to implement method ‘has_permission?’ in your class.

Instance Method Summary collapse

Instance Method Details

#may?(action, target) ⇒ Boolean

Determines whether a holder in this group may perform the specified action on the specified target.

Parameters:

  • action (#to_s)

    The action to perform. The available actions differ per permissions. The full list can be found in UI::Permission.

  • 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.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
# 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) ⇒ Boolean

Checks a permission without querying a specific action.

Returns:

  • (Boolean)

See Also:



26
27
28
29
# File 'lib/authorule/permission_accessors.rb', line 26

def may_access?(target)
  permission = Authorule.resolve(target)
  has_permission? permission
end

#may_not?(action, target) ⇒ Boolean

Determines whether a holder may not perform the specified action on the specified target.

Returns:

  • (Boolean)

See Also:



33
34
35
# File 'lib/authorule/permission_accessors.rb', line 33

def may_not?(action, target)
  !may?(action, target)
end

#may_not_access?(target) ⇒ Boolean

Determines whether a holder may not access the specified target.

Returns:

  • (Boolean)

See Also:



40
41
42
# File 'lib/authorule/permission_accessors.rb', line 40

def may_not_access?(target)
  !may_access?(target)
end