rails_admin_next 3.0.1 → 3.0.2

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
  SHA256:
3
- metadata.gz: ab5a6bc8f57c396848dea3a851d668da3604777f07674304de1b2eaab84074df
4
- data.tar.gz: 4b695b8d7a86cebf28db86e4f2730bfc081bfccb480c2279fb9fd8329407643f
3
+ metadata.gz: 50219c685864a241e7cca2ff03fbd7c0d8e7c3c9a1f49e65bb19b73f15924525
4
+ data.tar.gz: 37808fdd9c7012a71cd5e6973102dc0b3baf2c2fb7778a4c2eb0421ca4df585a
5
5
  SHA512:
6
- metadata.gz: 4b665f2830ea9086fcae2e1ba66c83b5dcd2000f4ebf1652fb161dccdfcf04d6353d17453ba26f3590a2e73d4cca54106fbb2fbe86a80c2e1d4da9fa0a4386fd
7
- data.tar.gz: bf1a98c7a6f8e14106f9460c1467099ef8c4a99755ffcc847b9d3f60364a9a9f03ad4f3e89781b60e5718df41654a7b7bb6c772b5b5350a9d29b0e1e2a0a7771
6
+ metadata.gz: 9a85fc8b87439b96f6910ec47d197d35d889dd4da565138982e25db0f039b7cbcef93178b98dae160f29ee8c701f7d3d58c827f85dc8b7172b8107536ac62f2b
7
+ data.tar.gz: d6b0b230e6ee33e864b9242fcff419197cc52e24220a007b0743585388ec96261c8bdb22b3384e2e79338d445cca4d26d4a4e7dd53f36ad48e1778a8179790ff
@@ -24,7 +24,7 @@ module RailsAdminNext
24
24
 
25
25
  helper_method :_current_user
26
26
 
27
- attr_reader :object, :model_config, :abstract_model, :authorization_adapter
27
+ attr_reader :object, :model_config, :abstract_model, :auditing_adapter, :authorization_adapter
28
28
 
29
29
  # nil without an authorization adapter. With one, a scope that is not a relation (nil, a
30
30
  # Hash, a Proc, an Array) comes from a broken policy and lists nothing: merged in, most of
data/docs/UPGRADING.md CHANGED
@@ -913,3 +913,13 @@ A `last_created_at` override in model config is not scoped for you. It runs with
913
913
  `bindings[:controller].authorization_scope(:index, abstract_model)`: the authorized relation, an
914
914
  empty one when the policy scope is broken, or `nil` without an authorization adapter. Calling the
915
915
  adapter's `query` directly skips that check.
916
+
917
+ ## History is hidden for a model PaperTrail does not version
918
+
919
+ With `config.audit_with :paper_trail`, a model without `has_paper_trail` no longer shows History
920
+ links, and its history pages list no versions. They used to fail with `NoMethodError`.
921
+
922
+ An auditing adapter may define `auditable?(abstract_model)`. When it answers false, the
923
+ `history_index` and `history_show` actions are hidden for that model. A custom adapter that does
924
+ not define it keeps the History links on every model, as before. A `visible` block you configure
925
+ on either history action replaces this check.
@@ -58,6 +58,11 @@ module RailsAdminNext
58
58
  )
59
59
  end
60
60
 
61
+ def auditable?
62
+ adapter = bindings[:controller].try(:auditing_adapter)
63
+ bindings[:abstract_model].nil? || !adapter.respond_to?(:auditable?) || adapter.auditable?(bindings[:abstract_model])
64
+ end
65
+
61
66
  # Is the action acting on the root level (Example: /admin/contact)
62
67
  register_instance_option :root? do
63
68
  false
@@ -14,6 +14,10 @@ module RailsAdminNext
14
14
  true
15
15
  end
16
16
 
17
+ register_instance_option :visible? do
18
+ authorized? && auditable?
19
+ end
20
+
17
21
  register_instance_option :route_fragment do
18
22
  "history"
19
23
  end
@@ -14,6 +14,10 @@ module RailsAdminNext
14
14
  true
15
15
  end
16
16
 
17
+ register_instance_option :visible? do
18
+ authorized? && auditable?
19
+ end
20
+
17
21
  register_instance_option :route_fragment do
18
22
  "history"
19
23
  end
@@ -114,6 +114,12 @@ module RailsAdminNext
114
114
  .collect { |version| VersionProxy.new(version, user_class) }
115
115
  end
116
116
 
117
+ # Optional in the auditing adapter contract: the history actions hide themselves for a model
118
+ # whose adapter answers false, and stay visible for an adapter that does not define it.
119
+ def auditable?(abstract_model)
120
+ versioned?(abstract_model.model)
121
+ end
122
+
117
123
  def delete_object(_object, _model, _user)
118
124
  # do nothing
119
125
  end
@@ -146,7 +152,11 @@ module RailsAdminNext
146
152
  sort_by
147
153
  end
148
154
 
149
- versions = object.nil? ? versions_for_model(model, scope) : object.public_send(model.model.versions_association_name)
155
+ versions =
156
+ if !auditable?(model) then version_class.none
157
+ elsif object.nil? then versions_for_model(model, scope)
158
+ else object.public_send(model.model.versions_association_name)
159
+ end
150
160
  versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
151
161
  versions = versions.reorder(sort)
152
162
 
@@ -7,7 +7,7 @@ module RailsAdminNext
7
7
  # the floor a local `gem build` produces.
8
8
  MAJOR = 3
9
9
  MINOR = 0
10
- PATCH = 1
10
+ PATCH = 2
11
11
  PRE = nil
12
12
 
13
13
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_next
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel López Prat