Class: Silas::Channels::ApprovalsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/silas/channels/approvals_controller.rb

Overview

Email approve/decline links land here. The signed token carries the invocation id + action (no session state in the URL); a GET shows a confirm page, a POST performs the action via the existing approve!/decline!.

Instance Method Summary collapse

Instance Method Details

#showObject



7
8
9
10
11
12
13
14
# File 'app/controllers/silas/channels/approvals_controller.rb', line 7

def show
  @claim = Silas::Channel.verify_token(params[:token])
  return render(:error, status: :unprocessable_entity) unless @claim

  @invocation = Silas::ToolInvocation.find_by(id: @claim["id"])
  @action = @claim["action"]
  render :show
end

#updateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/silas/channels/approvals_controller.rb', line 16

def update
  claim = Silas::Channel.verify_token(params[:token])
  return render(:error, status: :unprocessable_entity) unless claim

  invocation = Silas::ToolInvocation.find(claim["id"])
  if claim["action"] == "approve"
    invocation.approve!(by: "email")
  else
    invocation.decline!(reason: "declined by email", by: "email")
  end
  @action = claim["action"]
  render :done
rescue Silas::Error => e
  @message = e.message
  render :error, status: :unprocessable_entity
end