Class: Authorization::DevelopmentSupport::ChangeSupporter::AssignPrivilegeToRoleAction

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

- (AssignPrivilegeToRoleAction) initialize(privilege_sym, context, role_sym)

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

- (Object) context (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

- (Object) privilege (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

- (Object) role (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

+ (Object) specific_actions(candidate)



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

- (Object) apply(candidate)



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

- (Boolean) reverse?(other)

Returns:

  • (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

- (Object) to_a



344
345
346
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 344

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