2023-05-21 17:59:36 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2023-09-17 20:38:09 +03:00
|
|
|
class EmailSmtpSettingsController < ApplicationController
|
2023-05-21 17:59:36 +03:00
|
|
|
before_action :load_encrypted_config
|
2023-09-17 00:45:57 +03:00
|
|
|
authorize_resource :encrypted_config, only: :index
|
2026-07-13 10:19:47 +03:00
|
|
|
authorize_resource :encrypted_config, parent: false, only: %i[create destroy]
|
2023-05-21 17:59:36 +03:00
|
|
|
|
|
|
|
|
def index; end
|
|
|
|
|
|
|
|
|
|
def create
|
2023-09-03 14:05:31 +03:00
|
|
|
if @encrypted_config.update(email_configs)
|
2025-05-26 14:46:33 +03:00
|
|
|
unless Docuseal.multitenant?
|
|
|
|
|
SettingsMailer.smtp_successful_setup(@encrypted_config.value['from_email'] || current_user.email).deliver_now!
|
|
|
|
|
end
|
2023-08-10 23:35:51 +03:00
|
|
|
|
2024-09-18 19:47:47 +03:00
|
|
|
redirect_to settings_email_index_path, notice: I18n.t('changes_have_been_saved')
|
2023-05-21 17:59:36 +03:00
|
|
|
else
|
2025-08-14 09:25:35 +03:00
|
|
|
render :index, status: :unprocessable_content
|
2023-05-21 17:59:36 +03:00
|
|
|
end
|
2023-08-15 21:51:46 +03:00
|
|
|
rescue StandardError => e
|
2023-08-10 23:35:51 +03:00
|
|
|
flash[:alert] = e.message
|
|
|
|
|
|
2025-08-14 09:25:35 +03:00
|
|
|
render :index, status: :unprocessable_content
|
2023-05-21 17:59:36 +03:00
|
|
|
end
|
|
|
|
|
|
2026-07-13 10:19:47 +03:00
|
|
|
def destroy
|
|
|
|
|
@encrypted_config.destroy!
|
|
|
|
|
|
|
|
|
|
redirect_to settings_email_index_path, notice: I18n.t('smtp_settings_have_been_reset')
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def load_encrypted_config
|
|
|
|
|
@encrypted_config =
|
|
|
|
|
EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::EMAIL_SMTP_KEY)
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-03 14:05:31 +03:00
|
|
|
def email_configs
|
2023-05-21 17:59:36 +03:00
|
|
|
params.require(:encrypted_config).permit(value: {}).tap do |e|
|
|
|
|
|
e[:value].compact_blank!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|