effective_roles 1.3.5 → 1.3.6

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
  SHA1:
3
- metadata.gz: 58eaf0d1c8638d1f0f99db14e020ee9d1b8d44b8
4
- data.tar.gz: c6357c32354161bdd205cd1d1166324da3dcbda1
3
+ metadata.gz: e7b3c3686d78be5fc3ac9d9a81fe5fad8901c03e
4
+ data.tar.gz: ae7e62f7cef4c2029709d448e7720f784c042c12
5
5
  SHA512:
6
- metadata.gz: 1534d3a0e1aa8de3f66d5f57432e87ed2e5e67b3af72afa923d55ab2f1c8bc96f83ce356d6bae4699e856b6989bd3afda4ced5203119a2ae9a8e70cff9306dcb
7
- data.tar.gz: aab908afc6cad823ffb41e6b95f2e3bc58d3ba40614d12576a953f984dbad1044ebc48d3b38f0a3b7775618abfa3dbbe3835bf8003110c294fa19f0cb82bbbfe
6
+ metadata.gz: 7331da01447ec7fda1dfd106632078ff8bf54c62f80c2aebd8f09e1fe6ab7a71cddf222e09d6f57d582704e34c8e2da46c3b820bc0c3964e1c5d2a7ef8599664
7
+ data.tar.gz: edbb944a7efa16e069cf2c544d4990c0c7b6492ab78f8fc9143245634e8b599769d460143827f6f558dd70b879bd6e32a5965ca3e233e113d2ca0cafa028c2e9
@@ -0,0 +1,13 @@
1
+ module Admin
2
+ class RolesController < ApplicationController
3
+ before_filter :authenticate_user! # This is devise, ensure we're logged in.
4
+
5
+ layout (EffectiveRoles.layout.kind_of?(Hash) ? EffectiveRoles.layout[:admin_roles] : EffectiveRoles.layout)
6
+
7
+ def index
8
+ @page_title = 'Roles'
9
+
10
+ EffectiveOrders.authorized?(self, :admin, :effective_roles)
11
+ end
12
+ end
13
+ end
@@ -19,7 +19,8 @@ module EffectiveRolesHelper
19
19
  def effective_roles_summary_table(opts = {})
20
20
  raise 'Expected argument to be a Hash' unless opts.kind_of?(Hash)
21
21
 
22
- roles = Array(opts[:roles]).presence || EffectiveRoles.roles
22
+ roles = Array(opts[:roles]).presence
23
+ roles ||= EffectiveRoles.roles + [:signed_in, :signed_out]
23
24
 
24
25
  if opts[:only].present?
25
26
  klasses = Array(opts[:only])
@@ -82,6 +83,10 @@ module EffectiveRolesHelper
82
83
  content_tag(:span, 'Delete only', class: 'label label-warning')
83
84
  when :none
84
85
  content_tag(:span, 'No Access', class: 'label label-danger')
86
+ when :yes
87
+ content_tag(:span, 'Yes', class: 'label label-success')
88
+ when :no
89
+ content_tag(:span, 'No', class: 'label label-danger')
85
90
  when :unknown
86
91
  content_tag(:span, 'Unknown', class: 'label')
87
92
  else
@@ -90,8 +95,10 @@ module EffectiveRolesHelper
90
95
  end
91
96
 
92
97
  def effective_roles_authorization_label(klass)
93
- klass = klass.keys.first if klass.kind_of?(Hash)
98
+ # Custom permissions
99
+ return "#{klass.keys.first} #{klass.values.first}" if klass.kind_of?(Hash) && klass.length == 1
94
100
 
101
+ klass = klass.keys.first if klass.kind_of?(Hash)
95
102
  label = (klass.respond_to?(:name) ? klass.name : klass.to_s)
96
103
 
97
104
  ['Effective::Datatables::', 'Effective::'].each do |replace|
@@ -0,0 +1,3 @@
1
+ %h2= @page_title
2
+
3
+ = effective_roles_summary_table
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ mount EffectiveRoles::Engine => '/', as: 'effective_roles'
3
+ end
4
+
5
+ EffectiveRoles::Engine.routes.draw do
6
+ namespace :admin do
7
+ resources :roles, only: [:index]
8
+ end
9
+ end
@@ -5,6 +5,8 @@ module EffectiveRoles
5
5
  mattr_accessor :roles
6
6
  mattr_accessor :role_descriptions
7
7
 
8
+ mattr_accessor :layout
9
+
8
10
  mattr_accessor :assignable_roles
9
11
  mattr_accessor :disabled_roles
10
12
 
@@ -14,6 +16,8 @@ module EffectiveRoles
14
16
  yield self
15
17
  end
16
18
 
19
+ # This method converts whatever is given into its roles
20
+ # Pass an object, Integer, or Symbol to find corresponding role
17
21
  def self.roles_for(obj)
18
22
  if obj.respond_to?(:is_role_restricted?)
19
23
  obj.roles
@@ -57,17 +61,41 @@ module EffectiveRoles
57
61
 
58
62
  # Store the current ability (cancan support) and roles
59
63
  current_ability = controller.instance_variable_get(:@current_ability)
64
+ current_user = controller.instance_variable_get(:@current_user)
60
65
  current_user_roles = controller.current_user.roles
61
66
 
62
67
  # Set up the user, so the check is done with the desired permission level
63
68
  controller.instance_variable_set(:@current_ability, nil)
