avo 3.33.2 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/avo/associations_controller.rb +3 -0
- data/app/controllers/avo/base_application_controller.rb +8 -1
- data/app/controllers/avo/base_controller.rb +7 -0
- data/app/controllers/avo/charts_controller.rb +7 -4
- data/app/controllers/avo/search_controller.rb +1 -0
- data/app/views/avo/partials/_table_header.html.erb +1 -1
- data/lib/avo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 200b12a38ae843d5fde2df57e2357296a00b906e317a540b217f2364f7a3ece9
|
|
4
|
+
data.tar.gz: 4ef2edde97478a40af551eac07a6d56ce959cd69f24e8a4585cb30eda263dc43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f894d3007654c4d13f5938e741f298c77b1cd7aa15631c82a7612a6710415518b1bc4873df9a6da1357c2ec8fc7e0d137586471f46964b7e7f986268c698529
|
|
7
|
+
data.tar.gz: 847d1405db982c796931765a4499e4e7c1e74ef165a437a003c50a8b849aa57afccf9d9bad00768568f67dc1c203da9677d6d6131b3306ba78fc3d50d508cb8f
|
data/Gemfile.lock
CHANGED
|
@@ -118,6 +118,9 @@ module Avo
|
|
|
118
118
|
elsif has_many_reflection?
|
|
119
119
|
@record.send(association_name).delete @attachment_record
|
|
120
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
|
+
|
|
121
124
|
@record.send(:"#{association_name}=", nil)
|
|
122
125
|
end
|
|
123
126
|
|
|
@@ -148,7 +148,7 @@ 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.
|
|
151
|
+
@related_authorization.apply_policy(@record.association(association_name).scope).take!
|
|
152
152
|
else
|
|
153
153
|
@related_resource.find_record params[:related_id], query: @related_authorization.apply_policy(@record.send(association_name)), params: params
|
|
154
154
|
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,6 +11,7 @@ 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
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" }
|
|
@@ -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
|
-
|
|
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 =
|
|
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&.
|
|
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