55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'app/controllers/authorization_rules_controller.rb', line 55
def suggest_change
users_permission = params[:user].inject({}) do |memo, (user_id, data)|
if data[:permission] != "undetermined"
begin
memo[find_user_by_id(user_id)] = (data[:permission] == 'yes')
rescue ActiveRecord::NotFound
end
end
memo
end
prohibited_actions = (params[:prohibited_action] || []).collect do |spec|
deserialize_changes(spec).flatten
end
analyzer = Authorization::DevelopmentSupport::ChangeSupporter.new(authorization_engine)
privilege = params[:privilege].to_sym
context = params[:context].to_sym
all_users = User.all
@context = context
@approaches = analyzer.find_approaches_for(:users => all_users, :prohibited_actions => prohibited_actions) do
users.each_with_index do |user, idx|
unless users_permission[all_users[idx]].nil?
args = [privilege, {:context => context, :user => user}]
assert(users_permission[all_users[idx]] ? permit?(*args) : !permit?(*args))
end
end
end
@affected_users = @approaches.each_with_object({}) do |approach, memo|
memo[approach] = approach.affected_users(authorization_engine, all_users, privilege, context).length
end
max_affected_users = @affected_users.values.max
if params[:affected_users]
@approaches = @approaches.sort_by do |approach|
affected_users_count = @affected_users[approach]
if params[:affected_users] == "many"
approach.weight + (max_affected_users - affected_users_count) * 10
else
approach.weight + affected_users_count * 10
end
end
end
@grouped_approaches = analyzer.group_approaches(@approaches)
respond_to do |format|
format.js do
render :partial => 'suggestions'
end
end
end
|