Module: Authorization

Defined in:
app/helpers/users/authorization.rb

Instance Method Summary collapse

Instance Method Details



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/users/authorization.rb', line 2

def roles_control_links_for user
  links = []

  # Ordered Roles
  %w{member manager}.each do |role|
    unless user.roles.include? role
        if can? "add_#{role}_role"
          links << add_role_link(t("add_#{role}_role"), user, role)
        end
      else
      text = t(role)
      if can? "remove_#{role}_role"
        link = remove_role_link(t("remove_#{role}_role"), user, role)
        links << "#{text} (#{link})"
      else
        links << text
      end
    end
  end

  # Custom Roles
  rad.config.custom_roles.each do |role|
    unless user.roles.include? role
        if can? "add_custom_role"
          links << add_role_link(t(:add_custom_role, role: role), user, role)
        end
      else
      text = t(:custom_role, role: role)
      if can? "remove_custom_role"
        link = remove_role_link(t(:remove_custom_role, role: role), user, role)
        links << "#{text} (#{link})"
      else
        links << text
      end
    end
  end

  # Admin Roles
  unless user.roles.include? 'admin'
      if can? "add_admin_role"
        links << add_role_link(t(:add_admin_role), user, 'admin')
      end
    else
    text = t(:admin)
    if can? "remove_admin_role"
      link = remove_role_link(t(:remove_admin_role), user, 'admin')
      links << "#{text} (#{link})"
    else
      links << text
    end
  end

  links
end