add the app url input on the first setup page

This commit is contained in:
Alex Turchyn
2023-06-20 23:42:56 +03:00
parent 4977ee429c
commit 0ac30a5fc0
14 changed files with 93 additions and 11 deletions
@@ -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
+23
View File
@@ -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
+12 -2
View File
@@ -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