Files
docuseal/app/controllers/accounts_controller.rb
T

68 lines
1.8 KiB
Ruby
Raw Normal View History

2023-06-30 01:26:13 +03:00
# frozen_string_literal: true
class AccountsController < ApplicationController
LOCALE_OPTIONS = {
'en-US' => 'English (United States)',
'en-GB' => 'English (United Kingdom)',
2023-11-11 15:28:43 +02:00
'fr-FR' => 'French (France)',
2023-06-30 01:26:13 +03:00
'es-ES' => 'Spanish (Spain)',
'pt-PT' => 'Portuguese (Portugal)',
'de-DE' => 'German (Germany)'
}.freeze
2023-09-17 00:45:57 +03:00
before_action :load_account
authorize_resource :account
2023-06-30 01:26:13 +03:00
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)
2023-07-04 23:05:22 +03:00
@encrypted_config.assign_attributes(app_url_params)
unless URI.parse(@encrypted_config.value.to_s).class.in?([URI::HTTP, URI::HTTPS])
@encrypted_config.errors.add(:value, 'should be a valid URL')
return render :show, status: :unprocessable_entity
end
@encrypted_config.save!
2023-06-30 01:26:13 +03:00
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
2024-01-29 01:13:41 +02:00
def destroy
authorize!(:manage, current_account)
true_user.update!(locked_at: Time.current)
render turbo_stream: turbo_stream.replace(
:account_delete_button,
html: helpers.tag.p('Your account removal request will be processed within 2 weeks. ' \
'Please contact us if you want to keep your account.')
)
end
2023-06-30 01:26:13 +03:00
private
2023-09-17 00:45:57 +03:00
def load_account
@account = current_account
end
2023-06-30 01:26:13 +03:00
def account_params
params.require(:account).permit(:name, :timezone, :locale)
end
def app_url_params
2023-07-14 22:33:42 +03:00
return {} if params[:encrypted_config].blank?
2023-06-30 01:26:13 +03:00
params.require(:encrypted_config).permit(:value)
end
end