forest_admin_agent 1.39.4 → 1.40.1
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/resources/related/associate_related.rb +1 -0
- data/lib/forest_admin_agent/routes/resources/related/dissociate_related.rb +1 -0
- data/lib/forest_admin_agent/routes/resources/related/update_related.rb +5 -0
- data/lib/forest_admin_agent/routes/resources/store.rb +2 -0
- data/lib/forest_admin_agent/services/permissions.rb +2 -1
- data/lib/forest_admin_agent/services/smart_action_checker.rb +44 -1
- data/lib/forest_admin_agent/utils/schema/generator_field.rb +1 -1
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/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: 41424b4c16e2ad72007fc04077d6ba6eaaac2cb39e664a7bf45ca081ea3cd48f
|
|
4
|
+
data.tar.gz: 3436faf494fa9b564bddcdd218bc3e86d40e7d017ed3abeb232ff3cd2086b96f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b04f5cd5d017f5dc76cadf4277a7a6b7a940298d95db23a3e31a8f15b70b3964506f56861a82b18300c2c785e3d2ecef3e70c75c5f62d71d2c7ae4fe79e011f5
|
|
7
|
+
data.tar.gz: 77f78657ad7eac790127770d7ad4af2d98cdf4477882c882fab27779799e65c6f72ee7edb6adacf3673e2768153415935fd9c7060e03914e0cf8fec647a23b73
|
|
@@ -28,6 +28,7 @@ module ForestAdminAgent
|
|
|
28
28
|
target_primary_key_values = Utils::Id.unpack_id(context.child_collection, args[:params]['data'][0]['id'],
|
|
29
29
|
with_key: true)
|
|
30
30
|
relation = Schema.get_to_many_relation(context.collection, args[:params]['relation_name'])
|
|
31
|
+
Collection.assert_writable_relation!(args[:params]['relation_name'], relation)
|
|
31
32
|
|
|
32
33
|
case relation.type
|
|
33
34
|
when 'OneToMany'
|
|
@@ -34,6 +34,7 @@ module ForestAdminAgent
|
|
|
34
34
|
|
|
35
35
|
filter = get_base_foreign_filter(args, context)
|
|
36
36
|
relation = Schema.get_to_many_relation(context.collection, args[:params]['relation_name'])
|
|
37
|
+
Collection.assert_writable_relation!(args[:params]['relation_name'], relation)
|
|
37
38
|
|
|
38
39
|
relation_name = args[:params]['relation_name']
|
|
39
40
|
options = {
|
|
@@ -28,6 +28,11 @@ module ForestAdminAgent
|
|
|
28
28
|
# Must run before unpack_id: unauthorized callers get a 403, not a validation error
|
|
29
29
|
context.permissions.can?(:edit, mutated_collection(relation, context))
|
|
30
30
|
|
|
31
|
+
# Every relation type this route writes through can be read-only (#379's
|
|
32
|
+
# OneToOne identity join is the reason this exists, but the flag itself sits on
|
|
33
|
+
# the shared RelationSchema, so enforce it once here rather than per-branch).
|
|
34
|
+
Collection.assert_writable_relation!(args[:params]['relation_name'], relation)
|
|
35
|
+
|
|
31
36
|
parent_primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'])
|
|
32
37
|
|
|
33
38
|
linked_primary_key_values = if (id = args.dig(:params, 'data', 'id'))
|
|
@@ -67,6 +67,8 @@ module ForestAdminAgent
|
|
|
67
67
|
id = value.dig('data', 'id')
|
|
68
68
|
return if id.nil?
|
|
69
69
|
|
|
70
|
+
ForestAdminDatasourceToolkit::Utils::Collection.assert_writable_relation!(field, schema)
|
|
71
|
+
|
|
70
72
|
{
|
|
71
73
|
schema: schema,
|
|
72
74
|
foreign_collection: context.datasource.get_collection(schema.foreign_collection),
|
|
@@ -201,7 +201,8 @@ module ForestAdminAgent
|
|
|
201
201
|
smart_action_approval = SmartActionChecker.new(
|
|
202
202
|
request[:params],
|
|
203
203
|
collection,
|
|
204
|
-
|
|
204
|
+
# The schema scope lets the checker skip select-all resolution for global actions.
|
|
205
|
+
collection_actions[action['name'].to_sym].merge(scope: collection.schema[:actions][action['name']]&.scope),
|
|
205
206
|
caller,
|
|
206
207
|
user_data[:roleId],
|
|
207
208
|
filter
|
|
@@ -20,12 +20,24 @@ module ForestAdminAgent
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
class ApprovalSelectionTooLargeError < UnprocessableError
|
|
24
|
+
def initialize(max)
|
|
25
|
+
super(
|
|
26
|
+
"This action requires approval and cannot be triggered on more than #{max} records at once. " \
|
|
27
|
+
'Please refine your selection.'
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
23
32
|
class SmartActionChecker
|
|
24
33
|
include ForestAdminAgent::Utils
|
|
25
34
|
include ForestAdminDatasourceToolkit::Utils
|
|
26
35
|
include ForestAdminDatasourceToolkit::Components::Query
|
|
27
36
|
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
|
28
37
|
|
|
38
|
+
# The Forest server's cap on approval record ids; max_records_for_approval may only lower it.
|
|
39
|
+
MAX_RECORDS_FOR_APPROVAL = 500
|
|
40
|
+
|
|
29
41
|
attr_reader :parameters, :collection, :smart_action, :caller, :role_id, :filter, :attributes
|
|
30
42
|
|
|
31
43
|
def initialize(parameters, collection, smart_action, caller, role_id, filter)
|
|
@@ -66,9 +78,19 @@ module ForestAdminAgent
|
|
|
66
78
|
end
|
|
67
79
|
elsif smart_action[:approvalRequired].include?(role_id) && smart_action[:triggerEnabled].include?(role_id)
|
|
68
80
|
if condition_by_role_id(smart_action[:approvalRequiredConditions]).nil? || match_conditions(:approvalRequiredConditions)
|
|
81
|
+
# Global actions target no specific records — never resolve.
|
|
82
|
+
if attributes[:all_records] && smart_action[:scope] != ForestAdminDatasourceCustomizer::Decorators::Action::Types::ActionScope::GLOBAL
|
|
83
|
+
record_ids = resolve_select_all_record_ids
|
|
84
|
+
end
|
|
85
|
+
|
|
69
86
|
raise CustomActionRequiresApprovalError.new(
|
|
70
87
|
'This action requires to be approved.',
|
|
71
|
-
details: {
|
|
88
|
+
details: {
|
|
89
|
+
user_approval_enabled: smart_action[:userApprovalEnabled],
|
|
90
|
+
# camelCase: sent verbatim in the error data, the key the frontend reads.
|
|
91
|
+
roleIdsAllowedToApprove: smart_action[:userApprovalEnabled],
|
|
92
|
+
**(record_ids ? { recordIds: record_ids } : {})
|
|
93
|
+
}
|
|
72
94
|
)
|
|
73
95
|
elsif condition_by_role_id(smart_action[:triggerConditions]).nil? || match_conditions(:triggerConditions)
|
|
74
96
|
return true
|
|
@@ -78,6 +100,27 @@ module ForestAdminAgent
|
|
|
78
100
|
raise CustomActionTriggerForbiddenError, 'You don\'t have the permission to trigger this action.'
|
|
79
101
|
end
|
|
80
102
|
|
|
103
|
+
# Fetching cap+1 distinguishes "over the cap" from "exactly the cap".
|
|
104
|
+
def resolve_select_all_record_ids
|
|
105
|
+
configured = ForestAdminAgent::Facades::Container.config_from_cache[:max_records_for_approval]
|
|
106
|
+
# Anything but a positive Integer gets the default (a negative LIMIT means unlimited on
|
|
107
|
+
# some datasources, and a String would raise on comparison).
|
|
108
|
+
max = if configured.is_a?(Integer) && configured.positive?
|
|
109
|
+
[configured, MAX_RECORDS_FOR_APPROVAL].min
|
|
110
|
+
else
|
|
111
|
+
MAX_RECORDS_FOR_APPROVAL
|
|
112
|
+
end
|
|
113
|
+
records = collection.list(
|
|
114
|
+
caller,
|
|
115
|
+
filter.override(page: Page.new(offset: 0, limit: max + 1)),
|
|
116
|
+
Projection.new.with_pks(collection)
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
raise ApprovalSelectionTooLargeError, max if records.size > max
|
|
120
|
+
|
|
121
|
+
Utils::Id.pack_ids(collection, records)
|
|
122
|
+
end
|
|
123
|
+
|
|
81
124
|
def match_conditions(condition_name)
|
|
82
125
|
pks = Schema.primary_keys(collection)
|
|
83
126
|
|
|
@@ -127,7 +127,7 @@ module ForestAdminAgent
|
|
|
127
127
|
isFilterable: foreign_collection_filterable?(foreign_collection),
|
|
128
128
|
isPrimaryKey: false,
|
|
129
129
|
isRequired: false,
|
|
130
|
-
isReadOnly: key_field.is_read_only,
|
|
130
|
+
isReadOnly: relation.is_read_only || key_field.is_read_only,
|
|
131
131
|
isSortable: target_field.is_sortable,
|
|
132
132
|
validations: [],
|
|
133
133
|
reference: "#{foreign_collection.name}.#{relation.origin_key_target}"
|
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.
|
|
4
|
+
version: 1.40.1
|
|
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-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|