Files
docuseal/app/controllers/user_signatures_controller.rb
T

44 lines
1.2 KiB
Ruby
Raw Normal View History

2023-09-22 21:50:39 +03:00
# frozen_string_literal: true
class UserSignaturesController < ApplicationController
before_action :load_user_config
authorize_resource :user_config
def edit; end
def update
file = params[:file]
2024-09-23 15:45:47 +03:00
return redirect_to settings_profile_index_path, notice: I18n.t('unable_to_save_signature') if file.blank?
2023-09-22 21:50:39 +03:00
blob = ActiveStorage::Blob.create_and_upload!(io: file.open,
filename: file.original_filename,
content_type: file.content_type)
attachment = ActiveStorage::Attachment.create!(
blob:,
name: 'signature',
record: current_user
)
if @user_config.update(value: attachment.uuid)
2024-09-18 19:47:47 +03:00
redirect_to settings_profile_index_path, notice: I18n.t('signature_has_been_saved')
2023-09-22 21:50:39 +03:00
else
2024-09-23 15:45:47 +03:00
redirect_to settings_profile_index_path, notice: I18n.t('unable_to_save_signature')
2023-09-22 21:50:39 +03:00
end
end
def destroy
@user_config.destroy
2024-09-18 19:47:47 +03:00
redirect_to settings_profile_index_path, notice: I18n.t('signature_has_been_removed')
end
2023-09-22 21:50:39 +03:00
private
def load_user_config
@user_config =
UserConfig.find_or_initialize_by(user: current_user, key: UserConfig::SIGNATURE_KEY)
end
end