spree_admin_roles_and_access 2.0.0 → 3.2.1.beta

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -39
  3. data/app/assets/javascripts/spree/backend/spree_admin_roles_and_access.js +84 -1
  4. data/app/assets/stylesheets/spree/backend/spree_admin_roles_and_access.css +131 -1
  5. data/app/controllers/spree/admin/base_controller_decorator.rb +4 -0
  6. data/app/controllers/spree/admin/default_admin_dashboards_controller.rb +13 -0
  7. data/app/controllers/spree/admin/permission_sets_controller.rb +26 -0
  8. data/app/controllers/spree/admin/roles_controller.rb +5 -5
  9. data/app/models/spree/ability_decorator.rb +6 -5
  10. data/app/models/spree/permission.rb +11 -3
  11. data/app/models/spree/permission_set.rb +11 -0
  12. data/app/models/spree/permissions_permission_set.rb +6 -0
  13. data/app/models/spree/role_decorator.rb +8 -2
  14. data/app/models/spree/roles_permission.rb +5 -0
  15. data/app/models/spree/roles_permission_set.rb +6 -0
  16. data/app/models/spree/user_decorator.rb +2 -1
  17. data/app/overrides/spree/admin/roles/_form/add_permission_sets_to_role_form.html.erb.deface +28 -0
  18. data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_permission_sets_To_configuration_sub_menu.html.erb.deface +2 -0
  19. data/app/views/spree/admin/default_admin_dashboards/show.html.erb +1 -0
  20. data/app/views/spree/admin/permission_sets/_form.html.erb +49 -0
  21. data/app/views/spree/admin/permission_sets/_permission_pane.html.erb +19 -0
  22. data/app/views/spree/admin/permission_sets/edit.html.erb +12 -0
  23. data/app/views/spree/admin/permission_sets/index.html.erb +33 -0
  24. data/app/views/spree/admin/permission_sets/new.html.erb +12 -0
  25. data/app/views/spree/admin/permissions/_form.html.erb +37 -6
  26. data/app/views/spree/admin/permissions/index.html.erb +0 -2
  27. data/app/views/spree/admin/shared/_checkbox_list_pane.html.erb +20 -0
  28. data/config/initializers/auth.rb +13 -0
  29. data/config/initializers/cancan_ability.rb +1 -1
  30. data/config/initializers/cancan_controller_additions.rb +3 -3
  31. data/config/initializers/constants.rb +2 -2
  32. data/config/locales/en.yml +15 -1
  33. data/config/routes.rb +2 -0
  34. data/db/migrate/20130709104101_create_spree_permissions.rb +4 -4
  35. data/db/migrate/20130709104945_create_spree_roles_permissions.rb +3 -3
  36. data/db/migrate/20130709105614_add_editable_is_default_and_index_on_editable_is_default_and_name_to_spree_roles.rb +2 -3
  37. data/db/migrate/20170503090436_create_spree_permission_sets.rb +9 -0
  38. data/db/migrate/20170503091013_create_spree_roles_permission_sets.rb +8 -0
  39. data/db/migrate/20170503101648_create_spree_permissions_permission_sets.rb +8 -0
  40. data/db/migrate/20170508082615_add_description_to_permissions_and_permission_sets.rb +6 -0
  41. data/db/migrate/20170508082722_add_display_boolean_to_permission_sets.rb +5 -0
  42. data/db/migrate/20170508091139_deprecate_legacy_roles_and_permissions.rb +29 -0
  43. data/db/migrate/20170509082144_remove_column_boolean_from_permissions.rb +5 -0
  44. data/db/migrate/20170509090346_add_admin_boolean_to_roles.rb +5 -0
  45. data/lib/generators/spree_admin_roles_and_access/install/install_generator.rb +3 -3
  46. data/lib/spree/permissions.rb +7 -7
  47. data/lib/tasks/populate.rake +354 -72
  48. metadata +70 -17
  49. data/app/overrides/spree/admin/roles/_form/add_permissions_to_role_form.html.erb.deface +0 -13
