Files
docuseal/app/controllers/accounts_controller.rb
T

77 lines
2.1 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)',
2024-09-23 15:22:07 +03:00
'fr-FR' => 'Français',
'es-ES' => 'Español',
'pt-PT' => 'Português',
'de-DE' => 'Deutsch',
2025-10-06 17:04:01 +03:00
'it-IT' => 'Italiano',
'nl-NL' => 'Nederlands'
2023-06-30 01:26:13 +03:00
}.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)
2024-09-28 10:11:04 +03:00
unless Docuseal.multitenant?
@encrypted_config = EncryptedConfig.find_or_initialize_by(account: current_account,
key: EncryptedConfig::APP_URL_KEY)
@encrypted_config.assign_attributes(app_url_params)
2023-07-04 23:05:22 +03:00
2024-09-28 10:11:04 +03:00
unless URI.parse(@encrypted_config.value.to_s).class.in?([URI::HTTP, URI::HTTPS])
@encrypted_config.errors.add(:value, I18n.t('should_be_a_valid_url'))
2023-07-04 23:05:22 +03:00
2025-08-14 09:25:35 +03:00
return render :show, status: :unprocessable_content
2024-09-28 10:11:04 +03:00
end
2023-07-04 23:05:22 +03:00
2024-09-28 10:11:04 +03:00
@encrypted_config.save!
2023-06-30 01:26:13 +03:00
2024-09-28 10:11:04 +03:00
Docuseal.refresh_default_url_options!
end
2023-06-30 01:26:13 +03:00
2024-09-28 01:21:35 +03:00
with_locale do
redirect_to settings_account_path, notice: I18n.t('account_information_has_been_updated')
end
2023-06-30 01:26:13 +03:00
rescue ActiveRecord::RecordInvalid
2025-08-14 09:25:35 +03:00
render :show, status: :unprocessable_content
2023-06-30 01:26:13 +03:00
end
2024-01-29 01:13:41 +02:00
def destroy
authorize!(:manage, current_account)
2025-11-30 16:30:56 +02:00
true_user.skip_reconfirmation!
2025-04-16 00:54:36 +03:00
true_user.update!(locked_at: Time.current, email: true_user.email.sub('@', '+removed@'))
2025-10-22 20:37:08 +03:00
true_user.account.update!(archived_at: Time.current)
2024-01-29 01:13:41 +02:00
2024-09-18 19:47:47 +03:00
# rubocop:disable Layout/LineLength
2024-01-29 01:13:41 +02:00
render turbo_stream: turbo_stream.replace(
:account_delete_button,
2025-01-22 11:49:04 +02:00
html: helpers.tag.p(I18n.t('your_account_removal_request_will_be_processed_within_2_months_please_contact_us_if_you_want_to_keep_your_account'))
2024-01-29 01:13:41 +02:00
)
2024-09-18 19:47:47 +03:00
# rubocop:enable Layout/LineLength
2024-01-29 01:13:41 +02:00
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