Module: Collavre::Comment::Approvable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Collavre::Comment
- Defined in:
- app/models/collavre/comment/approvable.rb
Instance Method Summary collapse
-
#approval_action? ⇒ Boolean
A message that renders an approval button (pending) or an approved/denied status label (decided) in the chat list — i.e.
- #approval_status(user) ⇒ Object
- #can_be_approved_by?(user) ⇒ Boolean
- #parsed_action_tool_name ⇒ Object
Instance Method Details
#approval_action? ⇒ Boolean
A message that renders an approval button (pending) or an
approved/denied status label (decided) in the chat list — i.e. it
carries an action JSON payload. Both the has_pending_action
button (action.present? && action_executed_at.blank?) and the
✅ approved / 🚫 denied label (action_executed_at.present?, which implies
action.present?) roll up to this single condition.
Such a message is a HUMAN decision surface and must never be dispatched to an AI agent — regardless of who authored it or whether it has already been decided. This is the single source of truth for that invariant, enforced at every dispatch seam (Comment#dispatch_to_orchestration and AiAgent::A2aDispatcher#dispatch).
18 19 20 |
# File 'app/models/collavre/comment/approvable.rb', line 18 def approval_action? action.present? end |
#approval_status(user) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/collavre/comment/approvable.rb', line 26 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 |
#can_be_approved_by?(user) ⇒ Boolean
22 23 24 |
# File 'app/models/collavre/comment/approvable.rb', line 22 def can_be_approved_by?(user) approval_status(user) == :ok end |
#parsed_action_tool_name ⇒ Object
60 61 62 63 |
# File 'app/models/collavre/comment/approvable.rb', line 60 def parsed_action_tool_name parsed = JSON.parse(action) rescue nil parsed&.dig("tool_name") || "unknown" end |