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.



370
371
372
373
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 370

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.



369
370
371
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 369

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



369
370
371
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 369

def privilege
  @privilege
end

#roleObject (readonly)

Returns the value of attribute role.



369
370
371
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 369

def role
  @role
end

#userObject (readonly)

Returns the value of attribute user.



369
370
371
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 369

def user
  @user
end

Class Method Details

.specific_actions(candidate) ⇒ Object



358
359
360
361
362
363
364
365
366
367
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 358

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



375
376
377
378
379
380
381
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 375

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

#hashObject



383
384
385
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 383

def hash
  to_a[0].hash + super
end

#to_aObject



387
388
389
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 387

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