effective_datatables 2.4.1 → 2.4.2

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: 2f0b5d8833f49fa08b11c76ee4f49622ff13c72d
4
- data.tar.gz: 3b64fb8a94657715b230c1b47976c0c180afaeb4
3
+ metadata.gz: dd41f4b17a43b69b4164c73ec1c27333ff277423
4
+ data.tar.gz: ac99a8b3b030df212aef90af6600ce95545dede6
5
5
  SHA512:
6
- metadata.gz: 91119ca0ee5f73dfa6bcefd728cf18c9a4e4f0f5ba7522f1b242c4d44f11290d1a25139d7300f59f82e3710a1f8a34284e3a7eeca47800a493d4e91be02a0dc1
7
- data.tar.gz: 5caf11ca75774bb2133c8a67343a0b0aadb6f55e4b72b63136ecc459916d173bfe1105b5ae7e17a8b483d83582fd92a91bf8408da50cbc058fb8e2770119e2fa
6
+ metadata.gz: ce3b38c75aefba7aaedcbe339ed6ec87f59c878a8cac244c4f197d711efee35391bcf3498f1c775261bf2ca3f18b0288cd9a4b036711fd9a796c2ff2bb8953a3
7
+ data.tar.gz: ae522ad82d750f286ffe766eb205ac8417fc908558b62c1d9ffed46a17769d85e0e4fcd8c8ab53c1704aaa829517626e5aacd21e0d68501d93b349362f583ab1
data/README.md CHANGED
@@ -438,7 +438,7 @@ filterable # whether the dataTable is filterable
438
438
 
439
439
  ## actions_column
440
440
 
441
- Creates a column with links to this resource's Show, Edit and Destroy actions.
441
+ Creates a column with links to this resource's `show`, `edit` and `destroy` actions.
442
442
 
443
443
  Sets `responsivePriority: 0` so the column is last to collapse when the table is shrunk down.
444
444
 
@@ -448,7 +448,37 @@ Override the default actions by passing your own partial:
448
448
  actions_column partial: 'admin/posts/actions'
449
449
  ```
450
450
 
451
- Optionally uses the authorization method (below) to determine if the `current_user` has permission for each of these actions.
451
+ ### Showing action buttons
452
+
453
+ The show/edit/destroy action buttons can be configured to always show, always hide, or to consider the current_user's permission level.
454
+
455
+ To always show / hide:
456
+
457
+ ```ruby
458
+ actions_column show: false, edit: true, destroy: true, unarchive: true
459
+ ```
460
+
461
+ To authorize based on the current_user and the `config.authorization_method`:
462
+
463
+ ```ruby
464
+ actions_column show: :authorize
465
+ ```
466
+
467
+ The above will call the effective_datatables `config.authorization_method` just once to see if the current_user has permission to show/edit/destroy the collection class.
468
+
469
+ The action button will be displayed if `EffectiveDatatables.authorized?(controller, :edit, Post)` returns true.
470
+
471
+ To call authorize on each individual resource:
472
+
473
+ ```ruby
474
+ actions_column show: :authorize_each
475
+ ```
476
+
477
+ Or via a Proc:
478
+
479
+ ```ruby
480
+ actions_column show: Proc.new { |resource| can?(:show, resource.parent) }
481
+ ```
452
482
 
453
483
  See the `config/initializers/effective_datatable.rb` file for more information.
454
484
 
@@ -89,6 +89,8 @@ module Effective
89
89
  end
90
90
  end
91
91
 
92
+ # If locals[:show_action] == :authorize_each, this will get run again.
93
+
92
94
  rendered[name] = (render(
93
95
  :partial => opts[:partial],
94
96
  :as => opts[:partial_local],
@@ -1,3 +1,28 @@
1
+ :ruby
2
+ if show_action == :authorize_each
3
+ show_action = (EffectiveDatatables.authorized?(controller, :show, resource) rescue false)
4
+ elsif show_action.respond_to?(:call)
5
+ show_action = instance_exec(resource, &show_action)
6
+ end
7
+
8
+ if edit_action == :authorize_each
9
+ edit_action = (EffectiveDatatables.authorized?(controller, :edit, resource) rescue false)
10
+ elsif edit_action.respond_to?(:call)
11
+ edit_action = instance_exec(resource, &edit_action)
12
+ end
13
+
14
+ if destroy_action == :authorize_each
15
+ destroy_action = (EffectiveDatatables.authorized?(controller, :destroy, resource) rescue false)
16
+ elsif destroy_action.respond_to?(:call)
17
+ destroy_action = instance_exec(resource, &destroy_action)
18
+ end
19
+
20
+ if unarchive_action == :authorize_each
21
+ unarchive_action = (EffectiveDatatables.authorized?(controller, :unarchive, resource) rescue false)
22
+ elsif unarchive_action.respond_to?(:call)
23
+ unarchive_action = instance_exec(resource, &unarchive_action)
24
+ end
25
+
1
26
  - if show_action
2
27
  - url = (polymorphic_path([*controller_namespace, resource]) rescue nil) || (polymorphic_path(resource) rescue nil)
3
28
  - if url.present?
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.4.1'.freeze
2
+ VERSION = '2.4.2'.freeze
3
3
  end
@@ -41,14 +41,20 @@ EffectiveDatatables.setup do |config|
41
41
  # Valid values for each action are:
42
42
  # true (always include a link to this action)
43
43
  # false (never include a link to this action)
44
- # :authorize (include link only if authorized - only works with ActiveRecord collections)
44
+ # :authorize (include link only if authorized to show/edit/destroy the resource class)
45
+ # :authorize_each (include link only if authorized to show/edit/destroy the resource)
46
+ # Proc.new { |resource| can?(:edit, resource.parent) }
45
47
  #
46
- # When :authorize, a single check will be made via the above authorization_method
48
+ # When :authorize, a single check will be made via the above config.authorization_method
47
49
  # to see if the current_user has permission to :show/:edit/:destroy the collection class, i.e. Post
48
50
  # EffectiveDatatables.authorized? (:show || :edit || :destroy), Post
51
+ # This is a faster permission check, because it only checks the class once
49
52
  #
50
- # For performance reasons, we only check the class once, not every individual resource.
51
- # You can override this default by calling `actions_column show: false, edit: true, destroy: :authorize`
53
+ # If you want to authorize each individual resource, use :authorize_each
54
+ # EffectiveDatatables.authorized? (:show || :edit || :destroy), Post.find(1)
55
+ #
56
+ # You can override these defaults on a per-table basis
57
+ # by calling `actions_column(show: false, edit: true, destroy: :authorize)`
52
58
  config.actions_column = {
53
59
  show: :authorize,
54
60
  edit: :authorize,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
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-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails