effective_roles 2.2.1 → 2.3.2
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: 9bfa0c4c2878a1c88ee466c2cc321ad1ad8016adf44b521d710b81f11bda17d1
|
4
|
+
data.tar.gz: bb370586b9e8ff441156be67dcc9b296c7a445602100a8d571b49db406ee9300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85b549b0bddf0e29f1ac29eb37b49a227f49a6d8fd44396c727bc47c067e6ecb9f9297f4f5cf1f4ae274ac96b7bdd7aad6a59a8453dd2b46ca748d6f5585e44d
|
7
|
+
data.tar.gz: 45c5c8fd2a446bec85814198e8e609e67011758ddac0f2d8529ef8854f2a4b51d4a389f39f9f72ad7614c738f675b9bbc366901217bb94e50e8a98e4427e1f17
|
@@ -53,6 +53,8 @@ module ActsAsRoleRestricted
|
|
53
53
|
end
|
54
54
|
|
55
55
|
module ClassMethods
|
56
|
+
def acts_as_role_restricted?; true; end
|
57
|
+
|
56
58
|
# Call with for_role(:admin) or for_role(@user.roles) or for_role([:admin, :member]) or for_role(:admin, :member, ...)
|
57
59
|
|
58
60
|
# Returns all records which have been assigned any of the the given roles
|
@@ -87,17 +89,42 @@ module ActsAsRoleRestricted
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
92
|
+
def roles
|
93
|
+
EffectiveRoles.roles_for(roles_mask)
|
94
|
+
end
|
95
|
+
|
90
96
|
def roles=(roles)
|
91
97
|
self.roles_mask = EffectiveRoles.roles_mask_for(roles)
|
92
98
|
end
|
93
99
|
|
94
|
-
def
|
95
|
-
|
100
|
+
def add_role(role)
|
101
|
+
raise('expected role to be a symbol') unless role.kind_of?(Symbol)
|
102
|
+
raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
|
103
|
+
|
104
|
+
assign_attributes(roles: roles | [role])
|
105
|
+
end
|
106
|
+
|
107
|
+
def add_role!(role)
|
108
|
+
add_role(role); save!
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_role(role)
|
112
|
+
raise('expected role to be a symbol') unless role.kind_of?(Symbol)
|
113
|
+
raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
|
114
|
+
|
115
|
+
assign_attributes(roles: roles - [role])
|
116
|
+
end
|
117
|
+
|
118
|
+
def remove_role!(role)
|
119
|
+
remove_role(role); save!
|
96
120
|
end
|
97
121
|
|
98
122
|
# if user.is? :admin
|
99
123
|
def is?(role)
|
100
|
-
|
124
|
+
raise('expected role to be a symbol') unless role.kind_of?(Symbol)
|
125
|
+
raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
|
126
|
+
|
127
|
+
roles.include?(role)
|
101
128
|
end
|
102
129
|
|
103
130
|
# if user.is_any?(:admin, :editor)
|
@@ -4,7 +4,7 @@ module EffectiveRoles
|
|
4
4
|
|
5
5
|
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
6
6
|
initializer 'effective_roles.active_record' do |app|
|
7
|
-
|
7
|
+
app.config.to_prepare do
|
8
8
|
ActiveRecord::Base.extend(ActsAsRoleRestricted::Base)
|
9
9
|
end
|
10
10
|
end
|
data/lib/effective_roles.rb
CHANGED
@@ -102,12 +102,7 @@ module EffectiveRoles
|
|
102
102
|
assignable_roles
|
103
103
|
end.uniq
|
104
104
|
|
105
|
-
|
106
|
-
multiple = resource.acts_as_role_restricted_options[:multiple] if multiple.nil?
|
107
|
-
return assigned_roles if multiple
|
108
|
-
|
109
|
-
# Radios
|
110
|
-
(resource.roles - assigned_roles).present? ? [] : assigned_roles
|
105
|
+
assigned_roles
|
111
106
|
end
|
112
107
|
|
113
108
|
def self.assignable_roles_present?(resource)
|
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.2
|
4
|
+
version: 2.3.2
|
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:
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|