@@ -1,8 +1,8 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class RolesController < ResourceController
4
- before_filter :load_permissions, :only => [:edit, :new, :create, :update]
5
- before_filter :restrict_unless_editable, :only => [:edit, :update]
4
+ before_action :load_permission_sets, only: [:edit, :new, :create, :update]
5
+ before_action :restrict_unless_editable, only: [:edit, :update]
6
6
 
7
7
  def index
8
8
  @roles = Spree::Role.page(params[:page])
@@ -10,11 +10,11 @@ module Spree
10
10
 
11
11
  private
12
12
  def permitted_resource_params
13
- params.require(:role).permit(:name, :permission_ids => [])
13
+ params.require(:role).permit(:name, :admin_accessible, :is_default, permission_set_ids: [])
14
14
  end
15
15
 
16
- def load_permissions
17
- @permissions = Spree::Permission.visible.all
16
+ def load_permission_sets
17
+ @permission_sets = Spree::PermissionSet.order(:created_at)
18
18
  end
19
19
 
20
20
  def restrict_unless_editable
@@ -4,11 +4,12 @@ module Spree
4
4
  def initialize(user)
5
5
  self.clear_aliased_actions
6
6
 
7
- alias_action :edit, :to => :update
8
- alias_action :new, :to => :create
9
- alias_action :new_action, :to => :create
10
- alias_action :show, :to => :read
11
- alias_action :delete, :to => :destroy
7
+ alias_action :edit, to: :update
8
+ alias_action :new, to: :create
9
+ alias_action :new_action, to: :create
10
+ alias_action :show, to: :read
11
+ alias_action :index, to: :read
12
+ alias_action :delete, to: :destroy
12
13
 
13
14
  user ||= Spree.user_class.new
14
15
 
@@ -4,14 +4,22 @@ module Spree
4
4
 
5
5
  default_scope { order(:priority) }
6
6
 
7
- has_and_belongs_to_many :roles, :join_table => 'spree_roles_permissions', :class_name => 'Spree::Role'
7
+ # DEPRECATED: Use permission sets instead only here for aiding migration for existing users
8
+ has_and_belongs_to_many :legacy_roles, join_table: 'spree_roles_permissions', class_name: 'Spree::Role'
8
9
 
9
- validates :title, :presence => true, :uniqueness => true
10
+ has_many :permissions_permission_sets, dependent: :destroy
11
+ has_many :permission_sets, through: :permissions_permission_sets
10
12
 
11
- scope :visible, lambda { where(:visible => true) }
13
+ validates :title, presence: true, uniqueness: true
14
+
15
+ scope :visible, lambda { where(visible: true) }
12
16
 
13
17
  def ability(current_ability, user)
14
18
  send(title, current_ability, user)
15
19
  end
20
+
21
+ def name
22
+ title.gsub('-', '_').humanize
23
+ end
16
24
  end
17
25
  end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class PermissionSet < ActiveRecord::Base
3
+ has_many :permissions_permission_sets, dependent: :destroy
4
+ has_many :permissions, through: :permissions_permission_sets
5
+ has_many :roles_permission_sets, dependent: :destroy
6
+ has_many :roles, through: :roles_permission_sets
7
+
8
+ validates :name, presence: true, uniqueness: true
9
+ validates :permissions, length: { minimum: 1, too_short: Spree.t(:atleast_one_permission_is_required) }, on: :update
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class PermissionsPermissionSet < ActiveRecord::Base
3
+ belongs_to :permission
4
+ belongs_to :permission_set
5
+ end
6
+ end
@@ -1,8 +1,14 @@
1
1
  Spree::Role.class_eval do
2
2
 
3
- has_and_belongs_to_many :permissions, :join_table => 'spree_roles_permissions', :class_name => 'Spree::Permission'
3
+ has_many :roles_permission_sets, dependent: :destroy
4
+ has_many :permission_sets, through: :roles_permission_sets
5
+ has_many :permissions, through: :permission_sets
6
+
7
+ # DEPRECATED: Use permission sets instead. Only here for aiding migration for existing users
8
+ has_and_belongs_to_many :legacy_permissions, join_table: 'spree_roles_permissions', class_name: 'Spree::Permission'
4
9
 
5
10
  validates :name, uniqueness: true, allow_blank: true
