effective_roles 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/effective_roles_helper.rb +4 -0
- data/lib/effective_roles.rb +38 -23
- data/lib/effective_roles/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21d42ce9fbe7bbae58d667f38184abd0c55040a
|
4
|
+
data.tar.gz: 99fa18bac81fbed5b20643238c3a8fd31849dddc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c45bd6247a2c4c6f265728cb19796ce92d354d3f86c787551f8e3504e07b0397bdb126780acbbf731867238d2969a757a71893e06178bdd10180ccfc7f0ffb
|
7
|
+
data.tar.gz: eb599a4b8f4cfdf5e7cfbee54acacce834579d8eee4d60cea3d51202d5dbb882cc442cab73c32894de91a75b74adefccbafd63a67fe098e058c1df3dafd16fb3
|
@@ -16,7 +16,10 @@ module EffectiveRolesHelper
|
|
16
16
|
# effective_roles_summary_table(roles: [:admin, :superadmin], only: [Post, Event])
|
17
17
|
# effective_roles_summary_table(except: [Post, User])
|
18
18
|
# effective_roles_summary_table(aditionally: [Report::PostReport, User])
|
19
|
+
# effective_roles_summary_table({clinic_report: :export})
|
19
20
|
def effective_roles_summary_table(opts = {})
|
21
|
+
raise 'Expected argument to be a Hash' unless opts.kind_of?(Hash)
|
22
|
+
|
20
23
|
roles = Array(opts[:roles]).presence || EffectiveRoles.roles
|
21
24
|
|
22
25
|
if opts[:only].present?
|
@@ -26,6 +29,7 @@ module EffectiveRolesHelper
|
|
26
29
|
end
|
27
30
|
|
28
31
|
# Figure out all klasses (ActiveRecord objects)
|
32
|
+
Rails.application.eager_load!
|
29
33
|
tables = ActiveRecord::Base.connection.tables - ['schema_migrations', 'delayed_jobs']
|
30
34
|
|
31
35
|
klasses = ActiveRecord::Base.descendants.map do |model|
|
data/lib/effective_roles.rb
CHANGED
@@ -52,13 +52,48 @@ module EffectiveRoles
|
|
52
52
|
|
53
53
|
# This is used by the effective_roles_summary_table helper method
|
54
54
|
def self.authorization_level(controller, role, resource)
|
55
|
-
|
56
|
-
|
57
|
-
return :unknown unless (auth_method.respond_to?(:call) || auth_method.kind_of?(Symbol))
|
55
|
+
return :unknown unless (authorization_method_for_summary_table.respond_to?(:call) || authorization_method_for_summary_table.kind_of?(Symbol))
|
58
56
|
return :unknown unless (controller.current_user rescue nil).respond_to?(:roles=)
|
59
57
|
|
58
|
+
# Store the current ability (cancan support) and roles
|
59
|
+
current_ability = controller.instance_variable_get(:@current_ability)
|
60
|
+
current_user_roles = controller.current_user.roles
|
61
|
+
|
62
|
+
# Set up the user, so the check is done with the desired permission level
|
60
63
|
controller.instance_variable_set(:@current_ability, nil)
|
61
64
|
controller.current_user.roles = [role]
|
65
|
+
|
66
|
+
# Find the actual authorization level
|
67
|
+
level = _authorization_level(controller, role, resource, authorization_method_for_summary_table)
|
68
|
+
|
69
|
+
# Restore the existing current_user stuff
|
70
|
+
controller.instance_variable_set(:@current_ability, current_ability)
|
71
|
+
controller.current_user.roles = current_user_roles
|
72
|
+
|
73
|
+
level
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def self.role_description(role, obj = nil)
|
79
|
+
raise 'EffectiveRoles config.role_descriptions must be a Hash' unless role_descriptions.kind_of?(Hash)
|
80
|
+
(role_descriptions[obj.try(:class).to_s] || {})[role] || role_descriptions[role] || ''
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.disabled_roles_for(obj)
|
84
|
+
raise 'EffectiveRoles config.disabled_roles must be a Hash, Array or nil' unless [Hash, Array, NilClass].include?(disabled_roles.class)
|
85
|
+
|
86
|
+
case disabled_roles
|
87
|
+
when Array
|
88
|
+
disabled_roles
|
89
|
+
when Hash
|
90
|
+
Array(disabled_roles[obj.try(:class).to_s])
|
91
|
+
else
|
92
|
+
[]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self._authorization_level(controller, role, resource, auth_method)
|
62
97
|
resource = (resource.new() rescue resource)
|
63
98
|
|
64
99
|
# Custom actions
|
@@ -107,24 +142,4 @@ module EffectiveRoles
|
|
107
142
|
:none
|
108
143
|
end
|
109
144
|
|
110
|
-
private
|
111
|
-
|
112
|
-
def self.role_description(role, obj = nil)
|
113
|
-
raise 'EffectiveRoles config.role_descriptions must be a Hash' unless role_descriptions.kind_of?(Hash)
|
114
|
-
(role_descriptions[obj.try(:class).to_s] || {})[role] || role_descriptions[role] || ''
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.disabled_roles_for(obj)
|
118
|
-
raise 'EffectiveRoles config.disabled_roles must be a Hash, Array or nil' unless [Hash, Array, NilClass].include?(disabled_roles.class)
|
119
|
-
|
120
|
-
case disabled_roles
|
121
|
-
when Array
|
122
|
-
disabled_roles
|
123
|
-
when Hash
|
124
|
-
Array(disabled_roles[obj.try(:class).to_s])
|
125
|
-
else
|
126
|
-
[]
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
145
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_roles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|