add the app url input on the first setup page
This commit is contained in:
@@ -10,6 +10,10 @@ class ApplicationController < ActionController::Base
|
|||||||
:current_account,
|
:current_account,
|
||||||
:svg_icon
|
:svg_icon
|
||||||
|
|
||||||
|
def default_url_options
|
||||||
|
Docuseal.default_url_options
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def current_account
|
def current_account
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ProfileController < ApplicationController
|
class ProfileController < ApplicationController
|
||||||
|
before_action :load_encrypted_config, only: %i[index update_app_url]
|
||||||
|
|
||||||
|
def index; end
|
||||||
|
|
||||||
def update_contact
|
def update_contact
|
||||||
if current_user.update(contact_params)
|
if current_user.update(contact_params)
|
||||||
redirect_to settings_profile_index_path, notice: 'Contact information successfully updated'
|
redirect_to settings_profile_index_path, notice: 'Contact information successfully updated'
|
||||||
@@ -18,8 +22,23 @@ class ProfileController < ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
|
def load_encrypted_config
|
||||||
|
@encrypted_config =
|
||||||
|
EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::APP_URL_KEY)
|
||||||
|
end
|
||||||
|
|
||||||
def contact_params
|
def contact_params
|
||||||
params.require(:user).permit(:first_name, :last_name, :email, account_attributes: %i[name])
|
params.require(:user).permit(:first_name, :last_name, :email, account_attributes: %i[name])
|
||||||
end
|
end
|
||||||
@@ -27,4 +46,8 @@ class ProfileController < ApplicationController
|
|||||||
def password_params
|
def password_params
|
||||||
params.require(:user).permit(:password, :password_confirmation)
|
params.require(:user).permit(:password, :password_confirmation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def app_url_params
|
||||||
|
params.require(:encrypted_config).permit(:value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class SetupController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
@account = Account.new(account_params)
|
@account = Account.new(account_params)
|
||||||
@user = @account.users.new(user_params)
|
@user = @account.users.new(user_params)
|
||||||
|
@encrypted_config = EncryptedConfig.new(account: @account, key: EncryptedConfig::APP_URL_KEY)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -17,8 +18,11 @@ class SetupController < ApplicationController
|
|||||||
@user = @account.users.new(user_params)
|
@user = @account.users.new(user_params)
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
@account.encrypted_configs.create!(key: EncryptedConfig::ESIGN_CERTS_KEY,
|
encrypted_configs = [
|
||||||
value: GenerateCertificate.call)
|
{ 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)
|
sign_in(@user)
|
||||||
|
|
||||||
@@ -42,6 +46,12 @@ class SetupController < ApplicationController
|
|||||||
params.require(:account).permit(:name)
|
params.require(:account).permit(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def encrypted_config_params
|
||||||
|
return {} unless params[:encrypted_config]
|
||||||
|
|
||||||
|
params.require(:encrypted_config).permit(:value)
|
||||||
|
end
|
||||||
|
|
||||||
def redirect_to_root_if_signed
|
def redirect_to_root_if_signed
|
||||||
redirect_to root_path, notice: 'You are already signed in'
|
redirect_to root_path, notice: 'You are already signed in'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import ClipboardCopy from './elements/clipboard_copy'
|
|||||||
import TemplateBuilder from './template_builder/builder'
|
import TemplateBuilder from './template_builder/builder'
|
||||||
import DynamicList from './elements/dynamic_list'
|
import DynamicList from './elements/dynamic_list'
|
||||||
import DownloadButton from './elements/download_button'
|
import DownloadButton from './elements/download_button'
|
||||||
|
import SetOriginUrl from './elements/set_origin_url'
|
||||||
|
|
||||||
document.addEventListener('turbo:before-cache', () => {
|
document.addEventListener('turbo:before-cache', () => {
|
||||||
window.flash?.remove()
|
window.flash?.remove()
|
||||||
@@ -30,6 +31,7 @@ window.customElements.define('menu-active', MenuActive)
|
|||||||
window.customElements.define('clipboard-copy', ClipboardCopy)
|
window.customElements.define('clipboard-copy', ClipboardCopy)
|
||||||
window.customElements.define('dynamic-list', DynamicList)
|
window.customElements.define('dynamic-list', DynamicList)
|
||||||
window.customElements.define('download-button', DownloadButton)
|
window.customElements.define('download-button', DownloadButton)
|
||||||
|
window.customElements.define('set-origin-url', SetOriginUrl)
|
||||||
|
|
||||||
window.customElements.define('template-builder', class extends HTMLElement {
|
window.customElements.define('template-builder', class extends HTMLElement {
|
||||||
connectedCallback () {
|
connectedCallback () {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export default class extends HTMLElement {
|
||||||
|
connectedCallback () {
|
||||||
|
if (this.dataset.inputId) {
|
||||||
|
document.getElementById(this.dataset.inputId).value = document.location.origin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,4 +5,8 @@ class ApplicationMailer < ActionMailer::Base
|
|||||||
layout 'mailer'
|
layout 'mailer'
|
||||||
|
|
||||||
register_interceptor ActionMailerConfigsInterceptor
|
register_interceptor ActionMailerConfigsInterceptor
|
||||||
|
|
||||||
|
def default_url_options
|
||||||
|
Docuseal.default_url_options
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class EncryptedConfig < ApplicationRecord
|
|||||||
FILES_STORAGE_KEY = 'active_storage'
|
FILES_STORAGE_KEY = 'active_storage'
|
||||||
EMAIL_SMTP_KEY = 'action_mailer_smtp'
|
EMAIL_SMTP_KEY = 'action_mailer_smtp'
|
||||||
ESIGN_CERTS_KEY = 'esign_certs'
|
ESIGN_CERTS_KEY = 'esign_certs'
|
||||||
|
APP_URL_KEY = 'app_url'
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,15 @@
|
|||||||
<%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %>
|
<%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<h2 class="text-2xl font-bold mt-8 mb-4">App URL</h2>
|
||||||
|
<%= form_for @encrypted_config, url: update_app_url_settings_profile_index_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
|
||||||
|
<div class="form-control">
|
||||||
|
<%= f.text_field :value, required: true, class: 'base-input' %>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-0 md:w-52"></div>
|
<div class="w-0 md:w-52"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,6 +30,15 @@
|
|||||||
<%= ff.password_field :password, required: true, placeholder: '************', class: 'base-input' %>
|
<%= ff.password_field :password, required: true, placeholder: '************', class: 'base-input' %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= f.fields_for @encrypted_config do |ff| %>
|
||||||
|
<div class="form-control">
|
||||||
|
<% if @encrypted_config.value.blank? %>
|
||||||
|
<set-origin-url data-input-id="_encrypted_config_value"></set-origin-url>
|
||||||
|
<% end %>
|
||||||
|
<%= ff.label :value, 'App URL', class: 'label' %>
|
||||||
|
<%= ff.text_field :value, required: true, class: 'base-input' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<%= f.button button_title(title: 'Confirm', disabled_with: 'Processing'), class: 'base-button' %>
|
<%= f.button button_title(title: 'Confirm', disabled_with: 'Processing'), class: 'base-button' %>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ require 'active_job/railtie'
|
|||||||
|
|
||||||
Bundler.require(*Rails.groups)
|
Bundler.require(*Rails.groups)
|
||||||
|
|
||||||
module Docuseal
|
module DocuSeal
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
config.load_defaults 7.0
|
config.load_defaults 7.0
|
||||||
|
|
||||||
|
|||||||
@@ -75,10 +75,6 @@ Rails.application.configure do
|
|||||||
key_derivation_salt: 'dev key derivation salt'
|
key_derivation_salt: 'dev key derivation salt'
|
||||||
}
|
}
|
||||||
|
|
||||||
config.action_mailer.default_url_options = { host: 'localhost', port: ENV.fetch('PORT', 3000).to_i }
|
|
||||||
config.action_controller.default_url_options = config.action_mailer.default_url_options
|
|
||||||
routes.default_url_options = config.action_mailer.default_url_options
|
|
||||||
|
|
||||||
# Raises error for missing translations.
|
# Raises error for missing translations.
|
||||||
# config.i18n.raise_on_missing_translations = true
|
# config.i18n.raise_on_missing_translations = true
|
||||||
|
|
||||||
|
|||||||
@@ -81,10 +81,6 @@ Rails.application.configure do
|
|||||||
key_derivation_salt: ENV.fetch('SECRET_KEY_BASE', nil)
|
key_derivation_salt: ENV.fetch('SECRET_KEY_BASE', nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.action_mailer.default_url_options = { host: ENV.fetch('HOST', nil), port: ENV.fetch('PORT', nil) }
|
|
||||||
config.action_controller.default_url_options = config.action_mailer.default_url_options
|
|
||||||
routes.default_url_options = config.action_mailer.default_url_options
|
|
||||||
|
|
||||||
# Do not dump schema after migrations.
|
# Do not dump schema after migrations.
|
||||||
config.active_record.dump_schema_after_migration = false
|
config.active_record.dump_schema_after_migration = false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ Rails.application.routes.draw do
|
|||||||
collection do
|
collection do
|
||||||
patch :update_contact
|
patch :update_contact
|
||||||
patch :update_password
|
patch :update_password
|
||||||
|
patch :update_app_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Docuseal
|
||||||
|
DEFAULT_APP_URL = 'http://localhost:3000'
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def default_url_options
|
||||||
|
@default_url_options ||= begin
|
||||||
|
value = EncryptedConfig.find_by(key: EncryptedConfig::APP_URL_KEY)&.value
|
||||||
|
value ||= DEFAULT_APP_URL
|
||||||
|
url = Addressable::URI.parse(value)
|
||||||
|
{ host: url.host, port: url.port, protocol: url.scheme }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def refresh_default_url_options!
|
||||||
|
@default_url_options = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user