effective_roles 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2839a8a58a284f7b6f9f7b12a3d5a0eff69b9b60c1f99ef68d364acab5257355
|
4
|
+
data.tar.gz: 69856eb8d9e3296a26386d28560c36c238cbfc7d407168f2614f13f48fc9b9eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7c8c3befff4c7f7c51290f39f8f14a70ce50cca7448be66869875bca53422d23b73ef5b558b58ebc046b66f398d356d2fa3125bc595b9ecad737eb16a06d41d
|
7
|
+
data.tar.gz: c504136f2a6593dd272ce0208d72f26fb77a491e846c91b24ed5806a60aa4ffbea942ecb09e19e463166bbe0835e21071b7ac9493aecda527a479dc26c68c054
|
@@ -2,7 +2,7 @@ module EffectiveRolesHelper
|
|
2
2
|
def effective_roles_summary(obj, options = {}) # User or a Post, any acts_as_roleable
|
3
3
|
raise 'expected an acts_as_roleable object' unless obj.respond_to?(:roles)
|
4
4
|
|
5
|
-
descriptions = EffectiveRoles.
|
5
|
+
descriptions = EffectiveRoles.role_descriptions[obj.class.name] || EffectiveRoles.role_descriptions || {}
|
6
6
|
opts = { obj: obj, roles: obj.roles, descriptions: descriptions }.merge(options)
|
7
7
|
|
8
8
|
render partial: 'effective/roles/summary', locals: opts
|
@@ -17,7 +17,7 @@ module EffectiveRolesHelper
|
|
17
17
|
raise 'Expected argument to be a Hash' unless opts.kind_of?(Hash)
|
18
18
|
|
19
19
|
roles = Array(opts[:roles]).presence
|
20
|
-
roles ||= [:public, :signed_in] + EffectiveRoles.
|
20
|
+
roles ||= [:public, :signed_in] + EffectiveRoles.roles
|
21
21
|
|
22
22
|
if opts[:only].present?
|
23
23
|
klasses = Array(opts[:only])
|
@@ -103,7 +103,7 @@ module EffectiveRolesHelper
|
|
103
103
|
|
104
104
|
# This is used by the effective_roles_summary_table helper method
|
105
105
|
def effective_roles_authorization_level(controller, role, resource)
|
106
|
-
authorization_method =
|
106
|
+
authorization_method = EffectiveResources.authorization_method
|
107
107
|
|
108
108
|
raise('expected an authorization method') unless (authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol))
|
109
109
|
return :unknown unless (controller.current_user rescue nil).respond_to?(:roles=)
|
@@ -71,18 +71,18 @@ module ActsAsRoleRestricted
|
|
71
71
|
def with_role_sql(*roles)
|
72
72
|
roles = roles.flatten.compact
|
73
73
|
roles = roles.first.roles if roles.length == 1 && roles.first.respond_to?(:roles)
|
74
|
-
roles = (roles.map { |role| role.to_sym } & EffectiveRoles.
|
74
|
+
roles = (roles.map { |role| role.to_sym } & EffectiveRoles.roles)
|
75
75
|
|
76
|
-
roles.map { |role| "(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.
|
76
|
+
roles.map { |role| "(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.roles.index(role) }.join(' OR ')
|
77
77
|
end
|
78
78
|
|
79
79
|
def without_role(*roles)
|
80
80
|
roles = roles.flatten.compact
|
81
81
|
roles = roles.first.roles if roles.length == 1 && roles.first.respond_to?(:roles)
|
82
|
-
roles = (roles.map { |role| role.to_sym } & EffectiveRoles.
|
82
|
+
roles = (roles.map { |role| role.to_sym } & EffectiveRoles.roles)
|
83
83
|
|
84
84
|
where(
|
85
|
-
roles.map { |role| "NOT(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.
|
85
|
+
roles.map { |role| "NOT(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.roles.index(role) }.join(' AND ')
|
86
86
|
).or(where(roles_mask: nil))
|
87
87
|
end
|
88
88
|
end
|
data/lib/effective_roles.rb
CHANGED
@@ -3,25 +3,12 @@ require 'effective_roles/engine'
|
|
3
3
|
require 'effective_roles/version'
|
4
4
|
|
5
5
|
module EffectiveRoles
|
6
|
-
# mattr_accessor :roles
|
7
|
-
# mattr_accessor :role_descriptions
|
8
|
-
# mattr_accessor :assignable_roles
|
9
|
-
# mattr_accessor :layout
|
10
6
|
|
11
|
-
def self.
|
12
|
-
|
13
|
-
namespace ||= Tenant.current if defined?(Tenant)
|
14
|
-
|
15
|
-
if namespace
|
16
|
-
@config[namespace] ||= ActiveSupport::OrderedOptions.new
|
17
|
-
else
|
18
|
-
@config
|
19
|
-
end
|
7
|
+
def self.config_keys
|
8
|
+
[:roles, :role_descriptions, :assignable_roles, :layout]
|
20
9
|
end
|
21
10
|
|
22
|
-
|
23
|
-
yield(config(namespace))
|
24
|
-
end
|
11
|
+
include EffectiveGem
|
25
12
|
|
26
13
|
def self.permitted_params
|
27
14
|
{ roles: [] }
|
@@ -33,11 +20,11 @@ module EffectiveRoles
|
|
33
20
|
if obj.respond_to?(:is_role_restricted?)
|
34
21
|
obj.roles
|
35
22
|
elsif obj.kind_of?(Integer)
|
36
|
-
|
23
|
+
roles.reject { |r| (obj & 2 ** config.roles.index(r)).zero? }
|
37
24
|
elsif obj.kind_of?(Symbol)
|
38
|
-
Array(
|
25
|
+
Array(roles.find { |role| role == obj })
|
39
26
|
elsif obj.kind_of?(String)
|
40
|
-
Array(
|
27
|
+
Array(roles.find { |role| role == obj.to_sym })
|
41
28
|
elsif obj.kind_of?(Array)
|
42
29
|
obj.map { |obj| roles_for(obj) }.flatten.compact
|
43
30
|
elsif obj.nil?
|
@@ -53,7 +40,7 @@ module EffectiveRoles
|
|
53
40
|
end
|
54
41
|
|
55
42
|
def self.roles_collection(resource, current_user = nil, only: nil, except: nil, multiple: nil)
|
56
|
-
if
|
43
|
+
if assignable_roles.present?
|
57
44
|
raise('expected object to respond to is_role_restricted?') unless resource.respond_to?(:is_role_restricted?)
|
58
45
|
raise('expected current_user to respond to is_role_restricted?') if current_user && !current_user.respond_to?(:is_role_restricted?)
|
59
46
|
end
|
@@ -63,7 +50,7 @@ module EffectiveRoles
|
|
63
50
|
multiple = resource.acts_as_role_restricted_options[:multiple] if multiple.nil?
|
64
51
|
assignable = assignable_roles_collection(resource, current_user, multiple: multiple)
|
65
52
|
|
66
|
-
|
53
|
+
roles.map do |role|
|
67
54
|
next if only.present? && !only.include?(role)
|
68
55
|
next if except.present? && except.include?(role)
|
69
56
|
|
@@ -76,7 +63,7 @@ module EffectiveRoles
|
|
76
63
|
end
|
77
64
|
|
78
65
|
def self.assignable_roles_collection(resource, current_user = nil, multiple: nil)
|
79
|
-
return
|
66
|
+
return roles unless assignable_roles_present?(resource)
|
80
67
|
|
81
68
|
if current_user && !current_user.respond_to?(:is_role_restricted?)
|
82
69
|
raise('expected current_user to respond to is_role_restricted?')
|
@@ -86,8 +73,8 @@ module EffectiveRoles
|
|
86
73
|
raise('expected current_user to respond to is_role_restricted?')
|
87
74
|
end
|
88
75
|
|
89
|
-
assigned_roles = if
|
90
|
-
assignable = (
|
76
|
+
assigned_roles = if assignable_roles.kind_of?(Hash)
|
77
|
+
assignable = (assignable_roles[resource.class.to_s] || assignable_roles || {})
|
91
78
|
assigned = [] # our return value
|
92
79
|
|
93
80
|
if current_user.blank?
|
@@ -107,8 +94,8 @@ module EffectiveRoles
|
|
107
94
|
end
|
108
95
|
|
109
96
|
assigned
|
110
|
-
elsif
|
111
|
-
|
97
|
+
elsif assignable_roles.kind_of?(Array)
|
98
|
+
assignable_roles
|
112
99
|
end.uniq
|
113
100
|
|
114
101
|
# Check boxes
|
@@ -120,27 +107,27 @@ module EffectiveRoles
|
|
120
107
|
end
|
121
108
|
|
122
109
|
def self.assignable_roles_present?(resource)
|
123
|
-
return false unless
|
110
|
+
return false unless assignable_roles.present?
|
124
111
|
|
125
|
-
raise 'EffectiveRoles config.assignable_roles_for must be a Hash or Array' unless [Hash, Array].include?(
|
112
|
+
raise 'EffectiveRoles config.assignable_roles_for must be a Hash or Array' unless [Hash, Array].include?(assignable_roles.class)
|
126
113
|
raise('expected resource to respond to is_role_restricted?') unless resource.respond_to?(:is_role_restricted?)
|
127
114
|
|
128
|
-
if
|
129
|
-
|
130
|
-
elsif
|
131
|
-
|
115
|
+
if assignable_roles.kind_of?(Array)
|
116
|
+
assignable_roles
|
117
|
+
elsif assignable_roles.key?(resource.class.to_s)
|
118
|
+
assignable_roles[resource.class.to_s]
|
132
119
|
else
|
133
|
-
|
120
|
+
assignable_roles
|
134
121
|
end.present?
|
135
122
|
end
|
136
123
|
|
137
124
|
private
|
138
125
|
|
139
126
|
def self.role_description(role, obj = nil)
|
140
|
-
raise 'EffectiveRoles config.role_descriptions must be a Hash' unless
|
127
|
+
raise 'EffectiveRoles config.role_descriptions must be a Hash' unless role_descriptions.kind_of?(Hash)
|
141
128
|
|
142
|
-
description =
|
143
|
-
description ||=
|
129
|
+
description = role_descriptions.dig(obj.class.to_s, role) if obj.present?
|
130
|
+
description ||= role_descriptions[role]
|
144
131
|
description || ''
|
145
132
|
end
|
146
133
|
|
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: 2.1.
|
4
|
+
version: 2.1.1
|
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: 2021-02-
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|