Class Authorization::DevelopmentSupport::ChangeSupporter::RemoveRoleFromUserAction
In: lib/declarative_authorization/development_support/change_supporter.rb
Parent: AbstractAction

Methods

apply   hash   new   resembles?   reverse?   specific_actions   to_a  

Attributes

role  [R] 
user  [R] 

Public Class methods

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 505
505:         def initialize (user, role_sym)
506:           @user, @role = user, role_sym
507:         end

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 492
492:         def self.specific_actions (candidate)
493:           privilege = candidate.failed_tests.first.privilege
494:           context = candidate.failed_tests.first.context
495:           user = candidate.failed_tests.first.user
496:           roles_for_privilege = AnalyzerEngine::Role.all_for_privilege(privilege, context, candidate.engine).map(&:to_sym)
497:           user.role_symbols.collect {|role_sym| AnalyzerEngine::Role.for_sym(role_sym, candidate.engine)}.
498:               select {|role| roles_for_privilege.include?(role.to_sym)}.
499:               collect do |role|
500:             new(user, role.to_sym)
501:           end
502:         end

Public Instance methods

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 509
509:         def apply (candidate)
510:           # beware of shallow copies!
511:           cloned_user = @user.clone
512:           user_index = candidate.users.index(@user)
513:           raise "Cannot find #{@user.inspect} in users array" unless user_index
514:           candidate.users[user_index] = cloned_user
515:           cloned_user.role_symbols.delete(@role)
516:           raise "User#role_symbols immutable or user only shallowly cloned!" if cloned_user.role_symbols == @user.role_symbols
517:           true
518:         end

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 520
520:         def hash
521:           to_a[0,2].hash + @user.login.hash
522:         end

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 530
530:         def resembles? (spec)
531:           super(spec[0,2]) and (spec.length == 2 or spec[2] == @user.login)
532:         end

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 524
524:         def reverse? (other)
525:           (other.is_a?(AssignRoleToUserAction) or
526:               other.is_a?(AbstractCompoundAction)) and
527:                 other.reverse?(self)
528:         end

[Source]

     # File lib/declarative_authorization/development_support/change_supporter.rb, line 534
534:         def to_a
535:           [:remove_role_from_user, @role, @user]
536:         end

[Validate]