Class: Checkpoint::Query::ActionPermitted

Inherits:
Object
  • Object
show all
Defined in:
lib/checkpoint/query/action_permitted.rb

Overview

ActionPermitted is a predicate query that captures the user, action, and target, and checks if the authority permits the action. It is likely to be the most commonly issued query in any given application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, action, target = Checkpoint::Resource.all, authority: Authority::RejectAll.new) ⇒ ActionPermitted

Returns a new instance of ActionPermitted.

Parameters:

  • user (<application actor>)

    the acting user/account

  • action (String|Symbol)

    the action to be taken; this will be forced to a symbol

  • target (<application entity>) (defaults to: Checkpoint::Resource.all)

    the object or application resource to be acted upon; defaults to Resource.all to ease checking for zone-/system-wide permission.

  • authority (Checkpoint::Authority) (defaults to: Authority::RejectAll.new)

    the authority to ask about this permission



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/checkpoint/query/action_permitted.rb', line 19

def initialize(
  user,
  action,
  target = Checkpoint::Resource.all,
  authority: Authority::RejectAll.new)

  @user      = user
  @action    = action.to_sym
  @target    = target
  @authority = authority
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def action
  @action
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def target
  @target
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def user
  @user
end

Instance Method Details

#true?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/checkpoint/query/action_permitted.rb', line 31

def true?
  authority.permits?(user, action, target)
end