class Authorization::DevelopmentSupport::ChangeSupporter::Approach
Attributes
engine[R]
failed_tests[R]
steps[R]
users[R]
Public Class Methods
new(engine, users, steps)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 134 def initialize (engine, users, steps) @engine, @users, @steps = engine, users, steps end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 225 def <=> (other) sort_value <=> other.sort_value end
abstract_actions()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 164 def abstract_actions if failed_tests.first.positive [ AssignPrivilegeToRoleAction, AssignRoleToUserAction, CreateAndAssignRoleToUserAction, AddPrivilegeAndAssignRoleToUserAction ] else [ RemovePrivilegeFromRoleAction, RemoveRoleFromUserAction ] end end
affected_users(original_engine, original_users, privilege, context)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 145 def affected_users (original_engine, original_users, privilege, context) (0...@users.length).select do |i| original_engine.permit?(privilege, :context => context, :skip_attribute_test => true, :user => original_users[i]) != @engine.permit?(privilege, :context => context, :skip_attribute_test => true, :user => @users[i]) end.collect {|i| original_users[i]} end
apply(action)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 184 def apply (action) ok = action.apply(self) @steps << action if ok ok end
changes()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 160 def changes @steps end
check(approach_checker)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 138 def check (approach_checker) res = approach_checker.check(@engine, @users) @failed_tests = approach_checker.failed_tests #puts "CHECKING #{inspect} (#{res}, #{sort_value})" res end
initialize_copy(other)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 154 def initialize_copy (other) @engine = @engine.clone @users = @users.clone @steps = @steps.clone end
inspect()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 219 def inspect "Approach: Steps: #{changes.map(&:inspect) * ', '}"# + # "\n Roles: #{AnalyzerEngine.roles(@engine).map(&:to_sym).inspect}; " + # "\n Users: #{@users.map(&:role_symbols).inspect}" end
reverse_of_previous?(specific_action)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 180 def reverse_of_previous? (specific_action) changes.any? {|step| step.reverse?(specific_action)} end
similar_to(other)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 213 def similar_to (other) other.weight == weight and other.changes.map {|change| change.class.name}.sort == changes.map {|change| change.class.name}.sort end
sort_value()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 205 def sort_value weight + @failed_tests.length end
state_hash()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 195 def state_hash @state_hash ||= @engine.auth_rules.inject(0) do |memo, rule| memo + rule.privileges.hash + rule.contexts.hash + rule.attributes.hash + rule.role.hash end + @users.inject(0) {|memo, user| memo + user.role_symbols.hash } + @engine.privileges.hash + @engine.privilege_hierarchy.hash + @engine.roles.hash + @engine.role_hierarchy.hash end
subset?(other_approach)
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 190 def subset? (other_approach) other_approach.changes.length >= changes.length && changes.all? {|step| other_approach.changes.any? {|step_2| step_2.eql?(step)} } end
weight()
click to toggle source
# File lib/declarative_authorization/development_support/change_supporter.rb, line 209 def weight changes.sum(&:weight) end