11
+ validates :permission_sets, length: { minimum: 1, too_short: Spree.t(:atleast_one_permission_set_is_required) }, on: :update
6
12
 
7
13
  def ability(current_ability, user)
8
14
  permissions.each do |permission|
@@ -14,5 +20,5 @@ Spree::Role.class_eval do
14
20
  permissions.pluck(:title).include?(permission_title)
15
21
  end
16
22
 
17
- scope :default_role, lambda { where(:is_default => true) }
23
+ scope :default_role, lambda { where(is_default: true) }
18
24
  end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class RolesPermission < ActiveRecord::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class RolesPermissionSet < ActiveRecord::Base
3
+ belongs_to :role
4
+ belongs_to :permission_set
5
+ end
6
+ end
@@ -1,5 +1,6 @@
1
1
  module Spree
2
2
  Spree.user_class.class_eval do
3
- has_and_belongs_to_many :roles, join_table: 'spree_roles_users', class_name: 'Spree::Role'
3
+ has_many :spree_role_users, class_name: 'Spree::RoleUser'
4
+ has_many :roles, through: :spree_role_users, class_name: 'Spree::Role'
4
5
  end
5
6
  end
@@ -0,0 +1,28 @@
1
+ <!-- insert_bottom "[data-hook='additional_role_fields']" -->
2
+
3
+ <%= f.field_container :is_default, class: ['form-group'] do %>
4
+ <%= f.label :is_default, Spree.t(:is_default) %>
5
+ <%= f.check_box :is_default %>
6
+ <p class="help-block"><%= Spree.t(:role_is_default_help) %></p>
7
+ <%= f.error_message_on :is_default, class: 'error-message' %>
8
+ <% end %>
9
+
10
+ <%= f.field_container :admin_accessible, class: ['form-group'] do %>
11
+ <%= f.label :admin_accessible, Spree.t(:admin_accessible) %>
12
+ <%= f.check_box :admin_accessible %>
13
+ <p class="help-block"><%= Spree.t(:role_admin_accessible_help) %></p>
14
+ <%= f.error_message_on :admin_accessible, class: 'error-message' %>
15
+ <% end %>
16
+
17
+ <%= f.field_container :permission_sets, class: ['form-group input-group col-xs-12'] do %>
18
+ <%= hidden_field_tag 'role[permission_set_ids][]', [] %>
19
+ <div data-hook="admin_role_form_permission_sets" class="form-group">
20
+ <%- @role.permission_sets.to_a %>
21
+ <div class="searchable-scrollable-list">
22
+ <% @permission_sets.group_by { |permission_set| permission_set.display_permission? ? 'Display Permission' : 'Management Permission' }.each do |title, permission_sets| %>
23
+ <%= render 'spree/admin/shared/checkbox_list_pane', { items: permission_sets, title: title, is_checked: lambda { |x| @role.permission_sets.include? x}, field: 'role[permission_set_ids][]' } %>
24
+ <% end %>
25
+ </div>
26
+ </div>
27
+ <%= f.error_message_on :permission_sets %>
28
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <!-- insert_bottom "[data-hook='admin_configurations_sidebar_menu']" -->
2
+ <%= configurations_sidebar_menu_item(Spree.t(:permission_sets), spree.admin_permission_sets_path) if can? :manage, Spree::PermissionSet %>
@@ -0,0 +1 @@
1
+ <h2>Logged in as admin</h2>
@@ -0,0 +1,49 @@
1
+ <div class="alert alert-info"><%= Spree.t(:permission_set_admin_permission_required) %></div>
2
+
3
+ <div data-hook="admin_permission_set_form_fields">
4
+ <div class="inline-input-row col-xs-12">
5
+ <%= f.field_container :name, class: ['form-group input-group input-group-md'] do %>
6
+ <%= f.label :name, Spree.t(:permission_set_name), class: 'sr-only' %><span class="required"></span>
7
+ <%= f.text_field :name, class: 'form-control full-width-input', placeholder: 'Name of the permission set' %>
8
+ <%= f.error_message_on :name, class: 'help-block' %>
9
+ <% end %>
10
+ <%= f.field_container :description, class: ['form-group input-group input-group-md'] do %>
11
+ <%= f.label :description, Spree.t(:permission_set_description), class: 'sr-only' %>
12
+ <%= f.text_field :description, class: 'form-control full-width-input', placeholder: 'This permission set allows the role to...' %>
13
+ <%= f.error_message_on :description, class: 'help-block' %>
14
+ <% end %>
15
+ </div>
16
+
17
+ <%= f.field_container :display_permission, class: ['form-group'] do %>
18
+ <%= f.label :display_permission, Spree.t(:permission_set_display_permission) %>
19
+ <%= f.check_box :display_permission %>
20
+ <p class="help-block"><%= Spree.t(:permission_set_display_permission_help) %></p>
21
+ <%= f.error_message_on :display_permission %>
22
+ <% end %>
23
+
24
+ <%= f.field_container :permissions, class: ['form-group input-group col-xs-12'] do %>
25
+ <%= hidden_field_tag 'permission_set[permission_ids][]', [] %>
26
+ <%- @permission_set.permissions.to_a %>
27
+ <div class="searchable-scrollable-list">
28
+ <%- p_groups = @permissions.group_by { |permission|
29
+ if permission.title.include?('can-read')
30
+ 'Read Permissions'
31
+ elsif permission.title.include?('can-manage')
32
+ 'Manage Permissions'
33
+ else
34
+ 'Other Permissions'
35
+ end
36
+ } %>
37
+ <% ['Read Permissions', 'Manage Permissions', 'Other Permissions'].each do |title| %>
38
+ <%= render 'spree/admin/shared/checkbox_list_pane', {
39
+ items: p_groups[title],
40
+ title: title,
41
+ is_checked: lambda { |x| @permission_set.permissions.include? x },
42
+ field: 'permission_set[permission_ids][]'
43
+ } %>
44
+ <% end %>
45
+ </div>
46
+ <%= f.error_message_on :permissions %>
47
+ <% end %>
48
+ <div data-hook="additional_permission_fields"></div>
49
+ </div>
@@ -0,0 +1,19 @@
1
+ <%- selected_count = items.select { |item| is_checked.call(item) }.count %>
2
+ <%- available_count = items.count %>
3
+ <div class="panel-group scrollable-list-group-item">
4
+ <div class="panel panel-default">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= title %><span class="badge pull-right count"><%= selected_count %>/<%= available_count %></span></h3>
7
+ </div>
8
+ <ul class="list-group">
9
+ <% items.each do |item| %>
10
+ <li class="<%= is_checked.call(item) ? 'list-group-item-success list-group-item' : 'list-group-item' %>">
11
+ <%= label_tag do %>
12
+ <%= check_box_tag field, item.id, is_checked.call(item), class: 'hide' %>
13
+ <%= render item_partial, { item: item } %>
14
+ <% end %>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ </div>
19
+ </div>
@@ -0,0 +1,12 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:editing_resource, resource: Spree::PermissionSet.model_name.human) %>
3
+ <% end %>
4
+
5
+ <%= form_for [:admin, @permission_set], { html: { class: 'form-inline centered-floating-buttons' } } do |f| %>
6
+ <div class="form-fields-group">
7
+ <%= render partial: 'form', locals: { f: f } %>
8
+ </div>
9
+ <div class="fixed-bottom-button-group text-center">
10
+ <%= render partial: 'spree/admin/shared/edit_resource_links' %>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,33 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:permission_sets) %>
3
+ <% end %>
4
+
5
+ <% if can? :create, Spree::PermissionSet %>
6
+ <% content_for :page_actions do %>
7
+ <%= button_link_to Spree.t(:new_permission_set), new_object_url, class: 'btn btn-success', icon: 'add', id: 'admi_new_permission_set_link' %>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <% if @permission_sets.present? %>
12
+ <table class="table">
13
+ <thead>
14
+ <tr data-hook="admin_permission_sets_index_headers">
15
+ <th><%= sort_link @search, :name, Spree.t(:permission_set_name) %></th>
16
+ <th><%= sort_link @search, :updated_at, Spree.t(:permission_set_last_updated)%></th>
17
+ <th class="actions"></th>
18
+ </tr>
19
+ </thead>
20
+ <tbody>
21
+ <% @permission_sets.each do |permission_set| %>
22
+ <tr id="<%= spree_dom_id permission_set %>" data-hook="admin_permissions_index_rows">
23
+ <td><%= permission_set.name %></td>
24
+ <td title="<%= permission_set.updated_at %>"><%= time_ago_in_words(permission_set.updated_at) %> ago</td>
25
+ <td class="actions text-right">
26
+ <%= link_to_edit(permission_set, no_text: true) if can? :edit, permission_set %>
27
+ <%= link_to_delete(permission_set, no_text: true) if can? :destroy, permission_set %>
28
+ </td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:new_permission_set) %>
3
+ <% end %>
4
+
5
+ <%= form_for [:admin, @permission_set], html: { class: 'form-inline centered-floating-buttons' } do |f| %>
6
+ <div class="form-fields-group">
7
+ <%= render partial: 'form', locals: { f: f } %>
8
+ </div>
9
+ <div class="fixed-bottom-button-group text-center">
10
+ <%= render partial: 'spree/admin/shared/new_resource_links' %>
11
+ </div>
12
+ <% end %>
@@ -1,20 +1,51 @@
1
+ <div class="panel-group" id="permission-writing-guide">
2
+ <div class="panel panel-info">
3
+ <div class="panel-heading" role="button" data-toggle="collapse" data-target="#permission-list-guide">
4
+ <h3 class="panel-title">Pattern of the permissions <i class="icon icon-circle-arrow-right"></i></h3>
5
+ </div>
6
+
7
+ <ul class="list-group collapse" id="permission-list-guide">
8
+ <li class="list-group-item">Can/cannot - specifies whether the user with that permission can do or cannot do that task.</li>
9
+ <li class="list-group-item">Action - specifies the action which can be done by that model or subject like update, index, create etc. There is a special action called manage which matches every action.</li>
10
+ <li class="list-group-item">Subject - specified the model like products, users etc. of which the permission is given. There is an special subject called all which matches every subject.</li>
11
+ <li class="list-group-item">Attributes - specifies the attributes for which the permission is specified. Read-only actions shouldn't require this like index, read etc. But it is more secure if we specify them in other actions like create or update.</li>
12
+ </ul>
13
+ </div>
14
+
15
+ <div class="panel panel-info">
16
+ <div class="panel-heading" role="button" data-toggle="collapse" data-target="#permission-example">
17
+ <h3 class="panel-title">Some examples of permissions <i class="icon icon-circle-arrow-right"></i></h3>
18
+ </div>
19
+
20
+ <ul class="list-group collapse" id="permission-example">
21
+ <li class="list-group-item">can-manage-spree/product - can perform every action on Spree::Product but not on any other model or subject.</li>
22
+ <li class="list-group-item">can-update-all - can update all models or subjects.</li>
23
+ <li class="list-group-item">can-update-spree/product - can update only products, and not users, orders and other things.</li>
24
+ <li class="list-group-item">can-update-spree/product-price - can update only price of products.</li>
25
+ <li class="list-group-item">can-manage-all - can perform every action on all models.</li>
26
+ </ul>
27
+ </div>
28
+ </div>
29
+
1
30
  <div data-hook="admin_permission_form_fields">
