Class: ARBACVerifier::Rules::CanAssign

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/arbac_verifier/classes/rules/can_assign.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_role, positive_precondition_roles, negative_precondition_roles, target_role) ⇒ CanAssign

Returns a new instance of CanAssign.



28
29
30
31
32
33
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 28

def initialize(user_role, positive_precondition_roles, negative_precondition_roles, target_role)
  @user_role = user_role
  @positive_precondition_roles = positive_precondition_roles
  @negative_precondition_roles = negative_precondition_roles
  @target_role = target_role
end

Instance Attribute Details

#negative_precondition_rolesObject (readonly)

Returns the value of attribute negative_precondition_roles.



17
18
19
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 17

def negative_precondition_roles
  @negative_precondition_roles
end

#positive_precondition_rolesObject (readonly)

Returns the value of attribute positive_precondition_roles.



14
15
16
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 14

def positive_precondition_roles
  @positive_precondition_roles
end

#target_roleObject (readonly)

Returns the value of attribute target_role.



20
21
22
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 20

def target_role
  @target_role
end

#user_roleObject (readonly)

Returns the value of attribute user_role.



11
12
13
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 11

def user_role
  @user_role
end

Instance Method Details

#apply(state, assignee) ⇒ Object



52
53
54
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 52

def apply(state, assignee)
  state | [UserRole.new(assignee, @target_role)]
end

#can_apply?(state, assigner, assignee) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/arbac_verifier/classes/rules/can_assign.rb', line 40

def can_apply?(state, assigner, assignee)
  assigner_has_rights = state.to_a.any?{ |ur| ur.user == assigner and ur.role == @user_role}
  assignee_roles = state.select { |ur| ur.user == assignee}.map { |ar| ar.role }.to_set
  assigner_has_rights and
    positive_precondition_roles.subset? assignee_roles and
    !negative_precondition_roles.intersect? assignee_roles
end