Class: Authorization::DevelopmentSupport::ChangeSupporter::CreateAndAssignRoleToUserAction

Inherits:
AbstractCompoundAction 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 AbstractCompoundAction

#resembles?, #reverse?, #weight

Methods inherited from AbstractAction

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

Constructor Details

#initialize(user, privilege_sym, context_sym, role_sym) ⇒ CreateAndAssignRoleToUserAction

Returns a new instance of CreateAndAssignRoleToUserAction.



412
413
414
415
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 412

def initialize (user, privilege_sym, context_sym, role_sym)
  @user, @privilege, @context, @role = user, privilege_sym, context_sym, role_sym
  @actions = [AddPrivilegeAndAssignRoleToUserAction.new(@user, @privilege, @context, role_sym)]
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



411
412
413
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 411

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



411
412
413
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 411

def privilege
  @privilege
end

#roleObject (readonly)

Returns the value of attribute role.



411
412
413
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 411

def role
  @role
end

#userObject (readonly)

Returns the value of attribute user.



411
412
413
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 411

def user
  @user
end

Class Method Details

.specific_actions(candidate) ⇒ Object



400
401
402
403
404
405
406
407
408
409
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 400

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
  role = AnalyzerEngine::Role.for_sym(:change_supporter_new_role, candidate.engine)
  ([privilege] + privilege.ancestors).collect do |ancestor_privilege|
    new(user, ancestor_privilege.to_sym, context, role.to_sym)
  end
end

Instance Method Details

#apply(candidate) ⇒ Object



417
418
419
420
421
422
423
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 417

def apply (candidate)
  if AnalyzerEngine.apply_change(candidate.engine, [:add_role, @role])
    super(candidate)
  else
    false
  end
end

#hashObject



425
426
427
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 425

def hash
  to_a[0].hash + super
end

#to_aObject



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

def to_a
  [[:add_role, @role]] + super
end