avo 3.33.1 → 3.33.3

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: 251f54888bd2cc84f404a0d397b769ab791353f9f2786b3355fbecdc2f258a6c
4
- data.tar.gz: 74010e8c3b84085a6b52b9b47f396aadeb7beea85b43eeb2f9246a5abe15605d
3
+ metadata.gz: 200b12a38ae843d5fde2df57e2357296a00b906e317a540b217f2364f7a3ece9
4
+ data.tar.gz: 4ef2edde97478a40af551eac07a6d56ce959cd69f24e8a4585cb30eda263dc43
5
5
  SHA512:
6
- metadata.gz: ca5a2bb0a37b43afeb76fed59e7ace41c2ba8b2e7c8aeb498d404f82dd5bced610bb83c109ad86287f265c6ecd72615612318cb456b4cabe5147e5b391e067de
7
- data.tar.gz: bda30f213366f943b6cae6c7c7b89a09a249b8001145b52907f7e02b0941e61466b6fc50e2bd3e9d0c9771e44ad6d35dec2710e26661c874e299609c7df8bcbb
6
+ metadata.gz: 2f894d3007654c4d13f5938e741f298c77b1cd7aa15631c82a7612a6710415518b1bc4873df9a6da1357c2ec8fc7e0d137586471f46964b7e7f986268c698529
7
+ data.tar.gz: 847d1405db982c796931765a4499e4e7c1e74ef165a437a003c50a8b849aa57afccf9d9bad00768568f67dc1c203da9677d6d6131b3306ba78fc3d50d508cb8f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.33.1)
4
+ avo (3.33.3)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -14,6 +14,7 @@ module Avo
14
14
  before_action :set_attachment_record, only: [:create, :destroy]
15
15
  before_action :set_attach_fields, only: [:new, :create]
16
16
  before_action :authorize_index_action, only: :index
17
+ before_action :authorize_show_action, only: :show
17
18
  before_action :authorize_attach_action, only: [:new, :create]
18
19
  before_action :authorize_detach_action, only: :destroy
19
20
 
@@ -117,6 +118,9 @@ module Avo
117
118
  elsif has_many_reflection?
118
119
  @record.send(association_name).delete @attachment_record
119
120
  else
121
+ # `detach_*?` authorized the record in the URL, so only that one may be detached.
122
+ raise ActiveRecord::RecordNotFound unless @record.send(association_name) == @attachment_record
123
+
120
124
  @record.send(:"#{association_name}=", nil)
121
125
  end
122
126
 
@@ -185,6 +189,11 @@ module Avo
185
189
  authorize_if_defined "view_#{@field.id}?"
186
190
  end
187
191
 
192
+ def authorize_show_action
193
+ authorize_if_defined "view_#{@field.id}?"
194
+ @related_authorization.set_record(@related_record).authorize_action :show
195
+ end
196
+
188
197
  def authorize_attach_action
189
198
  authorize_if_defined "attach_#{@field.id}?"
190
199
  end
@@ -148,9 +148,9 @@ module Avo
148
148
  def set_related_record
149
149
  association_name = BaseResource.valid_association_name(@record, params[:related_name])
150
150
  @related_record = if @field.is_a? Avo::Fields::HasOneField
151
- @record.send association_name
151
+ @related_authorization.apply_policy(@record.association(association_name).scope).take!
152
152
  else
153
- @related_resource.find_record params[:related_id], query: @record.send(association_name), params: params
153
+ @related_resource.find_record params[:related_id], query: @related_authorization.apply_policy(@record.send(association_name)), params: params
154
154
  end
155
155
  @related_resource.hydrate(record: @related_record)
156
156
  end
@@ -221,6 +221,13 @@ module Avo
221
221
  @authorization.set_record(class_to_authorize).authorize_action action_to_authorize.to_sym
222
222
  end
223
223
 
