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
|
# File 'app/models/collavre/comment/approvable.rb', line 10
def approval_status(user)
return :not_allowed unless user
if action.blank?
return :not_allowed unless approver_id == user&.id
return :missing_action
end
begin
payload = JSON.parse(action)
rescue JSON::ParserError
return :invalid_action_format
end
return :invalid_action_format unless payload.is_a?(Hash)
actions = Array(payload["actions"])
actions = [ payload ] if actions.empty?
requires_admin = actions.any? do |item|
next false unless item.is_a?(Hash)
action_type = item["action"] || item["type"]
action_type == "approve_tool"
end
if requires_admin && SystemSetting.mcp_tool_approval_required?
return user.system_admin? ? :ok : :admin_required
end
return :missing_approver if approver_id.blank?
return :not_allowed unless approver_id == user&.id
:ok
end
|