Class: AuthorizationRulesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/authorization_rules_controller.rb,
app/controllers/authorization_rules_controller.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/authorization_rules_controller.rb', line 33

def change
  @users = find_all_users
  @users.sort! {|a, b| a. <=> b. }
  
  @privileges = authorization_engine.auth_rules.collect {|rule| rule.privileges.to_a}.flatten.uniq
  @privileges = @privileges.collect do |priv|
    priv = Authorization::DevelopmentSupport::AnalyzerEngine::Privilege.for_sym(priv, authorization_engine)
    (priv.descendants + priv.ancestors).map(&:to_sym)
  end.flatten.uniq
  @privileges.sort_by {|priv| priv.to_s}
  @privilege = params[:privilege].to_sym rescue @privileges.first
  @contexts = authorization_engine.auth_rules.collect {|rule| rule.contexts.to_a}.flatten.uniq
  @context = params[:context].to_sym rescue @contexts.first

  respond_to do |format|
    format.html
    format.js do
      render :partial => 'change'
    end
  end
end

#graphObject



26
27
28
29
30
31
# File 'app/controllers/authorization_rules_controller.rb', line 26

def graph
  if params[:format] == "svg"
    render :text => dot_to_svg(auth_to_dot(graph_options)),
        :content_type => "image/svg+xml"
  end
end

#indexObject



18
19
20
21
22
23
24
# File 'app/controllers/authorization_rules_controller.rb', line 18

def index
  respond_to do |format|
    format.html do
      @auth_rules_script = File.read("#{RAILS_ROOT}/config/authorization_rules.rb")
    end
  end
end

#suggest_changeObject



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.to_f / [affected_users_count, 0.1].min
        approach.weight + (max_affected_users - affected_users_count) * 10
      else
        #approach.weight * affected_users_count
        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