forest_admin_agent 1.39.4 → 1.40.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70619859806c445a79898fd7c0ccc1d8584d1d32441b2b41d9a955577effaf70
4
- data.tar.gz: 9aec675836fe8747de7d4a52ce392e0df50593c6b30dffa86d0c28349a142bcb
3
+ metadata.gz: a3449a32087ea2e6d73f842dc2ea471f3c6ff5b8977cc14739be8b52e56a7a55
4
+ data.tar.gz: efe4a6b6741625d381ee569918883ad2c514738ae459e78250dcd7e92601be7f
5
5
  SHA512:
6
- metadata.gz: b4d575fee79985367b338dcda0e3d646ce32e119ada6db4370acb4a402e11824330732160e4636d96c3cdf91704e6fc8e216082ac4ee091300325a61d6465853
7
- data.tar.gz: b48ea6b3ac88d37052c9bfb04d26e3179ef4182c96dce7df018847fab099971e83d3a9630d6c77430a738b273bac27571f2d03fe88f719b6a92e04b303697599
6
+ metadata.gz: 2b1ffd855a60f2982d11e9c84e42000a36bbfbc78ea7106c4a12bac3ec564aba01b4559e7d4c3ea63b27d47348ac857fbb4d69e2a802b5a5c1765c8005996933
7
+ data.tar.gz: a8d6416b4074df609fa8f177f61fa9685f3f80ea962b496f1e4ce121dd1d2dc080f8c26b2ef3b41be2c4b3d864398f793f3402a6e55ffd0f84bceb264bd569ee
@@ -201,7 +201,8 @@ module ForestAdminAgent
201
201
  smart_action_approval = SmartActionChecker.new(
202
202
  request[:params],
203
203
  collection,
204
- collection_actions[action['name'].to_sym],
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: { user_approval_enabled: smart_action[:userApprovalEnabled] }
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
 
@@ -6,7 +6,7 @@ module ForestAdminAgent
6
6
  module Schema
7
7
  class SchemaEmitter
8
8
  LIANA_NAME = "agent-ruby"
9
- LIANA_VERSION = "1.39.4"
9
+ LIANA_VERSION = "1.40.0"
10
10
 
11
11
  def self.generate(datasource)
12
12
  datasource.collections
@@ -1,3 +1,3 @@
1
1
  module ForestAdminAgent
2
- VERSION = "1.39.4"
2
+ VERSION = "1.40.0"
3
3
  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.39.4
4
+ version: 1.40.0
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-26 00:00:00.000000000 Z
12
+ date: 2026-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport