Class: Authorization::DevelopmentSupport::ChangeSupporter::AssignPrivilegeToRoleAction
- Inherits:
-
AbstractAction
- Object
- AbstractAction
- Authorization::DevelopmentSupport::ChangeSupporter::AssignPrivilegeToRoleAction
- Defined in:
- lib/declarative_authorization/development_support/change_supporter.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#privilege ⇒ Object
readonly
Returns the value of attribute privilege.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(candidate) ⇒ Object
-
#initialize(privilege_sym, context, role_sym) ⇒ AssignPrivilegeToRoleAction
constructor
A new instance of AssignPrivilegeToRoleAction.
- #reverse?(other) ⇒ Boolean
- #to_a ⇒ Object
Methods inherited from AbstractAction
#eql?, #hash, #inspect, readable_info, #resembles?, #resembles_any?, #weight
Constructor Details
#initialize(privilege_sym, context, role_sym) ⇒ AssignPrivilegeToRoleAction
Returns a new instance of AssignPrivilegeToRoleAction.
329 330 331 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 329 def initialize (privilege_sym, context, role_sym) @privilege, @context, @role = privilege_sym, context, role_sym end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
328 329 330 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 328 def context @context end |
#privilege ⇒ Object (readonly)
Returns the value of attribute privilege.
328 329 330 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 328 def privilege @privilege end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
328 329 330 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 328 def role @role end |
Class Method Details
.specific_actions(candidate) ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 314 def self.specific_actions (candidate) privilege = AnalyzerEngine::Privilege.for_sym( candidate.failed_tests.first.privilege, candidate.engine) context = candidate.failed_tests.first.context user = candidate.failed_tests.first.user ([privilege] + privilege.ancestors).collect do |ancestor_privilege| user.role_symbols.collect {|role_sym| AnalyzerEngine::Role.for_sym(role_sym, candidate.engine) }. collect {|role| [role] + role.ancestors}.flatten.uniq.collect do |role| # apply checks later if privilege is already present in that role new(ancestor_privilege.to_sym, context, role.to_sym) end end.flatten end |
Instance Method Details
#apply(candidate) ⇒ Object
333 334 335 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 333 def apply (candidate) AnalyzerEngine.apply_change(candidate.engine, to_a) end |
#reverse?(other) ⇒ Boolean
337 338 339 340 341 342 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 337 def reverse? (other) other.is_a?(RemovePrivilegeFromRoleAction) and other.privilege == @privilege and other.context == @context and other.role == @role end |
#to_a ⇒ Object
344 345 346 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 344 def to_a [:add_privilege, @privilege, @context, @role] end |