Module: AuthorizationRulesHelper

Defined in:
app/helpers/authorization_rules_helper.rb

Instance Method Summary collapse

Instance Method Details

#auth_usage_info_classes(auth_info) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/authorization_rules_helper.rb', line 53

def auth_usage_info_classes (auth_info)
  classes = []
  if auth_info[:controller_permissions]
    if auth_info[:controller_permissions][0]
      classes << "catch-all" if auth_info[:controller_permissions][0].actions.include?(:all)
      classes << "default-privilege" unless auth_info[:controller_permissions][0].privilege
      classes << "default-context" unless auth_info[:controller_permissions][0].context
      classes << "no-attribute-check" unless auth_info[:controller_permissions][0].attribute_check
    end
  else
    classes << "unprotected"
  end
  classes * " "
end

#auth_usage_info_title(auth_info) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/authorization_rules_helper.rb', line 68

def auth_usage_info_title (auth_info)
  titles = []
  if auth_usage_info_classes(auth_info) =~ /unprotected/
    titles << "No filter_access_to call protects this action"
  end
  if auth_usage_info_classes(auth_info) =~ /no-attribute-check/
    titles << "Action is not protected with attribute check"
  end
  if auth_usage_info_classes(auth_info) =~ /default-privilege/
    titles << "Privilege set automatically from action name by :all rule"
  end
  if auth_usage_info_classes(auth_info) =~ /default-context/
    titles << "Context set automatically from controller name by filter_access_to call without :context option"
  end
  titles * ". "
end


25
26
27
28
# File 'app/helpers/authorization_rules_helper.rb', line 25

def link_to_graph (title, options = {})
  type = options[:type] || ''
  link_to_function title, "$$('object')[0].data = '#{url_for :action => 'index', :format => 'svg', :type => type}'"
end


30
31
32
33
34
35
36
# File 'app/helpers/authorization_rules_helper.rb', line 30

def navigation
  link_to("Rules", authorization_rules_path) << ' | ' <<
  link_to("Graphical view", graph_authorization_rules_path) << ' | ' <<
  link_to("Usages", authorization_usages_path) #<< ' | ' <<
#  'Edit | ' <<
#  link_to("XACML export", :action => 'index', :format => 'xacml')
end

#role_color(role, fill = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/authorization_rules_helper.rb', line 38

def role_color (role, fill = false)
  fill_colors = %w{#ffdddd #ddffdd #ddddff #ffffdd #ffddff #ddffff}
  colors = %w{#dd0000 #00dd00 #0000dd #dddd00 #dd00dd #00dddd}
  @@role_colors ||= {}
  @@role_colors[role] ||= begin
    idx = @@role_colors.length % colors.length
    [colors[idx], fill_colors[idx]]
  end
  @@role_colors[role][fill ? 1 : 0]
end

#role_fill_color(role) ⇒ Object



49
50
51
# File 'app/helpers/authorization_rules_helper.rb', line 49

def role_fill_color (role)
  role_color(role, true)
end

#syntax_highlight(rules) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/authorization_rules_helper.rb', line 2

def syntax_highlight (rules)
  regexps = {
    :constant => [/(:)(\w+)/], 
    :proc => ['role', 'authorization', 'privileges'],
    :statement => ['has_permission_on', 'if_attribute', 'includes', 'privilege', 'to'],
    :operator => ['is', 'contains'],
    :special => ['user', 'true', 'false'],
    :preproc => ['do', 'end', /()(=&gt;)/, /()(\{)/, /()(\})/, /()(\[)/, /()(\])/],
    :comment => [/()(#.*$)/]#,
    #:privilege => [:read],
    #:context => [:conferences]
  }
  regexps.each do |name, res|
    res.each do |re|
      rules.gsub!(
        re.is_a?(String) ? Regexp.new("(^|[^:])\\b(#{Regexp.escape(re)})\\b") :
           (re.is_a?(Symbol) ? Regexp.new("()(:#{Regexp.escape(re.to_s)})\\b") : re), 
        "\\1<span class=\"#{name}\">\\2</span>")
    end
  end
  rules
end