avo 2.52.0 → 2.53.0
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/components/avo/fields/belongs_to_field/autocomplete_component.rb +1 -1
- data/app/components/avo/fields/has_one_field/show_component.rb +1 -1
- data/app/components/avo/index/resource_controls_component.rb +5 -1
- data/app/components/avo/views/resource_index_component.rb +13 -3
- data/app/controllers/avo/application_controller.rb +1 -1
- data/app/controllers/avo/associations_controller.rb +15 -11
- data/app/controllers/avo/base_controller.rb +2 -2
- data/lib/avo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7c443e49863a73766cc92d676614d0bfe854f53fa9f72d1ee4913bb736753e0
|
4
|
+
data.tar.gz: 76c3b161d5c0d26665ac35dadc6d0429f4f075cb519eadd280427e8ad78608d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309e09c4271214c5bbcbdfd10a9f90617825c19ca93accb7c52db17e38fcce0e5761572f824aee98c5a7059e5e4be575776002df7592c5bd2cd833fc387b5157
|
7
|
+
data.tar.gz: 2d905a0da113e8e010fe639d258864a91b1ced97755d5a3ce03448c3921e943235ef3cc56aca88ffcb2396147868e10256dbec3124c7e574e1484c44699ddeb6
|
data/Gemfile.lock
CHANGED
@@ -41,7 +41,7 @@ class Avo::Fields::BelongsToField::AutocompleteComponent < ViewComponent::Base
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def reflection_class
|
44
|
-
has_polymorphic_association? ? polymorphic_class : @resource.model_class.
|
44
|
+
has_polymorphic_association? ? polymorphic_class : @resource.model_class.reflect_on_association(@field.id).klass
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
@@ -36,7 +36,7 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def create_path
|
39
|
-
association_id = @field.resource.model_class.
|
39
|
+
association_id = @field.resource.model_class.reflect_on_association(@field.id).inverse_of.name
|
40
40
|
|
41
41
|
args = {
|
42
42
|
via_relation: association_id,
|
@@ -77,7 +77,11 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def is_has_many_association?
|
80
|
-
@reflection.
|
80
|
+
@reflection.class.in? [
|
81
|
+
ActiveRecord::Reflection::HasManyReflection,
|
82
|
+
ActiveRecord::Reflection::HasAndBelongsToManyReflection,
|
83
|
+
ActiveRecord::Reflection::ThroughReflection
|
84
|
+
]
|
81
85
|
end
|
82
86
|
|
83
87
|
def referrer_path
|
@@ -62,10 +62,20 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def can_attach?
|
65
|
-
|
66
|
-
klass = @reflection.through_reflection if klass.is_a? ::ActiveRecord::Reflection::ThroughReflection
|
65
|
+
return false if has_reflection_and_is_read_only
|
67
66
|
|
68
|
-
@reflection.
|
67
|
+
reflection_class = if @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
|
68
|
+
@reflection.through_reflection.class
|
69
|
+
else
|
70
|
+
@reflection.class
|
71
|
+
end
|
72
|
+
|
73
|
+
return false unless reflection_class.in? [
|
74
|
+
ActiveRecord::Reflection::HasManyReflection,
|
75
|
+
ActiveRecord::Reflection::HasAndBelongsToManyReflection
|
76
|
+
]
|
77
|
+
|
78
|
+
authorize_association_for(:attach)
|
69
79
|
end
|
70
80
|
|
71
81
|
def create_path
|
@@ -226,7 +226,7 @@ module Avo
|
|
226
226
|
|
227
227
|
return field.use_resource if field&.use_resource.present?
|
228
228
|
|
229
|
-
reflection = @model.
|
229
|
+
reflection = @model.class.reflect_on_association(params[:related_name])
|
230
230
|
|
231
231
|
reflected_model = reflection.klass
|
232
232
|
|
@@ -62,7 +62,7 @@ module Avo
|
|
62
62
|
def create
|
63
63
|
association_name = BaseResource.valid_association_name(@model, params[:related_name])
|
64
64
|
|
65
|
-
if
|
65
|
+
if has_many_reflection?
|
66
66
|
@model.send(association_name) << @attachment_model
|
67
67
|
else
|
68
68
|
@model.send("#{association_name}=", @attachment_model)
|
@@ -80,7 +80,7 @@ module Avo
|
|
80
80
|
def destroy
|
81
81
|
association_name = BaseResource.valid_association_name(@model, params[:related_name])
|
82
82
|
|
83
|
-
if
|
83
|
+
if has_many_reflection?
|
84
84
|
@model.send(association_name).delete @attachment_model
|
85
85
|
else
|
86
86
|
@model.send("#{association_name}=", nil)
|
@@ -101,7 +101,7 @@ module Avo
|
|
101
101
|
private
|
102
102
|
|
103
103
|
def set_reflection
|
104
|
-
@reflection = @model.
|
104
|
+
@reflection = @model.class.reflect_on_association(params[:related_name])
|
105
105
|
end
|
106
106
|
|
107
107
|
def set_attachment_class
|
@@ -127,12 +127,11 @@ module Avo
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def reflection_class
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
klass
|
130
|
+
if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
|
131
|
+
@reflection.through_reflection.class
|
132
|
+
else
|
133
|
+
@reflection.class
|
134
|
+
end
|
136
135
|
end
|
137
136
|
|
138
137
|
def authorize_if_defined(method)
|
@@ -155,8 +154,6 @@ module Avo
|
|
155
154
|
authorize_if_defined "detach_#{@field.id}?"
|
156
155
|
end
|
157
156
|
|
158
|
-
private
|
159
|
-
|
160
157
|
def set_related_authorization
|
161
158
|
@related_authorization = if related_resource
|
162
159
|
related_resource.authorization(user: _current_user)
|
@@ -164,5 +161,12 @@ module Avo
|
|
164
161
|
Services::AuthorizationService.new _current_user
|
165
162
|
end
|
166
163
|
end
|
164
|
+
|
165
|
+
def has_many_reflection?
|
166
|
+
reflection_class.in? [
|
167
|
+
ActiveRecord::Reflection::HasManyReflection,
|
168
|
+
ActiveRecord::Reflection::HasAndBelongsToManyReflection
|
169
|
+
]
|
170
|
+
end
|
167
171
|
end
|
168
172
|
end
|
@@ -134,7 +134,7 @@ module Avo
|
|
134
134
|
|
135
135
|
# This means that the record has been created through another parent record and we need to attach it somehow.
|
136
136
|
if params[:via_resource_id].present? && params[:via_belongs_to_resource_class].nil?
|
137
|
-
@reflection = @model.
|
137
|
+
@reflection = @model.class.reflect_on_association(params[:via_relation])
|
138
138
|
# Figure out what kind of association does the record have with the parent record
|
139
139
|
|
140
140
|
# Fills in the required infor for belongs_to and has_many
|
@@ -148,7 +148,7 @@ module Avo
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# For when working with has_one, has_one_through, has_many_through, has_and_belongs_to_many, polymorphic
|
151
|
-
if @reflection.is_a? ActiveRecord::Reflection::
|
151
|
+
if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection) || @reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
|
152
152
|
# find the record
|
153
153
|
via_resource = ::Avo::App.get_resource_by_model_name(params[:via_relation_class]).dup
|
154
154
|
@related_record = via_resource.find_record params[:via_resource_id], params: params
|
data/lib/avo/version.rb
CHANGED
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: 2.
|
4
|
+
version: 2.53.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|