forest_admin_agent 1.38.0 → 1.38.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 948a67317152cf955d6e7ff512b20b810d136ff9ab89e8ad87cbb2a09e9b80e2
|
|
4
|
+
data.tar.gz: 3984557e91f84b405857a45debf12c7ec2d39377575be0a645ad9c4c7c1de872
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d051b8008198eb80152b4e542ce4c570f0e3215c46a6e9cdbe05405d395c9760fc7176318a4eb0533e1ca91443c7c3be17ac9d51176094910e6fe3230f77bf43
|
|
7
|
+
data.tar.gz: a103408031a613a2061036ca066502f72752f2138d22e526cb5706bd7b703b415297cf9aba273d3976dc1a2bf52b6ed948d9f768e6c74d2f99031d9397dbd809
|
|
@@ -22,7 +22,7 @@ module ForestAdminAgent
|
|
|
22
22
|
|
|
23
23
|
def handle_request(args = {})
|
|
24
24
|
context = build(args)
|
|
25
|
-
context.permissions.can?(:edit, context.
|
|
25
|
+
context.permissions.can?(:edit, context.child_collection)
|
|
26
26
|
|
|
27
27
|
parent_primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true)
|
|
28
28
|
target_primary_key_values = Utils::Id.unpack_id(context.child_collection, args[:params]['data'][0]['id'],
|
|
@@ -44,16 +44,7 @@ module ForestAdminAgent
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
46
|
def associate_one_to_many(relation, parent_primary_key_values, target_primary_key_values, context)
|
|
47
|
-
|
|
48
|
-
value = Collection.get_value(context.child_collection, context.caller, target_primary_key_values, id)
|
|
49
|
-
filter = Filter.new(
|
|
50
|
-
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
51
|
-
[
|
|
52
|
-
ConditionTree::Nodes::ConditionTreeLeaf.new(id, 'Equal', value),
|
|
53
|
-
context.permissions.get_scope(context.child_collection)
|
|
54
|
-
]
|
|
55
|
-
)
|
|
56
|
-
)
|
|
47
|
+
filter = target_in_scope_filter(target_primary_key_values, context)
|
|
57
48
|
value = Collection.get_value(context.collection, context.caller, parent_primary_key_values,
|
|
58
49
|
relation.origin_key_target)
|
|
59
50
|
|
|
@@ -61,17 +52,7 @@ module ForestAdminAgent
|
|
|
61
52
|
end
|
|
62
53
|
|
|
63
54
|
def associate_polymorphic_one_to_many(relation, parent_primary_key_values, target_primary_key_values, context)
|
|
64
|
-
|
|
65
|
-
value = Collection.get_value(context.child_collection, context.caller, target_primary_key_values, id)
|
|
66
|
-
filter = Filter.new(
|
|
67
|
-
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
68
|
-
[
|
|
69
|
-
ConditionTree::Nodes::ConditionTreeLeaf.new(id, 'Equal', value),
|
|
70
|
-
context.permissions.get_scope(context.child_collection)
|
|
71
|
-
]
|
|
72
|
-
)
|
|
73
|
-
)
|
|
74
|
-
|
|
55
|
+
filter = target_in_scope_filter(target_primary_key_values, context)
|
|
75
56
|
value = Collection.get_value(context.collection, context.caller, parent_primary_key_values,
|
|
76
57
|
relation.origin_key_target)
|
|
77
58
|
|
|
@@ -83,16 +64,39 @@ module ForestAdminAgent
|
|
|
83
64
|
end
|
|
84
65
|
|
|
85
66
|
def associate_many_to_many(relation, parent_primary_key_values, target_primary_key_values, context)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
record = {
|
|
67
|
+
target = find_target_in_scope(target_primary_key_values, relation.foreign_key_target, context)
|
|
68
|
+
return if target.nil?
|
|
69
|
+
|
|
70
|
+
origin_value = Collection.get_value(context.collection, context.caller, parent_primary_key_values,
|
|
71
|
+
relation.origin_key_target)
|
|
72
|
+
record = {
|
|
73
|
+
relation.origin_key => origin_value,
|
|
74
|
+
relation.foreign_key => target[relation.foreign_key_target]
|
|
75
|
+
}
|
|
92
76
|
|
|
93
77
|
through_collection = context.datasource.get_collection(relation.through_collection)
|
|
94
78
|
through_collection.create(context.caller, record)
|
|
95
79
|
end
|
|
80
|
+
|
|
81
|
+
def find_target_in_scope(target_primary_key_values, foreign_key_target, context)
|
|
82
|
+
context.child_collection.list(
|
|
83
|
+
context.caller,
|
|
84
|
+
target_in_scope_filter(target_primary_key_values, context),
|
|
85
|
+
Projection.new([foreign_key_target])
|
|
86
|
+
).first
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def target_in_scope_filter(target_primary_key_values, context)
|
|
90
|
+
Filter.new(
|
|
91
|
+
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
92
|
+
[
|
|
93
|
+
ConditionTree::ConditionTreeFactory.match_ids(context.child_collection,
|
|
94
|
+
[target_primary_key_values]),
|
|
95
|
+
context.permissions.get_scope(context.child_collection)
|
|
96
|
+
]
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
end
|
|
96
100
|
end
|
|
97
101
|
end
|
|
98
102
|
end
|
|
@@ -17,9 +17,10 @@ module ForestAdminAgent
|
|
|
17
17
|
def handle_request(args = {})
|
|
18
18
|
context = build(args)
|
|
19
19
|
context.permissions.can?(:add, context.collection)
|
|
20
|
+
relations = authorized_linked_one_to_one_relations(args, context)
|
|
20
21
|
data = format_attributes(args, context.collection)
|
|
21
22
|
record = context.collection.create(context.caller, data)
|
|
22
|
-
link_one_to_one_relations(
|
|
23
|
+
link_one_to_one_relations(relations, record, context)
|
|
23
24
|
id = ForestAdminDatasourceToolkit::Utils::Record.primary_keys(context.collection, record)
|
|
24
25
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
|
25
26
|
condition_tree: ConditionTree::ConditionTreeFactory.match_ids(context.collection, [id])
|
|
@@ -37,24 +38,63 @@ module ForestAdminAgent
|
|
|
37
38
|
}
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
args[:params][:data][:relationships]&.map do |field, value|
|
|
42
|
-
schema = context.collection.schema[:fields][field]
|
|
43
|
-
next unless %w[OneToOne PolymorphicOneToOne].include?(schema.type)
|
|
41
|
+
private
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
origin_value = record[schema.origin_key_target]
|
|
43
|
+
def authorized_linked_one_to_one_relations(args, context)
|
|
44
|
+
linked_one_to_one_relations(args, context).map do |relation|
|
|
45
|
+
foreign_collection = relation[:foreign_collection]
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
context.permissions.can?(:edit, foreign_collection)
|
|
48
|
+
|
|
49
|
+
relation.merge(
|
|
50
|
+
scope: context.permissions.get_scope(foreign_collection),
|
|
51
|
+
primary_key_values: Utils::Id.unpack_id(foreign_collection, relation[:id], with_key: true)
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def linked_one_to_one_relations(args, context)
|
|
57
|
+
relationships = args.dig(:params, :data, :relationships) || {}
|
|
58
|
+
|
|
59
|
+
relationships.filter_map { |field, value| linked_one_to_one_relation(field, value, context) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def linked_one_to_one_relation(field, value, context)
|
|
63
|
+
schema = context.collection.schema[:fields][field]
|
|
64
|
+
return unless %w[OneToOne PolymorphicOneToOne].include?(schema.type)
|
|
65
|
+
|
|
66
|
+
id = value.dig('data', 'id')
|
|
67
|
+
return if id.nil?
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
schema: schema,
|
|
71
|
+
foreign_collection: context.datasource.get_collection(schema.foreign_collection),
|
|
72
|
+
id: id
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def link_one_to_one_relations(relations, record, context)
|
|
77
|
+
relations.each do |relation|
|
|
78
|
+
schema = relation[:schema]
|
|
79
|
+
foreign_collection = relation[:foreign_collection]
|
|
80
|
+
|
|
81
|
+
patch = { schema.origin_key => record[schema.origin_key_target] }
|
|
52
82
|
if schema.type == 'PolymorphicOneToOne'
|
|
53
83
|
patch[schema.origin_type_field] =
|
|
54
84
|
context.collection.name.gsub('__', '::')
|
|
55
85
|
end
|
|
56
|
-
|
|
57
|
-
|
|
86
|
+
|
|
87
|
+
new_fk_owner = ConditionTree::ConditionTreeFactory.match_records(
|
|
88
|
+
foreign_collection, [relation[:primary_key_values]]
|
|
89
|
+
)
|
|
90
|
+
filter = Filter.new(
|
|
91
|
+
condition_tree: ConditionTree::ConditionTreeFactory.intersect(
|
|
92
|
+
[
|
|
93
|
+
relation[:scope],
|
|
94
|
+
new_fk_owner
|
|
95
|
+
]
|
|
96
|
+
)
|
|
97
|
+
)
|
|
58
98
|
foreign_collection.update(context.caller, filter, patch)
|
|
59
99
|
end
|
|
60
100
|
end
|
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.38.
|
|
4
|
+
version: 1.38.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-08-
|
|
12
|
+
date: 2026-08-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|