Files
docuseal/app/controllers/application_controller.rb
T

45 lines
1.1 KiB
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
class ApplicationController < ActionController::Base
include ActiveStorage::SetCurrent
include Pagy::Backend
2023-05-21 17:59:36 +03:00
2023-07-05 00:22:05 +03:00
before_action :sign_in_for_demo, if: -> { Docuseal.demo? }
2023-05-21 17:59:36 +03:00
before_action :maybe_redirect_to_setup, unless: :signed_in?
before_action :authenticate_user!, unless: :devise_controller?
helper_method :button_title,
2023-06-11 12:42:13 +00:00
:current_account,
:svg_icon
2023-05-21 17:59:36 +03:00
2023-06-29 02:04:17 +03:00
rescue_from Pagy::OverflowError do
redirect_to request.path
end
def default_url_options
Docuseal.default_url_options
end
2023-05-21 17:59:36 +03:00
private
2023-07-05 00:22:05 +03:00
def sign_in_for_demo
2023-07-12 01:24:25 +03:00
sign_in(User.order('random()').take) unless signed_in?
2023-07-05 00:22:05 +03:00
end
2023-05-21 17:59:36 +03:00
def current_account
current_user&.account
end
def maybe_redirect_to_setup
redirect_to setup_index_path unless User.exists?
end
2023-08-05 15:25:16 +03:00
def button_title(title: 'Submit', disabled_with: 'Submitting', icon: nil, icon_disabled: nil)
render_to_string(partial: 'shared/button_title', locals: { title:, disabled_with:, icon:, icon_disabled: })
2023-06-11 12:42:13 +00:00
end
2023-06-11 15:51:52 +03:00
def svg_icon(icon_name, class: '')
render_to_string(partial: "icons/#{icon_name}", locals: { class: })
2023-05-21 17:59:36 +03:00
end
end