diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 974ba177..aa0bd5d5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,10 @@ class ApplicationController < ActionController::Base :current_account, :svg_icon + def default_url_options + Docuseal.default_url_options + end + private def current_account diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb index 0b90f5a7..033f12a8 100644 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profile_controller.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true class ProfileController < ApplicationController + before_action :load_encrypted_config, only: %i[index update_app_url] + + def index; end + def update_contact if current_user.update(contact_params) redirect_to settings_profile_index_path, notice: 'Contact information successfully updated' @@ -18,8 +22,23 @@ class ProfileController < ApplicationController end end + def update_app_url + if @encrypted_config.update(app_url_params) + Docuseal.refresh_default_url_options! + + redirect_to settings_profile_index_path, notice: 'App URL successfully changed' + else + render :index, status: :unprocessable_entity + end + end + private + def load_encrypted_config + @encrypted_config = + EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::APP_URL_KEY) + end + def contact_params params.require(:user).permit(:first_name, :last_name, :email, account_attributes: %i[name]) end @@ -27,4 +46,8 @@ class ProfileController < ApplicationController def password_params params.require(:user).permit(:password, :password_confirmation) end + + def app_url_params + params.require(:encrypted_config).permit(:value) + end end diff --git a/app/controllers/setup_controller.rb b/app/controllers/setup_controller.rb index 43817ef2..8fe0bbc2 100644 --- a/app/controllers/setup_controller.rb +++ b/app/controllers/setup_controller.rb @@ -10,6 +10,7 @@ class SetupController < ApplicationController def index @account = Account.new(account_params) @user = @account.users.new(user_params) + @encrypted_config = EncryptedConfig.new(account: @account, key: EncryptedConfig::APP_URL_KEY) end def create @@ -17,8 +18,11 @@ class SetupController < ApplicationController @user = @account.users.new(user_params) if @user.save - @account.encrypted_configs.create!(key: EncryptedConfig::ESIGN_CERTS_KEY, - value: GenerateCertificate.call) + encrypted_configs = [ + { key: EncryptedConfig::APP_URL_KEY, value: encrypted_config_params[:value] }, + { key: EncryptedConfig::ESIGN_CERTS_KEY, value: GenerateCertificate.call } + ] + @account.encrypted_configs.create!(encrypted_configs) sign_in(@user) @@ -42,6 +46,12 @@ class SetupController < ApplicationController params.require(:account).permit(:name) end + def encrypted_config_params + return {} unless params[:encrypted_config] + + params.require(:encrypted_config).permit(:value) + end + def redirect_to_root_if_signed redirect_to root_path, notice: 'You are already signed in' end diff --git a/app/javascript/application.js b/app/javascript/application.js index b9ee6f22..aca2d2c0 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -11,6 +11,7 @@ import ClipboardCopy from './elements/clipboard_copy' import TemplateBuilder from './template_builder/builder' import DynamicList from './elements/dynamic_list' import DownloadButton from './elements/download_button' +import SetOriginUrl from './elements/set_origin_url' document.addEventListener('turbo:before-cache', () => { window.flash?.remove() @@ -30,6 +31,7 @@ window.customElements.define('menu-active', MenuActive) window.customElements.define('clipboard-copy', ClipboardCopy) window.customElements.define('dynamic-list', DynamicList) window.customElements.define('download-button', DownloadButton) +window.customElements.define('set-origin-url', SetOriginUrl) window.customElements.define('template-builder', class extends HTMLElement { connectedCallback () { diff --git a/app/javascript/elements/set_origin_url.js b/app/javascript/elements/set_origin_url.js new file mode 100644 index 00000000..77b0758f --- /dev/null +++ b/app/javascript/elements/set_origin_url.js @@ -0,0 +1,7 @@ +export default class extends HTMLElement { + connectedCallback () { + if (this.dataset.inputId) { + document.getElementById(this.dataset.inputId).value = document.location.origin + } + } +} diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 0962aa12..8631df97 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -5,4 +5,8 @@ class ApplicationMailer < ActionMailer::Base layout 'mailer' register_interceptor ActionMailerConfigsInterceptor + + def default_url_options + Docuseal.default_url_options + end end diff --git a/app/models/encrypted_config.rb b/app/models/encrypted_config.rb index 0f11dd10..e06e5f52 100644 --- a/app/models/encrypted_config.rb +++ b/app/models/encrypted_config.rb @@ -24,6 +24,7 @@ class EncryptedConfig < ApplicationRecord FILES_STORAGE_KEY = 'active_storage' EMAIL_SMTP_KEY = 'action_mailer_smtp' ESIGN_CERTS_KEY = 'esign_certs' + APP_URL_KEY = 'app_url' belongs_to :account diff --git a/app/views/profile/index.html.erb b/app/views/profile/index.html.erb index ec9244a7..b367a41e 100644 --- a/app/views/profile/index.html.erb +++ b/app/views/profile/index.html.erb @@ -44,6 +44,15 @@ <%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %> <% end %> +