effective_roles 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -5
- data/app/helpers/effective_roles_helper.rb +10 -1
- data/app/models/concerns/acts_as_role_restricted.rb +1 -1
- data/app/views/effective/roles/{_roles_fields.html.haml → _fields.html.haml} +0 -0
- data/app/views/effective/roles/_summary.html.haml +8 -0
- data/lib/effective_roles.rb +5 -1
- data/lib/effective_roles/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d832ec2924f72a3152a0fe14101828688567e16
|
4
|
+
data.tar.gz: 7fe30643ec98f42e1c9a31f5a75737f3a2c4d182
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b5bfb39046d1917b89dc245ceb3649349667d08b7e1652c79842a3b77fa6042fc3a98f02610996c896d6ac5061f997405759595731b177555913530596b0959
|
7
|
+
data.tar.gz: 8cba4ba09d26c7cda64fdd0bfb05adcb97bf92c0cd76e8e65076d12aaef9bb5112347240fb803e59834b025229d2df2ca6a7a346dfbc6172e094d0f3836675df
|
data/README.md
CHANGED
@@ -107,25 +107,25 @@ Compare against another acts_as_role_restricted object:
|
|
107
107
|
|
108
108
|
```ruby
|
109
109
|
post = Post.new()
|
110
|
-
post.roles =
|
110
|
+
post.roles = :admin
|
111
111
|
|
112
112
|
user = User.new()
|
113
|
-
user.roles =
|
113
|
+
user.roles = nil
|
114
114
|
|
115
115
|
post.roles_permit?(user)
|
116
116
|
=> false # Post requires the :admin role, but User has no admin role
|
117
117
|
```
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
post.roles =
|
121
|
-
user.roles =
|
120
|
+
post.roles = :superadmin
|
121
|
+
user.roles = :admin
|
122
122
|
|
123
123
|
post.roles_permit?(user)
|
124
124
|
=> false # User does not have the superadmin role
|
125
125
|
```
|
126
126
|
|
127
127
|
```ruby
|
128
|
-
post.roles =
|
128
|
+
post.roles = :admin
|
129
129
|
user.roles = [:superadmin, :admin]
|
130
130
|
|
131
131
|
post.roles_permit?(user)
|
@@ -211,6 +211,32 @@ simple_form_for @user do |f|
|
|
211
211
|
= f.input :roles, :collection => EffectiveRoles.roles_collection(f.object, current_user), :as => :check_boxes
|
212
212
|
```
|
213
213
|
|
214
|
+
### Strong Parameters
|
215
|
+
|
216
|
+
Make your controller aware of the passed parameters:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
def permitted_params
|
220
|
+
params.require(:base_object).permit(EffectiveRoles.permitted_params)
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
224
|
+
The actual permitted parameters are:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
roles: []
|
228
|
+
```
|
229
|
+
|
230
|
+
## Summary
|
231
|
+
|
232
|
+
Use the `effective_roles_summary` view helper to output a list of roles and descriptions.
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
effective_roles_summary(user) # any acts_as_role_restricted object
|
236
|
+
effective_roles_summary(post)
|
237
|
+
```
|
238
|
+
|
239
|
+
|
214
240
|
## Summary table
|
215
241
|
|
216
242
|
Use the `effective_roles_summary_table` view helper to output a table of the actual permission levels for each role and ActiveRecord object combination.
|
@@ -8,7 +8,16 @@ module EffectiveRolesHelper
|
|
8
8
|
|
9
9
|
opts = {:f => form, :roles => roles, :descriptions => descriptions}.merge(options)
|
10
10
|
|
11
|
-
render :partial => 'effective/roles/
|
11
|
+
render :partial => 'effective/roles/fields', :locals => opts
|
12
|
+
end
|
13
|
+
|
14
|
+
def effective_roles_summary(obj, options = {}) # User or a Post, any acts_as_roleable
|
15
|
+
raise 'expected an acts_as_roleable object' unless obj.respond_to?(:roles)
|
16
|
+
|
17
|
+
descriptions = EffectiveRoles.role_descriptions[obj.class.name] || EffectiveRoles.role_descriptions || {}
|
18
|
+
opts = {:obj => obj, :roles => obj.roles, :descriptions => descriptions}.merge(options)
|
19
|
+
|
20
|
+
render :partial => 'effective/roles/summary', :locals => opts
|
12
21
|
end
|
13
22
|
|
14
23
|
# Output a table of permissions for each role based on current permissions
|
@@ -62,7 +62,7 @@ module ActsAsRoleRestricted
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def roles=(roles)
|
65
|
-
self.roles_mask = (roles.map(&:to_sym) & EffectiveRoles.roles).map { |r| 2**EffectiveRoles.roles.index(r) }.sum
|
65
|
+
self.roles_mask = (Array(roles).flatten.map(&:to_sym) & EffectiveRoles.roles).map { |r| 2**EffectiveRoles.roles.index(r) }.sum
|
66
66
|
end
|
67
67
|
|
68
68
|
def roles
|
File without changes
|
data/lib/effective_roles.rb
CHANGED
@@ -16,6 +16,10 @@ module EffectiveRoles
|
|
16
16
|
yield self
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.permitted_params
|
20
|
+
{roles: []}
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.authorized?(controller, action, resource)
|
20
24
|
if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
|
21
25
|
raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
|
@@ -41,7 +45,7 @@ module EffectiveRoles
|
|
41
45
|
|
42
46
|
# EffectiveRoles.roles_mask_for(:admin, :member)
|
43
47
|
def self.roles_mask_for(*roles)
|
44
|
-
(Array(roles).map(&:to_sym) & EffectiveRoles.roles).map { |r| 2**EffectiveRoles.roles.index(r) }.sum
|
48
|
+
(Array(roles).flatten.map(&:to_sym) & EffectiveRoles.roles).map { |r| 2**EffectiveRoles.roles.index(r) }.sum
|
45
49
|
end
|
46
50
|
|
47
51
|
def self.roles_collection(obj = nil, user = nil)
|
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.4.
|
4
|
+
version: 1.4.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: 2016-12-
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -167,7 +167,8 @@ files:
|
|
167
167
|
- app/models/concerns/acts_as_role_restricted.rb
|
168
168
|
- app/models/effective/access_denied.rb
|
169
169
|
- app/views/admin/roles/index.html.haml
|
170
|
-
- app/views/effective/roles/
|
170
|
+
- app/views/effective/roles/_fields.html.haml
|
171
|
+
- app/views/effective/roles/_summary.html.haml
|
171
172
|
- app/views/effective/roles/_summary_table.html.haml
|
172
173
|
- config/effective_roles.rb
|
173
174
|
- config/routes.rb
|