2
31
  <div data-hook="permission_title" class="form-group">
3
32
  <%= f.label :title, Spree.t(:permission_title) %> <span class="required">*</span>
4
33
  <%= f.text_field :title, class: 'form-control' %>
34
+ <a href="#permission-writing-guide" class="help-block">help</a>
35
+ </div>
36
+ <div data-hook="permission_description" class="form-group">
37
+ <%= f.label :description, Spree.t(:permission_description) %>
38
+ <%= f.text_field :description, class: 'form-control', placeholder: 'This allows the permitted user to..' %>
5
39
  </div>
6
40
  <div data-hook="permission_priority" class="form-group">
7
41
  <%= f.label :priority, Spree.t(:permission_priority) %> <span class="required">*</span>
8
42
  <%= f.number_field :priority, in: 0..9, step: 1, class: 'form-control' %>
43
+ <p class="help-block"><%= Spree.t(:permission_priority_help) %></p>
9
44
  </div>
10
45
  <div data-hook="permission_visible" class="checkbox">
11
46
  <label>
12
- <%= f.check_box :visible, value: true %><%= Spree.t(:permission_visible) %>
13
- </label>
14
- </div>
15
- <div data-hook="permission_boolean" class="checkbox">
16
- <label>
17
- <%= f.check_box :boolean, value: true %> <%= Spree.t(:permission_boolean) %>
47
+ <%= f.check_box :visible, value: true %><%= Spree.t(:permission_visible) %>
48
+ <p class="help-block"><%= Spree.t(:permission_visible_help) %></p>
18
49
  </label>
