Class: ARBACVerifier::Rules::CanRevoke

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_role, target_role) ⇒ CanRevoke

Returns a new instance of CanRevoke.



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

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

Instance Attribute Details

#target_roleObject (readonly)

Returns the value of attribute target_role.



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

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_revoke.rb', line 11

def user_role
  @user_role
end

Instance Method Details

#apply(state, revokee) ⇒ Object



37
38
39
40
# File 'lib/arbac_verifier/classes/rules/can_revoke.rb', line 37

def apply(state, revokee)
  new_state = state.dup
  new_state.delete_if{ |ur| ur.user == revokee and ur.role == @target_role }
end

#can_apply?(state, revoker, revokee) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/arbac_verifier/classes/rules/can_revoke.rb', line 27

def can_apply?(state, revoker, revokee)
  assigner_has_rights = state.to_a.any?{ |ur| ur.user == revoker and ur.role == @user_role}
  assignee_has_revoking_role = state.to_a.any?{ |ur| ur.user == revokee and ur.role == target_role}
  assigner_has_rights and assignee_has_revoking_role
end