5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/lcp_ruby/workflow/approval/resolution_handler.rb', line 5
def self.resolve(approval_request, outcome:, deciding_user:)
request_model = Registry.request_model
step_model = Registry.step_model
task_model = Registry.task_model
approval_def = find_approval_def(approval_request)
transition_name = approval_def.resolution_transition(outcome)
unless transition_name
approval_request.update!(status: "error")
fire_event("approval_resolution_failed", approval_request,
reason: "No resolution transition for outcome '#{outcome}'")
return
end
approval_request.update!(status: outcome.to_s, resolved_at: Time.current)
if approval_def.short_circuit
cancel_remaining(approval_request, step_model, task_model)
end
record = load_record(approval_request)
workflow_def = find_workflow_def(approval_request)
transition = workflow_def.transition(transition_name)
evaluator = SystemEvaluator.new(roles: transition&.roles || [])
begin
TransitionExecutor.execute(
record, transition_name,
user: deciding_user,
evaluator: evaluator,
triggered_by: "approval_engine"
)
rescue TransitionDeniedError, WorkflowError => e
approval_request.update!(status: "error")
fire_event("approval_transition_failed", approval_request,
reason: e.message, transition: transition_name)
end
end
|