Class: Authorization::DevelopmentSupport::ChangeSupporter::RemovePrivilegeFromRoleAction

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/declarative_authorization/development_support/change_supporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractAction

#eql?, #hash, #inspect, readable_info, #resembles?, #resembles_any?, #weight

Constructor Details

#initialize(privilege_sym, context, role_sym) ⇒ RemovePrivilegeFromRoleAction

Returns a new instance of RemovePrivilegeFromRoleAction.



430
431
432
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 430

def initialize (privilege_sym, context, role_sym)
  @privilege, @context, @role = privilege_sym, context, role_sym
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



429
430
431
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 429

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



429
430
431
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 429

def privilege
  @privilege
end

#roleObject (readonly)

Returns the value of attribute role.



429
430
431
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 429

def role
  @role
end

Class Method Details

.specific_actions(candidate) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 416

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|
      new(ancestor_privilege.to_sym, context, role.to_sym)
    end
  end.flatten
end

Instance Method Details

#apply(candidate) ⇒ Object



434
435
436
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 434

def apply (candidate)
  AnalyzerEngine.apply_change(candidate.engine, to_a)
end

#reverse?(other) ⇒ Boolean

Returns:

  • (Boolean)


438
439
440
441
442
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 438

def reverse? (other)
  (other.is_a?(AssignPrivilegeToRoleAction) or
      other.is_a?(AbstractCompoundAction)) and
        other.reverse?(self)
end

#to_aObject



444
445
446
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 444

def to_a
  [:remove_privilege, @privilege, @context, @role]
end