effective_roles 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a5e585f998b2061367570bc40dbff8085f877a6
4
- data.tar.gz: a0fab03af238f58c876de0f477d14692391ea8ec
3
+ metadata.gz: 2d832ec2924f72a3152a0fe14101828688567e16
4
+ data.tar.gz: 7fe30643ec98f42e1c9a31f5a75737f3a2c4d182
5
5
  SHA512:
6
- metadata.gz: df1780092055c2617a963a0949999fe988a5aa296f83f6e6ac1ee121d181c7924ac773f8dcc608b1fad274a1181f9b8b00f5b218e1c134cdd4529af656c14807
7
- data.tar.gz: 50572e287aae3987ddb2142a7044993f5d87edf80e37ad753145f75210bb81f18d91eb6c5477678dc86735589a52737e69c728291f36900389219f66f7d1b9db
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 = [:admin]
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 = [:superadmin]
121
- user.roles = [:admin]
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 = [:admin]
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/roles_fields', :locals => opts
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
@@ -0,0 +1,8 @@
1
+ .effective-role
2
+ %p
3
+ %label.control-label Roles
4
+
5
+ - roles.each do |role|
6
+ .effective-role
7
+ %p= role
8
+ %p.help-block= descriptions[role]
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveRoles
2
- VERSION = '1.4.0'.freeze
2
+ VERSION = '1.4.1'.freeze
3
3
  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.4.0
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-07 00:00:00.000000000 Z
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/_roles_fields.html.haml
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