module BrandingAttachments extend ActiveSupport::Concern private def attach_branding_logo(record) file = params.dig(:branding, :logo_file) record.logo_file.attach(file) if file.present? end def attach_cover_image(record, entitlements:) remove_flag = params[:remove_cover].to_s == "1" || params.dig(:match, :remove_cover).to_s == "1" if remove_flag record.cover_image.purge if record.cover_image.attached? record.cover_slate.purge if record.cover_slate.attached? return end file = params.dig(:branding, :cover_image) || params[:cover_image] return if file.blank? entitlements.assert_can_upload_cover! record.cover_slate.purge if record.cover_slate.attached? record.cover_image.attach(file) end def enqueue_cover_slate_generation(record) GenerateCoverSlateJob.enqueue_for(record) if record.cover_image.attached? end def normalize_hex_color(value, fallback) v = value.to_s.strip v = "##{v}" if v.match?(/\A[0-9A-Fa-f]{6}\z/) v.match?(Brandable::HEX_COLOR) ? v : fallback end end