64
- controller.current_user.roles = [role]
69
+
70
+ case role
71
+ when :signed_in
72
+ controller.current_user.roles = []
73
+ when :signed_out
74
+ controller.instance_variable_set(:@current_user, nil)
75
+
76
+ if defined?(EffectiveLogging) && EffectiveLogging.respond_to?(:supressed?)
77
+ EffectiveLogging.supressed { (controller.request.env['warden'].set_user(false) rescue nil) }
78
+ else
79
+ (controller.request.env['warden'].set_user(false) rescue nil)
80
+ end
81
+ else
82
+ controller.current_user.roles = [role]
83
+ end
65
84
 
66
85
  # Find the actual authorization level
67
86
  level = _authorization_level(controller, role, resource, authorization_method_for_summary_table)
68
87
 
69
88
  # Restore the existing current_user stuff
89
+ if role == :signed_out
90
+ if defined?(EffectiveLogging) && EffectiveLogging.respond_to?(:supressed?)
91
+ EffectiveLogging.supressed { (controller.request.env['warden'].set_user(current_user) rescue nil) }
92
+ else
93
+ (controller.request.env['warden'].set_user(current_user) rescue nil)
94
+ end
95
+ end
96
+
70
97
  controller.instance_variable_set(:@current_ability, current_ability)
98
+ controller.instance_variable_set(:@current_user, current_user)
71
99
  controller.current_user.roles = current_user_roles
72
100
 
73
101
  level
@@ -99,7 +127,7 @@ module EffectiveRoles
99
127
  # Custom actions
100
128
  if resource.kind_of?(Hash)
101
129
  resource.each do |key, value|
102
- return value if (controller.instance_exec(controller, value, key, &auth_method) rescue false)
130
+ return (controller.instance_exec(controller, key, value, &auth_method) rescue false) ? :yes : :no
103
131
  end
104
132
  end
105
133
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveRoles
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = '1.3.6'.freeze
3
3
  end
@@ -71,10 +71,13 @@ EffectiveRoles.setup do |config|
71
71
  #
72
72
  # Or just keep it simple, and use this Array syntax of permissions for every resource
73
73
  #
74
- # config.unassignable_roles = [:member]
75
- config.disabled_roles = {
76
- 'User' => [:member]
77
- }
74
+ # config.disabled_roles = [:member]
75
+ #
76
+ # or
77
+ #
78
+ # config.disabled_roles = {
79
+ # 'User' => [:member]
80
+ # }
78
81
 
79
82
 
80
83
  # config.authorization_method_for_summary_table
@@ -86,4 +89,8 @@ EffectiveRoles.setup do |config|
86
89
  # Use CanCan: can?(action, resource)
87
90
  config.authorization_method_for_summary_table = Proc.new { |controller, action, resource| true }
88
91
 
92
+ # Layout Settings
93
+ # Configure the Layout per controller, or all at once
94
+ config.layout = 'application'
95
+
89
96
  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.3.5
4
+ version: 1.3.6
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: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -159,20 +159,25 @@ executables: []
159
159
  extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
+ - MIT-LICENSE
163
+ - README.md
164
+ - Rakefile
165
+ - app/controllers/admin/roles_controller.rb
162
166
  - app/helpers/effective_roles_helper.rb
163
167
  - app/models/concerns/acts_as_role_restricted.rb
168
+ - app/views/admin/roles/index.html.haml
164
169
  - app/views/effective/roles/_roles_fields.html.haml
165
170
  - app/views/effective/roles/_summary_table.html.haml
171
+ - config/routes.rb
172
+ - lib/effective_roles.rb
166
173
  - lib/effective_roles/engine.rb
167
174
  - lib/effective_roles/version.rb
168
- - lib/effective_roles.rb
169
175
  - lib/generators/effective_roles/install_generator.rb
170
- - lib/generators/templates/effective_roles.rb
171
176
  - lib/generators/templates/README
177
+ - lib/generators/templates/effective_roles.rb
172
178
  - lib/tasks/effective_roles_tasks.rake
173
- - MIT-LICENSE
174
- - Rakefile
175
- - README.md
179
+ - spec/dummy/README.rdoc
180
+ - spec/dummy/Rakefile
176
181
  - spec/dummy/app/assets/javascripts/application.js
177
182
  - spec/dummy/app/assets/stylesheets/application.css
178
183
  - spec/dummy/app/controllers/application_controller.rb
@@ -180,6 +185,7 @@ files:
180
185
  - spec/dummy/app/models/post.rb
181
186
  - spec/dummy/app/models/user.rb
182
187
  - spec/dummy/app/views/layouts/application.html.erb
188
+ - spec/dummy/config.ru
183
189
  - spec/dummy/config/application.rb
184
190
  - spec/dummy/config/boot.rb
185
191
  - spec/dummy/config/database.yml
@@ -194,11 +200,8 @@ files:
194
200
  - spec/dummy/config/initializers/session_store.rb
195
201
  - spec/dummy/config/initializers/wrap_parameters.rb
196
202
  - spec/dummy/config/routes.rb
197
- - spec/dummy/config.ru
198
203
  - spec/dummy/db/schema.rb
199
204
  - spec/dummy/db/test.sqlite3
200
- - spec/dummy/Rakefile
201
- - spec/dummy/README.rdoc
202
205
  - spec/effective_roles_spec.rb
203
206
  - spec/models/acts_as_role_restricted_spec.rb
204
207
  - spec/spec_helper.rb
@@ -223,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
226
  version: '0'
224
227
  requirements: []
225
228
  rubyforge_project:
226
- rubygems_version: 2.0.14
229
+ rubygems_version: 2.4.6
227
230
  signing_key:
228
231
  specification_version: 4
229
232
  summary: Assign multiple roles to any User or other ActiveRecord object. Select only