docbrown/app/models/settings/user_experience.rb
Ben Halpern ec7adf56fe
Allow admins to set cover image height configs (#19936)
* Initial basic work

* Bulk of related work, including find/replace on the inputs

* Adjust some tests

* Adjust some specs

* Fix a few more tests

* Clean up tests

* Adjust tests

* Test fiddle

* Adjust crop back to be a param

* Update tests

* Set proper defaults

* Fix some styling

* Adjust enrichment logic and tests

* Adjust form JS

* Update test snapshot

* Clean up formatting

* Fix spec name

* Adjust some css and defaults

* Adjust translation for image provider options

* Switch from fill to fill-down

* Proper fallback image

* Fix tests

* Update app/services/images/optimizer.rb

Co-authored-by: Mac Siri <mac@forem.com>

---------

Co-authored-by: Mac Siri <mac@forem.com>
2023-08-21 13:25:16 -04:00

44 lines
1.9 KiB
Ruby

module Settings
# Basic UX settings that can be overridden by individual user preferences.
class UserExperience < Base
self.table_name = :settings_user_experiences
HEX_COLOR_REGEX = /\A#(\h{6}|\h{3})\z/
FEED_STRATEGIES = %w[basic large_forem_experimental].freeze
FEED_STYLES = %w[basic rich compact].freeze
COVER_IMAGE_FITS = %w[crop limit].freeze
# The default font for all users that have not chosen a custom font yet
setting :default_font, type: :string, default: "sans_serif"
setting :feed_strategy, type: :string, default: "basic", validates: {
inclusion: { in: FEED_STRATEGIES }
}
# basic (current default), rich (cover image on all posts), compact (more minimal)
setting :feed_style, type: :string, default: "basic", validates: {
inclusion: { in: FEED_STYLES }
}
setting :home_feed_minimum_score, type: :integer, default: 0
setting :index_minimum_score, type: :integer, default: 0
setting :index_minimum_date, type: :integer, default: 1_500_000_000
setting :primary_brand_color_hex, type: :string, default: "#3b49df", validates: {
format: {
with: HEX_COLOR_REGEX,
message: proc { I18n.t("models.settings.user_experience.message") }
},
color_contrast: true
}
# cover images
setting :cover_image_height, type: :integer, default: 420
setting :cover_image_fit, type: :string, default: "crop", validates: {
inclusion: { in: COVER_IMAGE_FITS }
}
# a non-public forem will redirect all unauthenticated pages to the registration page.
# a public forem could have more fine-grained authentication (listings ar private etc.) in future
setting :public, type: :boolean, default: true
setting :tag_feed_minimum_score, type: :integer, default: 0
setting :default_locale, type: :string, default: "en"
setting :display_in_directory, type: :boolean, default: true
end
end