224
+ # Records listed through a parent's association field are that field's panel, so they are listed
225
+ # with the panel's resource and policy, or another resource's policy scope would filter them.
226
+ def authorize_via_association(field, resource_class)
227
+ raise ActiveRecord::RecordNotFound unless field && resource_class == (field.use_resource || field.target_resource)
228
+ raise Avo::NotAuthorizedError unless field.authorized?
229
+ end
230
+
224
231
  def _authenticate!
225
232
  instance_eval(&Avo.configuration.authenticate)
226
233
  return if performed?
@@ -11,8 +11,9 @@ module Avo
11
11
  before_action :set_record_to_fill, only: [:new, :edit, :create, :update]
12
12
  before_action :detect_fields
13
13
  before_action :set_edit_title_and_breadcrumbs, only: [:edit, :update]
14
+ before_action :authorize_record_before_fill, only: :update
14
15
  before_action :fill_record, only: [:create, :update]
15
- # Don't run base authorizations for associations
16
+ # AssociationsController authorizes each of its actions itself, so a new action needs its own check
16
17
  before_action :authorize_base_action, except: :preview, if: -> { controller_name != "associations" }
17
18
  before_action :set_pagy_locale, only: :index
18
19
 
@@ -221,6 +222,12 @@ module Avo
221
222
 
222
223
  private
223
224
 
225
+ # `authorize_base_action` runs after filling, so a policy can check the submitted values. An existing
226
+ # record is also authorized as loaded, or submitting a new owner would make it pass an owner-only policy.
227
+ def authorize_record_before_fill
228
+ authorize_action @record
229
+ end
230
+
224
231
  def save_record
225
232
  perform_action_and_record_errors do
226
233
  save_record_action
@@ -2,6 +2,10 @@ require_dependency "avo/base_controller"
2
2
 
3
3
  module Avo
4
4
  class ChartsController < BaseController
5
+ # A chart summarizes the resource's index, or on an association page the association's panel,
6
+ # which `association_scope` authorizes.
7
+ before_action -> { authorize_action @resource.model_class, :index }, unless: :is_associated_summary
8
+
5
9
  def distribution_chart
6
10
  @values_summary = summary_query.group(params[:field_id].to_sym).reorder("count_all desc").count
7
11
 
@@ -34,11 +38,10 @@ module Avo
34
38
 
35
39
  parent_resource.detect_fields
36
40
 
37
- association_name = BaseResource.valid_association_name(parent_record, params[:association_name])
38
-
39
- parent_field = find_association_field(resource: parent_resource, association: association_name)
41
+ parent_field = find_association_field(resource: parent_resource, association: params[:association_name])
42
+ authorize_via_association parent_field, @resource.class
40
43
 
41
- association_query = parent_resource.authorization.apply_policy parent_record.send(association_name)
44
+ association_query = @resource.authorization.apply_policy parent_record.send(parent_field.association_name)
42
45
 
43
46
  if parent_field.scope.present?
44
47
  association_query = Avo::ExecutionContext.new(
@@ -129,6 +129,7 @@ module Avo
129
129
 
130
130
  # This scope is applied if the search is being performed on a has_many association
131
131
  def apply_has_many_scope
132
+ authorize_via_association field, resource
132
133
  association_name = BaseResource.valid_association_name(parent, params[:via_association_id])
133
134
 
134
135
  # Get association records
@@ -94,7 +94,7 @@
94
94
  field_id: field.id,
95
95
  via_record_id: @parent_record&.to_param,
96
96
  via_resource_class: @parent_resource&.class&.to_s,
97
- association_name: @field&.attribute_id
97
+ association_name: @field&.id
98
98
  }.compact
99
99
  ) %>"
100
100
  class="absolute inset-auto bg-white w-full sm:w-[400px] top-0 mt-6 p-4 z-40 shadow-modal rounded overflow-hidden hidden border border-gray-50"
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.33.1" unless const_defined?(:VERSION)
2
+ VERSION = "3.33.3" unless const_defined?(:VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.33.1
4
+ version: 3.33.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin