effective_roles 1.3.5 → 1.3.6
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 +4 -4
 - data/app/controllers/admin/roles_controller.rb +13 -0
 - data/app/helpers/effective_roles_helper.rb +9 -2
 - data/app/views/admin/roles/index.html.haml +3 -0
 - data/config/routes.rb +9 -0
 - data/lib/effective_roles.rb +30 -2
 - data/lib/effective_roles/version.rb +1 -1
 - data/lib/generators/templates/effective_roles.rb +11 -4
 - metadata +14 -11
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e7b3c3686d78be5fc3ac9d9a81fe5fad8901c03e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ae7e62f7cef4c2029709d448e7720f784c042c12
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
| 
      
 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 
     | 
    
         
            -
                 
     | 
| 
      
 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|
         
     | 
    
        data/config/routes.rb
    ADDED
    
    
    
        data/lib/effective_roles.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 130 
     | 
    
         
            +
                    return (controller.instance_exec(controller, key, value, &auth_method) rescue false) ? :yes : :no
         
     | 
| 
       103 
131 
     | 
    
         
             
                  end
         
     | 
| 
       104 
132 
     | 
    
         
             
                end
         
     | 
| 
       105 
133 
     | 
    
         | 
| 
         @@ -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. 
     | 
| 
       75 
     | 
    
         
            -
               
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       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. 
     | 
| 
      
 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:  
     | 
| 
      
 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 
     | 
    
         
            -
            -  
     | 
| 
       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. 
     | 
| 
      
 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
         
     |