forest_admin_agent 1.12.13 → 1.12.15
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/lib/forest_admin_agent/routes/abstract_authenticated_route.rb +8 -6
- data/lib/forest_admin_agent/routes/abstract_related_route.rb +9 -7
- data/lib/forest_admin_agent/routes/abstract_route.rb +7 -3
- data/lib/forest_admin_agent/routes/action/actions.rb +31 -25
- data/lib/forest_admin_agent/routes/capabilities/collections.rb +4 -4
- data/lib/forest_admin_agent/routes/charts/api_chart_collection.rb +10 -10
- data/lib/forest_admin_agent/routes/charts/api_chart_datasource.rb +8 -7
- data/lib/forest_admin_agent/routes/charts/charts.rb +64 -66
- data/lib/forest_admin_agent/routes/request_context.rb +17 -0
- data/lib/forest_admin_agent/routes/resources/count.rb +9 -9
- data/lib/forest_admin_agent/routes/resources/csv.rb +11 -11
- data/lib/forest_admin_agent/routes/resources/delete.rb +20 -19
- data/lib/forest_admin_agent/routes/resources/list.rb +14 -14
- data/lib/forest_admin_agent/routes/resources/native_query.rb +9 -9
- data/lib/forest_admin_agent/routes/resources/related/associate_related.rb +32 -29
- data/lib/forest_admin_agent/routes/resources/related/count_related.rb +9 -9
- data/lib/forest_admin_agent/routes/resources/related/csv_related.rb +10 -9
- data/lib/forest_admin_agent/routes/resources/related/dissociate_related.rb +63 -40
- data/lib/forest_admin_agent/routes/resources/related/list_related.rb +12 -11
- data/lib/forest_admin_agent/routes/resources/related/update_related.rb +60 -52
- data/lib/forest_admin_agent/routes/resources/show.rb +8 -8
- data/lib/forest_admin_agent/routes/resources/store.rb +18 -15
- data/lib/forest_admin_agent/routes/resources/update.rb +9 -9
- data/lib/forest_admin_agent/routes/resources/update_field.rb +17 -17
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/version.rb +1 -1
- metadata +2 -1
|
@@ -21,25 +21,25 @@ module ForestAdminAgent
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def handle_request(args = {})
|
|
24
|
-
build(args)
|
|
25
|
-
|
|
24
|
+
context = build(args)
|
|
25
|
+
context.permissions.can?(:edit, context.collection)
|
|
26
26
|
|
|
27
|
-
relation =
|
|
28
|
-
parent_primary_key_values = Utils::Id.unpack_id(
|
|
27
|
+
relation = context.collection.schema[:fields][args[:params]['relation_name']]
|
|
28
|
+
parent_primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'])
|
|
29
29
|
|
|
30
30
|
linked_primary_key_values = if (id = args.dig(:params, 'data', 'id'))
|
|
31
|
-
Utils::Id.unpack_id(
|
|
31
|
+
Utils::Id.unpack_id(context.child_collection, id)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
case relation.type
|
|
35
35
|
when 'ManyToOne'
|
|
36
|
-
update_many_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
36
|
+
update_many_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
37
37
|
when 'PolymorphicManyToOne'
|
|
38
|
-
update_polymorphic_many_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
38
|
+
update_polymorphic_many_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
39
39
|
when 'OneToOne'
|
|
40
|
-
update_one_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
40
|
+
update_one_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
41
41
|
when 'PolymorphicOneToOne'
|
|
42
|
-
update_polymorphic_one_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
42
|
+
update_polymorphic_one_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
{ content: nil, status: 204 }
|
|
@@ -47,29 +47,30 @@ module ForestAdminAgent
|
|
|
47
47
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
|
-
def update_many_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
50
|
+
def update_many_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
51
51
|
foreign_value = if linked_primary_key_values
|
|
52
|
-
Collection.get_value(
|
|
52
|
+
Collection.get_value(context.child_collection, context.caller, linked_primary_key_values,
|
|
53
53
|
relation.foreign_key_target)
|
|
54
54
|
end
|
|
55
|
-
fk_owner = ConditionTree::ConditionTreeFactory.match_ids(
|
|
56
|
-
|
|
55
|
+
fk_owner = ConditionTree::ConditionTreeFactory.match_ids(context.collection, [parent_primary_key_values])
|
|
56
|
+
context.collection.update(context.caller, Filter.new(condition_tree: fk_owner),
|
|
57
|
+
{ relation.foreign_key => foreign_value })
|
|
57
58
|
end
|
|
58
59
|
|
|
59
|
-
def update_polymorphic_many_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
60
|
+
def update_polymorphic_many_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
60
61
|
foreign_value = if linked_primary_key_values
|
|
61
62
|
Collection.get_value(
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
context.child_collection,
|
|
64
|
+
context.caller,
|
|
64
65
|
linked_primary_key_values,
|
|
65
|
-
relation.foreign_key_targets[
|
|
66
|
+
relation.foreign_key_targets[context.child_collection.name]
|
|
66
67
|
)
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
polymorphic_type =
|
|
70
|
-
fk_owner = ConditionTree::ConditionTreeFactory.match_ids(
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
polymorphic_type = context.child_collection.name.gsub('__', '::')
|
|
71
|
+
fk_owner = ConditionTree::ConditionTreeFactory.match_ids(context.collection, [parent_primary_key_values])
|
|
72
|
+
context.collection.update(
|
|
73
|
+
context.caller,
|
|
73
74
|
Filter.new(condition_tree: fk_owner),
|
|
74
75
|
{
|
|
75
76
|
relation.foreign_key => foreign_value,
|
|
@@ -78,29 +79,29 @@ module ForestAdminAgent
|
|
|
78
79
|
)
|
|
79
80
|
end
|
|
80
81
|
|
|
81
|
-
def update_polymorphic_one_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
82
|
-
origin_value = Collection.get_value(
|
|
82
|
+
def update_polymorphic_one_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
83
|
+
origin_value = Collection.get_value(context.collection, context.caller, parent_primary_key_values,
|
|
83
84
|
relation.origin_key_target)
|
|
84
85
|
|
|
85
|
-
break_old_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
86
|
-
create_new_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
86
|
+
break_old_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
87
|
+
create_new_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
87
88
|
end
|
|
88
89
|
|
|
89
|
-
def update_one_to_one(relation, parent_primary_key_values, linked_primary_key_values)
|
|
90
|
-
origin_value = Collection.get_value(
|
|
90
|
+
def update_one_to_one(relation, parent_primary_key_values, linked_primary_key_values, context)
|
|
91
|
+
origin_value = Collection.get_value(context.collection, context.caller, parent_primary_key_values,
|
|
91
92
|
relation.origin_key_target)
|
|
92
93
|
|
|
93
|
-
break_old_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
94
|
-
create_new_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
94
|
+
break_old_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
95
|
+
create_new_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
95
96
|
end
|
|
96
97
|
|
|
97
|
-
def break_old_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
98
|
+
def break_old_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
98
99
|
linked_primary_key_values ||= []
|
|
99
100
|
|
|
100
101
|
old_fk_owner_filter = Filter.new(
|
|
101
102
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
102
103
|
[
|
|
103
|
-
|
|
104
|
+
context.permissions.get_scope(context.collection),
|
|
104
105
|
ConditionTree::Nodes::ConditionTreeBranch.new(
|
|
105
106
|
'And',
|
|
106
107
|
[
|
|
@@ -112,54 +113,58 @@ module ForestAdminAgent
|
|
|
112
113
|
ConditionTree::Nodes::ConditionTreeLeaf.new(
|
|
113
114
|
relation.origin_type_field,
|
|
114
115
|
ConditionTree::Operators::EQUAL,
|
|
115
|
-
|
|
116
|
+
context.collection.name.gsub('__', '::')
|
|
116
117
|
)
|
|
117
118
|
]
|
|
118
119
|
),
|
|
119
120
|
# Don't set the new record's field to null
|
|
120
121
|
# if it's already initialized with the right value
|
|
121
|
-
ConditionTree::ConditionTreeFactory.match_ids(
|
|
122
|
+
ConditionTree::ConditionTreeFactory.match_ids(context.child_collection,
|
|
123
|
+
[linked_primary_key_values]).inverse
|
|
122
124
|
]
|
|
123
125
|
)
|
|
124
126
|
)
|
|
125
127
|
|
|
126
|
-
result =
|
|
128
|
+
result = context.child_collection.aggregate(context.caller, old_fk_owner_filter,
|
|
129
|
+
Aggregation.new(operation: 'Count'), 1)
|
|
127
130
|
return unless !(result[0]['value']).nil? && (result[0]['value']).positive?
|
|
128
131
|
|
|
129
132
|
# Avoids updating records to null if it's not authorized by the ORM
|
|
130
133
|
# and if there is no record to update (the filter returns no record)
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
context.child_collection.update(
|
|
136
|
+
context.caller,
|
|
134
137
|
old_fk_owner_filter,
|
|
135
138
|
{ relation.origin_key => nil, relation.origin_type_field => nil }
|
|
136
139
|
)
|
|
137
140
|
end
|
|
138
141
|
|
|
139
|
-
def create_new_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
142
|
+
def create_new_polymorphic_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
140
143
|
return unless linked_primary_key_values
|
|
141
144
|
|
|
142
|
-
new_fk_owner = ConditionTree::ConditionTreeFactory.match_ids(
|
|
145
|
+
new_fk_owner = ConditionTree::ConditionTreeFactory.match_ids(context.child_collection,
|
|
146
|
+
[linked_primary_key_values])
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
context.child_collection.update(
|
|
149
|
+
context.caller,
|
|
146
150
|
Filter.new(
|
|
147
151
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
148
152
|
[
|
|
149
|
-
|
|
153
|
+
context.permissions.get_scope(context.collection), new_fk_owner
|
|
150
154
|
]
|
|
151
155
|
)
|
|
152
156
|
),
|
|
153
|
-
{ relation.origin_key => origin_value,
|
|
157
|
+
{ relation.origin_key => origin_value,
|
|
158
|
+
relation.origin_type_field => context.collection.name.gsub('__', '::') }
|
|
154
159
|
)
|
|
155
160
|
end
|
|
156
161
|
|
|
157
|
-
def break_old_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
162
|
+
def break_old_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
158
163
|
linked_primary_key_values ||= []
|
|
159
164
|
old_fk_owner_filter = Filter.new(
|
|
160
165
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
161
166
|
[
|
|
162
|
-
|
|
167
|
+
context.permissions.get_scope(context.collection),
|
|
163
168
|
ConditionTree::Nodes::ConditionTreeLeaf.new(
|
|
164
169
|
relation.origin_key,
|
|
165
170
|
ConditionTree::Operators::EQUAL,
|
|
@@ -167,30 +172,33 @@ module ForestAdminAgent
|
|
|
167
172
|
),
|
|
168
173
|
# Don't set the new record's field to null
|
|
169
174
|
# if it's already initialized with the right value
|
|
170
|
-
ConditionTree::ConditionTreeFactory.match_ids(
|
|
175
|
+
ConditionTree::ConditionTreeFactory.match_ids(context.child_collection,
|
|
176
|
+
[linked_primary_key_values]).inverse
|
|
171
177
|
]
|
|
172
178
|
)
|
|
173
179
|
)
|
|
174
180
|
|
|
175
|
-
result =
|
|
181
|
+
result = context.child_collection.aggregate(context.caller, old_fk_owner_filter,
|
|
182
|
+
Aggregation.new(operation: 'Count'), 1)
|
|
176
183
|
return unless !(result[0]['value']).nil? && (result[0]['value']).positive?
|
|
177
184
|
|
|
178
185
|
# Avoids updating records to null if it's not authorized by the ORM
|
|
179
186
|
# and if there is no record to update (the filter returns no record)
|
|
180
187
|
|
|
181
|
-
|
|
188
|
+
context.child_collection.update(context.caller, old_fk_owner_filter, { relation.origin_key => nil })
|
|
182
189
|
end
|
|
183
190
|
|
|
184
|
-
def create_new_one_to_one_relationship(relation, origin_value, linked_primary_key_values)
|
|
191
|
+
def create_new_one_to_one_relationship(relation, origin_value, linked_primary_key_values, context)
|
|
185
192
|
return unless linked_primary_key_values
|
|
186
193
|
|
|
187
|
-
new_fk_owner = ConditionTree::ConditionTreeFactory.match_ids(
|
|
194
|
+
new_fk_owner = ConditionTree::ConditionTreeFactory.match_ids(context.child_collection,
|
|
195
|
+
[linked_primary_key_values])
|
|
188
196
|
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
context.child_collection.update(
|
|
198
|
+
context.caller,
|
|
191
199
|
Filter.new(condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
192
200
|
[
|
|
193
|
-
|
|
201
|
+
context.permissions.get_scope(context.collection),
|
|
194
202
|
new_fk_owner
|
|
195
203
|
]
|
|
196
204
|
)),
|
|
@@ -14,18 +14,18 @@ module ForestAdminAgent
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def handle_request(args = {})
|
|
17
|
-
build(args)
|
|
18
|
-
|
|
19
|
-
scope =
|
|
20
|
-
primary_key_values = Utils::Id.unpack_id(
|
|
21
|
-
condition_tree = ConditionTree::ConditionTreeFactory.match_records(
|
|
17
|
+
context = build(args)
|
|
18
|
+
context.permissions.can?(:read, context.collection)
|
|
19
|
+
scope = context.permissions.get_scope(context.collection)
|
|
20
|
+
primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true)
|
|
21
|
+
condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values])
|
|
22
22
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
23
23
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope])
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
projection = ProjectionFactory.all(
|
|
26
|
+
projection = ProjectionFactory.all(context.collection)
|
|
27
27
|
|
|
28
|
-
records =
|
|
28
|
+
records = context.collection.list(context.caller, filter, projection)
|
|
29
29
|
|
|
30
30
|
raise Http::Exceptions::NotFoundError, 'Record does not exists' unless records.size.positive?
|
|
31
31
|
|
|
@@ -33,7 +33,7 @@ module ForestAdminAgent
|
|
|
33
33
|
name: args[:params]['collection_name'],
|
|
34
34
|
content: JSONAPI::Serializer.serialize(
|
|
35
35
|
records[0],
|
|
36
|
-
class_name:
|
|
36
|
+
class_name: context.collection.name,
|
|
37
37
|
is_collection: false,
|
|
38
38
|
serializer: Serializer::ForestSerializer,
|
|
39
39
|
include: projection.relations(only_keys: true)
|
|
@@ -14,44 +14,47 @@ module ForestAdminAgent
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def handle_request(args = {})
|
|
17
|
-
build(args)
|
|
18
|
-
|
|
19
|
-
data = format_attributes(args)
|
|
20
|
-
record =
|
|
21
|
-
link_one_to_one_relations(args, record)
|
|
22
|
-
id = ForestAdminDatasourceToolkit::Utils::Record.primary_keys(
|
|
17
|
+
context = build(args)
|
|
18
|
+
context.permissions.can?(:add, context.collection)
|
|
19
|
+
data = format_attributes(args, context.collection)
|
|
20
|
+
record = context.collection.create(context.caller, data)
|
|
21
|
+
link_one_to_one_relations(args, record, context)
|
|
22
|
+
id = ForestAdminDatasourceToolkit::Utils::Record.primary_keys(context.collection, record)
|
|
23
23
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
24
|
-
condition_tree: ConditionTree::ConditionTreeFactory.match_ids(
|
|
24
|
+
condition_tree: ConditionTree::ConditionTreeFactory.match_ids(context.collection, [id])
|
|
25
25
|
)
|
|
26
|
-
records =
|
|
26
|
+
records = context.collection.list(context.caller, filter, ProjectionFactory.all(context.collection))
|
|
27
27
|
|
|
28
28
|
{
|
|
29
29
|
name: args[:params]['collection_name'],
|
|
30
30
|
content: JSONAPI::Serializer.serialize(
|
|
31
31
|
records[0],
|
|
32
32
|
is_collection: false,
|
|
33
|
-
class_name:
|
|
33
|
+
class_name: context.collection.name,
|
|
34
34
|
serializer: Serializer::ForestSerializer
|
|
35
35
|
)
|
|
36
36
|
}
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def link_one_to_one_relations(args, record)
|
|
39
|
+
def link_one_to_one_relations(args, record, context)
|
|
40
40
|
args[:params][:data][:relationships]&.map do |field, value|
|
|
41
|
-
schema =
|
|
41
|
+
schema = context.collection.schema[:fields][field]
|
|
42
42
|
next unless %w[OneToOne PolymorphicOneToOne].include?(schema.type)
|
|
43
43
|
|
|
44
|
-
primary_key_values = Utils::Id.unpack_id(
|
|
45
|
-
foreign_collection =
|
|
44
|
+
primary_key_values = Utils::Id.unpack_id(context.collection, value['data']['id'], with_key: true)
|
|
45
|
+
foreign_collection = context.datasource.get_collection(schema.foreign_collection)
|
|
46
46
|
# Load the value that will be used as origin_key
|
|
47
47
|
origin_value = record[schema.origin_key_target]
|
|
48
48
|
|
|
49
49
|
# update new relation (may update zero or one records).
|
|
50
50
|
patch = { schema.origin_key => origin_value }
|
|
51
|
-
|
|
51
|
+
if schema.type == 'PolymorphicOneToOne'
|
|
52
|
+
patch[schema.origin_type_field] =
|
|
53
|
+
context.collection.name.gsub('__', '::')
|
|
54
|
+
end
|
|
52
55
|
condition_tree = ConditionTree::ConditionTreeFactory.match_records(foreign_collection, [primary_key_values])
|
|
53
56
|
filter = Filter.new(condition_tree: condition_tree)
|
|
54
|
-
foreign_collection.update(
|
|
57
|
+
foreign_collection.update(context.caller, filter, patch)
|
|
55
58
|
end
|
|
56
59
|
end
|
|
57
60
|
end
|
|
@@ -15,24 +15,24 @@ module ForestAdminAgent
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def handle_request(args = {})
|
|
18
|
-
build(args)
|
|
19
|
-
|
|
20
|
-
scope =
|
|
21
|
-
primary_key_values = Utils::Id.unpack_id(
|
|
22
|
-
condition_tree = ConditionTree::ConditionTreeFactory.match_records(
|
|
18
|
+
context = build(args)
|
|
19
|
+
context.permissions.can?(:edit, context.collection)
|
|
20
|
+
scope = context.permissions.get_scope(context.collection)
|
|
21
|
+
primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true)
|
|
22
|
+
condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values])
|
|
23
23
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
24
24
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope])
|
|
25
25
|
)
|
|
26
|
-
data = format_attributes(args)
|
|
27
|
-
|
|
28
|
-
records =
|
|
26
|
+
data = format_attributes(args, context.collection)
|
|
27
|
+
context.collection.update(context.caller, filter, data)
|
|
28
|
+
records = context.collection.list(context.caller, filter, ProjectionFactory.all(context.collection))
|
|
29
29
|
|
|
30
30
|
{
|
|
31
31
|
name: args[:params]['collection_name'],
|
|
32
32
|
content: JSONAPI::Serializer.serialize(
|
|
33
33
|
records[0],
|
|
34
34
|
is_collection: false,
|
|
35
|
-
class_name:
|
|
35
|
+
class_name: context.collection.name,
|
|
36
36
|
serializer: Serializer::ForestSerializer
|
|
37
37
|
)
|
|
38
38
|
}
|
|
@@ -23,18 +23,18 @@ module ForestAdminAgent
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def handle_request(args = {})
|
|
26
|
-
build(args)
|
|
26
|
+
context = build(args)
|
|
27
27
|
|
|
28
|
-
primary_key_values = Utils::Id.unpack_id(
|
|
28
|
+
primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true)
|
|
29
29
|
field_name = args[:params]['field_name']
|
|
30
30
|
array_index = parse_index(args[:params]['index'])
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
context.permissions.can?(:edit, context.collection)
|
|
33
33
|
|
|
34
|
-
field_schema =
|
|
35
|
-
validate_array_field!(field_schema, field_name)
|
|
34
|
+
field_schema = context.collection.schema[:fields][field_name]
|
|
35
|
+
validate_array_field!(field_schema, field_name, context.collection)
|
|
36
36
|
|
|
37
|
-
record = fetch_record(primary_key_values)
|
|
37
|
+
record = fetch_record(primary_key_values, context)
|
|
38
38
|
|
|
39
39
|
array = record[field_name]
|
|
40
40
|
validate_array_value!(array, field_name, array_index)
|
|
@@ -44,21 +44,21 @@ module ForestAdminAgent
|
|
|
44
44
|
updated_array = array.dup
|
|
45
45
|
updated_array[array_index] = new_value
|
|
46
46
|
|
|
47
|
-
scope =
|
|
48
|
-
condition_tree = ConditionTree::ConditionTreeFactory.match_records(
|
|
47
|
+
scope = context.permissions.get_scope(context.collection)
|
|
48
|
+
condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values])
|
|
49
49
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
50
50
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope])
|
|
51
51
|
)
|
|
52
|
-
|
|
52
|
+
context.collection.update(context.caller, filter, { field_name => updated_array })
|
|
53
53
|
|
|
54
|
-
records =
|
|
54
|
+
records = context.collection.list(context.caller, filter, ProjectionFactory.all(context.collection))
|
|
55
55
|
|
|
56
56
|
{
|
|
57
57
|
name: args[:params]['collection_name'],
|
|
58
58
|
content: JSONAPI::Serializer.serialize(
|
|
59
59
|
records[0],
|
|
60
60
|
is_collection: false,
|
|
61
|
-
class_name:
|
|
61
|
+
class_name: context.collection.name,
|
|
62
62
|
serializer: Serializer::ForestSerializer
|
|
63
63
|
)
|
|
64
64
|
}
|
|
@@ -75,8 +75,8 @@ module ForestAdminAgent
|
|
|
75
75
|
raise Http::Exceptions::ValidationError, "Invalid index: #{index_param}"
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
def validate_array_field!(field_schema, field_name)
|
|
79
|
-
FieldValidator.validate(
|
|
78
|
+
def validate_array_field!(field_schema, field_name, collection)
|
|
79
|
+
FieldValidator.validate(collection, field_name)
|
|
80
80
|
return if field_schema.column_type.is_a?(Array)
|
|
81
81
|
|
|
82
82
|
raise Http::Exceptions::ValidationError,
|
|
@@ -87,13 +87,13 @@ module ForestAdminAgent
|
|
|
87
87
|
raise Http::Exceptions::ValidationError, e.message
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
def fetch_record(primary_key_values)
|
|
91
|
-
scope =
|
|
92
|
-
condition_tree = ConditionTree::ConditionTreeFactory.match_records(
|
|
90
|
+
def fetch_record(primary_key_values, context)
|
|
91
|
+
scope = context.permissions.get_scope(context.collection)
|
|
92
|
+
condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values])
|
|
93
93
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
94
94
|
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope])
|
|
95
95
|
)
|
|
96
|
-
records =
|
|
96
|
+
records = context.collection.list(context.caller, filter, ProjectionFactory.all(context.collection))
|
|
97
97
|
|
|
98
98
|
raise Http::Exceptions::NotFoundError, 'Record not found' unless records&.any?
|
|
99
99
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.12.
|
|
4
|
+
version: 1.12.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -314,6 +314,7 @@ files:
|
|
|
314
314
|
- lib/forest_admin_agent/routes/charts/api_chart_datasource.rb
|
|
315
315
|
- lib/forest_admin_agent/routes/charts/charts.rb
|
|
316
316
|
- lib/forest_admin_agent/routes/query_handler.rb
|
|
317
|
+
- lib/forest_admin_agent/routes/request_context.rb
|
|
317
318
|
- lib/forest_admin_agent/routes/resources/count.rb
|
|
318
319
|
- lib/forest_admin_agent/routes/resources/csv.rb
|
|
319
320
|
- lib/forest_admin_agent/routes/resources/delete.rb
|