diff --git a/app/controllers/account_logo_controller.rb b/app/controllers/account_logo_controller.rb new file mode 100644 index 00000000..e3b69bd0 --- /dev/null +++ b/app/controllers/account_logo_controller.rb @@ -0,0 +1,36 @@ +# 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 diff --git a/app/models/account.rb b/app/models/account.rb index d3d53d0c..aab90683 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -18,8 +18,13 @@ # index_accounts_on_uuid (uuid) UNIQUE # class Account < ApplicationRecord + LOGO_CONTENT_TYPES = %w[image/png image/jpeg image/svg+xml].freeze + LOGO_MAX_BYTES = 2.megabytes + attribute :uuid, :string, default: -> { SecureRandom.uuid } + has_one_attached :logo + has_many :users, dependent: :destroy has_many :encrypted_configs, dependent: :destroy has_many :account_configs, dependent: :destroy diff --git a/app/views/personalization_settings/_logo_form.html.erb b/app/views/personalization_settings/_logo_form.html.erb index fc6f3ac7..1740e7e8 100644 --- a/app/views/personalization_settings/_logo_form.html.erb +++ b/app/views/personalization_settings/_logo_form.html.erb @@ -1 +1,32 @@ -<%= render 'logo_placeholder' %> +
+ Replaces the default WaboSign mark on the sign-in page, signing flow, dashboard navbar, share-link QR page, and audit-trail PDFs. Browser favicons and the PWA manifest icon stay on the default brand. +
+- <%= t('display_your_company_name_and_logo_when_signing_documents') %> -
-- Logo upload UI is not bundled with this open-source edition. Drop your custom logo into public/logo.svg and edit app/views/shared/_logo.html.erb to white-label the signing UI. -
-