Files
terminus/app/action.rb
T
Brooke Kuhlmann 2d5a39a970 Refactored actions to include Dry Monands and Initable by default
Necessary to reduce lines of code since both the Dry Monads and Initiable gems are commonly used. By requiring and -- in the case of Dry Monads -- including them within the base action, all actions can now inherit and immediately use this functionality.

Milestone: patch
2025-12-08 08:30:32 -07:00

45 lines
893 B
Ruby

# auto_register: false
# frozen_string_literal: true
require "dry/monads"
require "hanami/action"
require "initable"
module Terminus
# The application base action.
class Action < Hanami::Action
include Dry::Monads[:result]
before :authorize
protected
def authorize request, response
rodauth = request.env["rodauth"]
return unless rodauth
handle_rodauth_redirect(rodauth, response) { rodauth.require_account }
response[:current_user_id] = rodauth.account_id
end
private
def handle_rodauth_redirect rodauth, response
halted = catch(:halt) { yield }
# :nocov:
return unless halted
code, headers, body = *halted
rodauth.flash.next.each { |key, value| response.flash[key] = value }
response.redirect headers["Location"], code
throw :halt, [code, body]
# :nocov:
end
end
end