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
# 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 {|priv| Authorization::DevelopmentSupport::AnalyzerEngine::Privilege.for_sym(priv, authorization_engine).descendants.map(&:to_sym) }.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



52
53
54
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
# File 'app/controllers/authorization_rules_controller.rb', line 52

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

  users_keys = users_permission.keys
  analyzer = Authorization::DevelopmentSupport::ChangeSupporter.new(authorization_engine)
  
  privilege = params[:privilege].to_sym
  context = params[:context].to_sym
  @context = context
  @approaches = analyzer.find_approaches_for(:users => users_keys, :prohibited_actions => prohibited_actions) do
    users.each_with_index do |user, idx|
      args = [privilege, {:context => context, :user => user}]
      assert(users_permission[users_keys[idx]] ? permit?(*args) : !permit?(*args))
    end
  end

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