19
50
  </div>
20
51
 
@@ -13,7 +13,6 @@
13
13
  <th><%= Spree.t(:permission_title) %></th>
14
14
  <th><%= Spree.t(:permission_priority) %></th>
15
15
  <th><%= Spree.t(:permission_visible) %></th>
16
- <th><%= Spree.t(:permission_boolean) %></th>
17
16
  <th class="actions"></th>
18
17
  </tr>
19
18
  </thead>
@@ -23,7 +22,6 @@
23
22
  <td><%= permission.title %></td>
24
23
  <td><%= permission.priority %></td>
25
24
  <td><%= permission.visible %></td>
26
- <td><%= permission.boolean %></td>
27
25
  <td class="actions text-right">
28
26
  <%= link_to_edit(permission, no_text: true) if can? :edit, permission %>
29
27
  <%= link_to_delete(permission, no_text: true) if can? :destroy, permission %>
@@ -0,0 +1,20 @@
1
+ <%- selected_count = items.select { |item| is_checked.call(item) }.count %>
2
+ <%- available_count = items.count %>
3
+ <div class="panel-group scrollable-list-group-item">
4
+ <div class="panel panel-default">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= title %><span class="badge pull-right count"><%= selected_count %>/<%= available_count %></span></h3>
7
+ </div>
8
+ <ul class="list-group">
9
+ <% items.each do |item| %>
10
+ <li class="<%= is_checked.call(item) ? 'list-group-item-success list-group-item checkbox-list-pane' : 'list-group-item checkbox-list-pane' %>">
11
+ <%= label_tag do %>
12
+ <%= check_box_tag field, item.id, is_checked.call(item), class: 'hide' %>
13
+ <p><strong><%= item.name %></strong></p>
14
+ <p><%= item.description %></p>
15
+ <% end %>
16
+ </li>
17
+ <% end %>
18
+ </ul>
19
+ </div>
20
+ </div>
@@ -0,0 +1,13 @@
1
+ module Spree::Core::ControllerHelpers::Auth
2
+ alias_method :original_redirect_unauthorized_access, :redirect_unauthorized_access
3
+
4
+ def redirect_unauthorized_access
5
+ if try_spree_current_user && try_spree_current_user.roles.any?(&:admin_accessible?)
6
+ request_path = request.fullpath
7
+ flash[:notice] = Spree.t(:unable_to_access_requested_resource, request_path: request_path)
8
+ redirect_to admin_default_admin_dashboard_path
9
+ else
10
+ original_redirect_unauthorized_access
11
+ end
12
+ end
13
+ end
@@ -28,4 +28,4 @@ CanCan::Ability.module_eval do
28
28
  def cannot(*args, &block)
29
29
  rules << CanCan::Rule.new(false, *args, &block)
30
30
  end
31
- end
31
+ end
@@ -1,11 +1,11 @@
1
1
  CanCan::ControllerAdditions.class_eval do
2
- # specs of #authorize_with_attributes! is written in authorize_admin in roles_controller_spec
2
+ # specs of #authorize_with_attributes! is written in authorize_admin in roles_controller_spec
3
3
  def authorize_with_attributes!(action, subject, attributes = [])
4
- attributes = attributes.keys if attributes.is_a?(Hash)
4
+ attributes = attributes.keys if attributes.respond_to?(:keys)
5
5
  if attributes.is_a? Array
6
6
  attributes.each { |attribute| authorize!(action, subject, attribute) }
7
7
  else
8
8
  authorize!(action, subject)
9
9
  end
10
10
  end
11
- end
11
+ end