* wip - Got logo upload working * Now have the logo rendering in the header and in the admin image config section. * Small layout tweak for admin -> config -> images -> logo. * feat: create a logo uploader with some tests * feat: use the logoUploader instead of the ArticleImageUploader * feat: return early because svg's do not contain exif or gps data * chore: we can move the raise outside the transaction as the rest of the transaction won't execute if we raise an error * feat: add a size range * WIP: resize an image to a random number for now * hid the logo behind a feature flag and kept logo_svg as is in the site header. * Added the jpe file type to the logo uploader. * Skipped the resizing of an image if it's an SVG in the logo uploader. * Added content types to the content type logo uploader allow list. * Synced logo validation with frontend and backend. * Removed unnecessary ALLOWED_PARAMS elements. * feat: update the logo upoader and tests * chore: remove comments * chore: remove comments * feat: update the resizing for the images + add the correct content type * spec: test the versions * fix: update the Constant * feat: add the versions of the logo * feat: populate the settings correctly and consistently * feat: add an random string to the file name to avoid caching issues * feat: amend the logo layout * chore: remove comments * spec: update * feat: image type whitelist * feat: update the logo css and also just use resized_logo and remove mobile resize * feat: add a max-height * only add site-logo if the feature flag is off * Renamed IMAGE_TYPE_WHITELIST to IMAGE_TYPE_ALLOWLIST * Update app/controllers/admin/creator_settings_controller.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Update app/uploaders/logo_uploader.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Update app/uploaders/logo_uploader.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Update app/uploaders/logo_uploader.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Update spec/uploaders/logo_uploader_spec.rb Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> * Update spec/uploaders/logo_uploader_spec.rb Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> * chore: revert admin change * refactor: use a static value for directory * feat: freeze constants * feat: remove the logo requirement * chore: spacing * remove logo requirement Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com> Co-authored-by: Michael Kohl <citizen428@forem.com> Co-authored-by: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com>
54 lines
1.9 KiB
Ruby
54 lines
1.9 KiB
Ruby
module Admin
|
|
class CreatorSettingsController < Admin::ApplicationController
|
|
ALLOWED_PARAMS = %i[checked_code_of_conduct checked_terms_and_conditions community_name
|
|
invite_only_mode logo primary_brand_color_hex public].freeze
|
|
|
|
def new
|
|
@max_file_size = LogoUploader::MAX_FILE_SIZE
|
|
@logo_allowed_types = (LogoUploader::CONTENT_TYPE_ALLOWLIST +
|
|
LogoUploader::EXTENSION_ALLOWLIST.map { |extension| ".#{extension}" }).join(",")
|
|
end
|
|
|
|
def create
|
|
extra_authorization
|
|
ActiveRecord::Base.transaction do
|
|
::Settings::Community.community_name = settings_params[:community_name]
|
|
::Settings::UserExperience.primary_brand_color_hex = settings_params[:primary_brand_color_hex]
|
|
::Settings::Authentication.invite_only_mode = settings_params[:invite_only]
|
|
::Settings::UserExperience.public = settings_params[:public]
|
|
|
|
if settings_params[:logo]
|
|
logo_uploader = upload_logo(settings_params[:logo])
|
|
::Settings::General.original_logo = logo_uploader.url
|
|
# An SVG will not be resized, hence we apply the OR statements below to populate SETTINGS consistently.
|
|
::Settings::General.resized_logo = logo_uploader.resized_logo.url || logo_uploader.url
|
|
end
|
|
end
|
|
current_user.update!(
|
|
saw_onboarding: true,
|
|
checked_code_of_conduct: settings_params[:checked_code_of_conduct],
|
|
checked_terms_and_conditions: settings_params[:checked_terms_and_conditions],
|
|
)
|
|
redirect_to root_path
|
|
rescue StandardError => e
|
|
flash.now[:error] = e.message
|
|
render new_admin_creator_setting_path
|
|
end
|
|
|
|
private
|
|
|
|
def extra_authorization
|
|
not_authorized unless current_user.has_role?(:creator)
|
|
end
|
|
|
|
def settings_params
|
|
params.permit(ALLOWED_PARAMS)
|
|
end
|
|
|
|
def upload_logo(image)
|
|
LogoUploader.new.tap do |uploader|
|
|
uploader.store!(image)
|
|
end
|
|
end
|
|
end
|
|
end
|