You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/app/controllers/account_logo_controller.rb

37 lines
1.2 KiB

# frozen_string_literal: true
class AccountLogoController < ApplicationController
before_action :authorize_change
def create
file = params[:logo]
return reject('Choose a file to upload.') if file.blank? || !file.respond_to?(:content_type)
return reject('Logo must be a PNG, JPEG, or SVG image.') unless Account::LOGO_CONTENT_TYPES.include?(file.content_type)
return reject("Logo must be under #{Account::LOGO_MAX_BYTES / 1.megabyte} MB.") if file.size > Account::LOGO_MAX_BYTES
safe = AccountLogo.sanitize_upload(file)
current_account.logo.attach(io: safe.io, filename: safe.filename, content_type: safe.content_type)
redirect_to settings_personalization_path, notice: 'Logo updated.'
rescue StandardError => e
Rails.logger.warn("[AccountLogo] upload failed: #{e.class}: #{e.message}")
reject("Couldn't save the logo: #{e.message}")
end
def destroy
current_account.logo.purge if current_account.logo.attached?
redirect_to settings_personalization_path, notice: 'Logo removed.'
end
private
def authorize_change
authorize!(:manage, current_account)
end
def reject(message)
redirect_back(fallback_location: settings_personalization_path, alert: message)
end
end