effective_roles 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/acts_as_role_restricted.rb +3 -1
- data/lib/effective_roles/version.rb +1 -1
- data/lib/effective_roles.rb +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 592048e729650a2988a1b4cd6a88982f74798715385cac9d17f80fd5c975b197
|
4
|
+
data.tar.gz: f0dbc94accae4749fa9fea221cf7f0ffc7013463ddd3571e68c64789bed554b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38b3e7b0aa680d4e47ea1d2411bb3a7c77a5c5155e6f6702b5ee14b14cc48b51bd0497e26c780a5f9fa4aec88cc0cab12da8bc5936cc5def8d44bde29a8f7693
|
7
|
+
data.tar.gz: 608cd0e64ecc94c77daba4c559f4b22fa6eb18b8515a33695f87da051dadd72f16b91c1bf6b76a05b457fe2cfb1c1e6e965e1f2d0c76077fc70f7297b75742b4
|
@@ -24,12 +24,14 @@ module ActsAsRoleRestricted
|
|
24
24
|
included do
|
25
25
|
attr_accessor(:current_user) unless respond_to?(:current_user)
|
26
26
|
|
27
|
+
attr_accessor :skip_effective_roles_validation
|
28
|
+
|
27
29
|
acts_as_role_restricted_options = @acts_as_role_restricted_opts.dup
|
28
30
|
self.send(:define_method, :acts_as_role_restricted_options) { acts_as_role_restricted_options }
|
29
31
|
|
30
32
|
validates :roles_mask, numericality: true, allow_nil: true
|
31
33
|
|
32
|
-
validate(if: -> { changes.include?(:roles_mask) && EffectiveRoles.assignable_roles_present?(self) && current_user.present? }) do
|
34
|
+
validate(if: -> { changes.include?(:roles_mask) && EffectiveRoles.assignable_roles_present?(self) && current_user.present? }, unless: -> { skip_effective_roles_validation }) do
|
33
35
|
roles_was = EffectiveRoles.roles_for(changes[:roles_mask].first)
|
34
36
|
changed = (roles + roles_was) - (roles & roles_was) # XOR
|
35
37
|
|
data/lib/effective_roles.rb
CHANGED
@@ -44,7 +44,7 @@ module EffectiveRoles
|
|
44
44
|
(role_colors || {})[role]
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.roles_collection(resource, current_user = nil, only: nil, except: nil,
|
47
|
+
def self.roles_collection(resource, current_user = nil, only: nil, except: nil, skip_disabled: nil)
|
48
48
|
if assignable_roles.present?
|
49
49
|
raise('expected object to respond to is_role_restricted?') unless resource.respond_to?(:is_role_restricted?)
|
50
50
|
raise('expected current_user to respond to is_role_restricted?') if current_user && !current_user.respond_to?(:is_role_restricted?)
|
@@ -52,11 +52,12 @@ module EffectiveRoles
|
|
52
52
|
|
53
53
|
only = Array(only).compact
|
54
54
|
except = Array(except).compact
|
55
|
-
multiple = resource.acts_as_role_restricted_options[:multiple] if multiple.nil?
|
56
|
-
assignable = assignable_roles_collection(resource, current_user, multiple: multiple)
|
57
55
|
skip_disabled = assignable_roles.kind_of?(Hash) if skip_disabled.nil?
|
58
56
|
|
59
|
-
|
57
|
+
all_roles = assignable_roles_collection(resource)
|
58
|
+
assignable = assignable_roles_collection(resource, current_user)
|
59
|
+
|
60
|
+
all_roles.map do |role|
|
60
61
|
next if only.present? && !only.include?(role)
|
61
62
|
next if except.present? && except.include?(role)
|
62
63
|
|
@@ -71,7 +72,7 @@ module EffectiveRoles
|
|
71
72
|
end.compact
|
72
73
|
end
|
73
74
|
|
74
|
-
def self.assignable_roles_collection(resource, current_user = nil
|
75
|
+
def self.assignable_roles_collection(resource, current_user = nil)
|
75
76
|
return roles unless assignable_roles_present?(resource)
|
76
77
|
|
77
78
|
if current_user && !current_user.respond_to?(:is_role_restricted?)
|
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.
|
4
|
+
version: 2.8.0
|
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: 2024-04-
|
11
|
+
date: 2024-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|