adjust templates, add timezone and locale
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AccountsController < ApplicationController
|
||||
LOCALE_OPTIONS = {
|
||||
'en-US' => 'English (United States)',
|
||||
'en-GB' => 'English (United Kingdom)',
|
||||
'es-ES' => 'Spanish (Spain)',
|
||||
'pt-PT' => 'Portuguese (Portugal)',
|
||||
'de-DE' => 'German (Germany)'
|
||||
}.freeze
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
current_account.update!(account_params)
|
||||
|
||||
@encrypted_config = EncryptedConfig.find_or_initialize_by(account: current_account,
|
||||
key: EncryptedConfig::APP_URL_KEY)
|
||||
@encrypted_config.update!(app_url_params)
|
||||
|
||||
Docuseal.refresh_default_url_options!
|
||||
|
||||
redirect_to settings_account_path, notice: 'Account information has been updated'
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
render :show, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:name, :timezone, :locale)
|
||||
end
|
||||
|
||||
def app_url_params
|
||||
params.require(:encrypted_config).permit(:value)
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,11 @@
|
||||
# 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'
|
||||
redirect_to settings_profile_index_path, notice: 'Contact information has been updated'
|
||||
else
|
||||
render :index, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,17 +14,7 @@ class ProfileController < ApplicationController
|
||||
def update_password
|
||||
if current_user.update(password_params)
|
||||
bypass_sign_in(current_user)
|
||||
redirect_to settings_profile_index_path, notice: 'Password successfully changed'
|
||||
else
|
||||
render :index, status: :unprocessable_entity
|
||||
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'
|
||||
redirect_to settings_profile_index_path, notice: 'Password has been changed'
|
||||
else
|
||||
render :index, status: :unprocessable_entity
|
||||
end
|
||||
@@ -34,20 +22,11 @@ class ProfileController < ApplicationController
|
||||
|
||||
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])
|
||||
params.require(:user).permit(:first_name, :last_name, :email)
|
||||
end
|
||||
|
||||
def password_params
|
||||
params.require(:user).permit(:password, :password_confirmation)
|
||||
end
|
||||
|
||||
def app_url_params
|
||||
params.require(:encrypted_config).permit(:value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ class RegistrationsController < Devise::RegistrationsController
|
||||
|
||||
def build_resource(_hash = {})
|
||||
account = Account.new(account_params)
|
||||
account.timezone = Accounts.normalize_timezone(account.timezone)
|
||||
|
||||
self.resource = account.users.new(user_params)
|
||||
end
|
||||
@@ -18,6 +19,6 @@ class RegistrationsController < Devise::RegistrationsController
|
||||
def account_params
|
||||
return {} if params[:account].blank?
|
||||
|
||||
params.require(:account).permit(:name)
|
||||
params.require(:account).permit(:name, :timezone)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,8 @@ class SetupController < ApplicationController
|
||||
|
||||
def create
|
||||
@account = Account.new(account_params)
|
||||
@account.timezone = Accounts.normalize_timezone(@account.timezone)
|
||||
|
||||
@user = @account.users.new(user_params)
|
||||
|
||||
if @user.save
|
||||
@@ -24,6 +26,8 @@ class SetupController < ApplicationController
|
||||
]
|
||||
@account.encrypted_configs.create!(encrypted_configs)
|
||||
|
||||
Docuseal.refresh_default_url_options!
|
||||
|
||||
sign_in(@user)
|
||||
|
||||
redirect_to root_path
|
||||
@@ -43,7 +47,7 @@ class SetupController < ApplicationController
|
||||
def account_params
|
||||
return {} unless params[:account]
|
||||
|
||||
params.require(:account).permit(:name)
|
||||
params.require(:account).permit(:name, :timezone)
|
||||
end
|
||||
|
||||
def encrypted_config_params
|
||||
|
||||
@@ -16,7 +16,7 @@ class StartFormController < ApplicationController
|
||||
.find_or_initialize_by(**submitter_params)
|
||||
|
||||
if @submitter.completed_at?
|
||||
redirect_to start_form_completed_path(@template.slug, email: submission_params[:email])
|
||||
redirect_to start_form_completed_path(@template.slug, email: submitter_params[:email])
|
||||
else
|
||||
@submitter.assign_attributes(
|
||||
uuid: @template.submitters.first['uuid'],
|
||||
@@ -36,7 +36,7 @@ class StartFormController < ApplicationController
|
||||
end
|
||||
|
||||
def completed
|
||||
@submitter = Submitter.where(submission: @template.submitters).find_by(email: params[:email])
|
||||
@submitter = Submitter.where(submission: @template.submissions).find_by!(email: params[:email])
|
||||
end
|
||||
|
||||
private
|
||||
@@ -46,7 +46,7 @@ class StartFormController < ApplicationController
|
||||
end
|
||||
|
||||
def load_template
|
||||
slug = params[:slug] || params[:start_template_slug]
|
||||
slug = params[:slug] || params[:start_form_slug]
|
||||
|
||||
@template = Template.find_by!(slug:)
|
||||
end
|
||||
|
||||
@@ -19,6 +19,7 @@ class SubmitFormController < ApplicationController
|
||||
submitter = Submitter.find_by!(slug: params[:slug])
|
||||
submitter.values.merge!(normalized_values)
|
||||
submitter.completed_at = Time.current if params[:completed] == 'true'
|
||||
submitter.opened_at ||= Time.current
|
||||
|
||||
submitter.save!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user