class Authorization::DevelopmentSupport::ChangeSupporter::AssignPrivilegeToRoleAction

Attributes

context[R]
privilege[R]
role[R]

Public Class Methods

new(privilege_sym, context, role_sym) click to toggle source
# 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
specific_actions(candidate) click to toggle source
# 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

Public Instance Methods

apply(candidate) click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 333
def apply (candidate)
  AnalyzerEngine.apply_change(candidate.engine, to_a)
end
reverse?(other) click to toggle source
# 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() click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 344
def to_a
  [:add_privilege, @privilege, @context, @role]
end