class Authorization::DevelopmentSupport::ChangeSupporter::AssignRoleToUserAction
Attributes
role[R]
user[R]
Public Class Methods
new(user, role_sym)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 360 def initialize (user, role_sym) @user, @role = user, role_sym end
specific_actions(candidate)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 350 def self.specific_actions (candidate) privilege = candidate.failed_tests.first.privilege context = candidate.failed_tests.first.context user = candidate.failed_tests.first.user AnalyzerEngine::Role.all_for_privilege(privilege, context, candidate.engine).collect do |role| new(user, role.to_sym) end end
Public Instance Methods
apply(candidate)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 364 def apply (candidate) if candidate.engine.roles_with_hierarchy_for(@user).include?(@role) false else # beware of shallow copies! cloned_user = @user.clone user_index = candidate.users.index(@user) raise "Cannot find #{@user.inspect} in users array" unless user_index candidate.users[user_index] = cloned_user # possible on real user objects? cloned_user.role_symbols << @role raise "User#role_symbols immutable or user only shallowly cloned!" if cloned_user.role_symbols == @user.role_symbols true end end
hash()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 380 def hash to_a[0,2].hash + @user.login.hash end
resembles?(spec)
click to toggle source
Calls superclass method
Authorization::DevelopmentSupport::ChangeSupporter::AbstractAction#resembles?
# File lib/declarative_authorization/development_support/change_supporter.rb, line 390 def resembles? (spec) super(spec[0,2]) and (spec.length == 2 or spec[2] == @user.login) end
reverse?(other)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 384 def reverse? (other) other.is_a?(RemoveRoleFromUserAction) and other.user.login == @user.login and other.role == @role end
to_a()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 394 def to_a [:assign_role_to_user, @role, @user] end