diff --git a/app/controllers/admin/settings/mascots_controller.rb b/app/controllers/admin/settings/mascots_controller.rb deleted file mode 100644 index cd4e66f0a..000000000 --- a/app/controllers/admin/settings/mascots_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Admin - module Settings - class MascotsController < Admin::ApplicationController - def create - errors = upsert_config(settings_params) - - if errors.none? - Audit::Logger.log(:internal, current_user, params.dup) - redirect_to admin_config_path, notice: "Site configuration was successfully updated." - else - redirect_to admin_config_path, alert: "😠#{errors.to_sentence}" - end - end - - def settings_params - params - .require(:settings_mascot) - .permit(*::Settings::Mascot.keys) - end - - def upsert_config(configs) - errors = [] - configs.each do |key, value| - ::Settings::Mascot.public_send("#{key}=", value) if value.present? - rescue ActiveRecord::RecordInvalid => e - errors << e.message - next - end - - errors - end - end - end -end diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index 91e153160..07bcfd855 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -57,10 +57,10 @@ class ChatChannelsController < ApplicationController flash[:error] = chat_channel.errors.full_messages.to_sentence else if chat_channel_params[:discoverable].to_i.zero? - ChatChannelMembership.create(user_id: Settings::Mascot.mascot_user_id, chat_channel_id: chat_channel.id, + ChatChannelMembership.create(user_id: SiteConfig.mascot_user_id, chat_channel_id: chat_channel.id, role: "member", status: "active") else - ChatChannelMembership.find_by(user_id: Settings::Mascot.mascot_user_id)&.destroy + ChatChannelMembership.find_by(user_id: SiteConfig.mascot_user_id)&.destroy end flash[:settings_notice] = "Channel settings updated." end @@ -76,10 +76,10 @@ class ChatChannelsController < ApplicationController message: "Channel settings updation failed. Try again later." }, success: :bad_request else if chat_channel_params[:discoverable] - ChatChannelMembership.create(user_id: Settings::Mascot.mascot_user_id, chat_channel_id: @chat_channel.id, + ChatChannelMembership.create(user_id: SiteConfig.mascot_user_id, chat_channel_id: @chat_channel.id, role: "member", status: "active") else - ChatChannelMembership.find_by(user_id: Settings::Mascot.mascot_user_id)&.destroy + ChatChannelMembership.find_by(user_id: SiteConfig.mascot_user_id)&.destroy end render json: { success: true, message: "Channel settings updated.", data: {} }, success: :ok end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 4c009ddfb..154626e34 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -110,7 +110,7 @@ class CommentsController < ApplicationController response_template = ResponseTemplate.find(params[:response_template][:id]) authorize response_template, :moderator_create? - moderator = User.find(Settings::Mascot.mascot_user_id) + moderator = User.find(SiteConfig.mascot_user_id) @comment = Comment.new(permitted_attributes(Comment)) @comment.user_id = moderator.id @comment.body_markdown = response_template.content diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 1d77c55e7..1c52df701 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -68,7 +68,7 @@ class SearchController < ApplicationController def chat_channels user_ids = if chat_channel_params[:user_id].present? - [current_user.id, Settings::Mascot.mascot_user_id, chat_channel_params[:user_id]].reject(&:blank?) + [current_user.id, SiteConfig.mascot_user_id, chat_channel_params[:user_id]].reject(&:blank?) else [current_user.id] end diff --git a/app/lib/constants/settings/mascot.rb b/app/lib/constants/settings/mascot.rb deleted file mode 100644 index 4c325a70d..000000000 --- a/app/lib/constants/settings/mascot.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Constants - module Settings - module Mascot - DETAILS = { - footer_image_url: { - description: "Special cute mascot image used in the footer.", - placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER - }, - footer_image_width: { - description: "The footer mascot width will resized to this value, defaults to 52", - placeholder: "" - }, - footer_image_height: { - description: "The footer mascot height will be resized to this value, defaults to 120", - placeholder: "" - }, - image_description: { - description: "Used as the alt text for the mascot image", - placeholder: "" - }, - image_url: { - description: "Used as the mascot image.", - placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER - }, - mascot_user_id: { - description: "User ID of the Mascot account", - placeholder: "1" - } - }.freeze - end - end -end diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index c6a8affdf..be896d296 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -70,6 +70,14 @@ module Constants description: "Community Moderators Newsletter ID", placeholder: "" }, + mascot_image_url: { + description: "Used as the mascot image.", + placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER + }, + mascot_user_id: { + description: "User ID of the Mascot account", + placeholder: "1" + }, meta_keywords: { description: "", placeholder: "List of valid keywords: comma separated, letters only e.g. engineering, development" diff --git a/app/models/article.rb b/app/models/article.rb index e6ce90c9f..f308daee5 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -178,7 +178,7 @@ class Article < ApplicationRecord .where(user_id: User.with_role(:super_admin) .union(User.with_role(:admin)) .union(id: [Settings::Community.staff_user_id, - Settings::Mascot.mascot_user_id].compact) + SiteConfig.mascot_user_id].compact) .select(:id)).order(published_at: :desc).tagged_with(tag_name) } @@ -788,7 +788,7 @@ class Article < ApplicationRecord return unless SiteConfig.spam_trigger_terms.any? { |term| Regexp.new(term.downcase).match?(title.downcase) } Reaction.create( - user_id: Settings::Mascot.mascot_user_id, + user_id: SiteConfig.mascot_user_id, reactable_id: id, reactable_type: "Article", category: "vomit", @@ -798,7 +798,7 @@ class Article < ApplicationRecord user.add_role(:suspended) Note.create( - author_id: Settings::Mascot.mascot_user_id, + author_id: SiteConfig.mascot_user_id, noteable_id: user_id, noteable_type: "User", reason: "automatic_suspend", diff --git a/app/models/comment.rb b/app/models/comment.rb index d861f5a4c..7a0e2edbe 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -274,7 +274,7 @@ class Comment < ApplicationRecord user.registered_at > 5.days.ago Reaction.create( - user_id: Settings::Mascot.mascot_user_id, + user_id: SiteConfig.mascot_user_id, reactable_id: id, reactable_type: "Comment", category: "vomit", @@ -284,7 +284,7 @@ class Comment < ApplicationRecord user.add_role(:suspended) Note.create( - author_id: Settings::Mascot.mascot_user_id, + author_id: SiteConfig.mascot_user_id, noteable_id: user_id, noteable_type: "User", reason: "automatic_suspend", diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 62a95af05..cbba6b6eb 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -130,7 +130,7 @@ class Reaction < ApplicationRecord end def negative_reaction_from_untrusted_user? - return if user&.any_admin? || user&.id == Settings::Mascot.mascot_user_id + return if user&.any_admin? || user&.id == SiteConfig.mascot_user_id negative? && !user.trusted end diff --git a/app/models/settings/mascot.rb b/app/models/settings/mascot.rb index 42d297915..f994ce408 100644 --- a/app/models/settings/mascot.rb +++ b/app/models/settings/mascot.rb @@ -6,10 +6,6 @@ module Settings # the cache, or call Settings::Mascot.clear_cache cache_prefix { "v1" } - field :footer_image_height, type: :integer, default: 120 - field :footer_image_url, type: :string, validates: { url: true } - field :footer_image_width, type: :integer, default: 52 - field :image_description, type: :string, default: "The community mascot" field :image_url, type: :string, default: proc { URL.local_image("mascot.png") }, diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 59de94b07..6e6e99788 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -103,10 +103,6 @@ class SiteConfig < RailsSettings::Base type: :string, default: proc { URL.local_image("mascot.png") }, validates: { url: true } - field :mascot_image_description, type: :string, default: "The community mascot" - field :mascot_footer_image_url, type: :string, validates: { url: true } - field :mascot_footer_image_width, type: :integer, default: 52 - field :mascot_footer_image_height, type: :integer, default: 120 # Meta keywords field :meta_keywords, type: :hash, default: { diff --git a/app/models/user.rb b/app/models/user.rb index 8b27e6e0b..2cbe3edd2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -310,7 +310,7 @@ class User < ApplicationRecord end def self.mascot_account - find_by(id: Settings::Mascot.mascot_user_id) + find_by(id: SiteConfig.mascot_user_id) end def tag_line diff --git a/app/services/authentication/providers/apple.rb b/app/services/authentication/providers/apple.rb index 193b36fb6..ea2a05d10 100644 --- a/app/services/authentication/providers/apple.rb +++ b/app/services/authentication/providers/apple.rb @@ -18,7 +18,7 @@ module Authentication } if Rails.env.test? - user_data[:profile_image] = Settings::Mascot.image_url + user_data[:profile_image] = SiteConfig.mascot_image_url else user_data[:remote_profile_image_url] = Users::ProfileImageGenerator.call end diff --git a/app/services/users/create_mascot_account.rb b/app/services/users/create_mascot_account.rb index 4be3bd84f..db1c8f701 100644 --- a/app/services/users/create_mascot_account.rb +++ b/app/services/users/create_mascot_account.rb @@ -4,7 +4,7 @@ module Users email: "mascot@forem.com", username: "mascot", name: "Mascot", - profile_image: Settings::Mascot.image_url, + profile_image: SiteConfig.mascot_image_url, confirmed_at: Time.current, registered_at: Time.current, password: SecureRandom.hex @@ -15,10 +15,10 @@ module Users end def call - raise "Mascot already set" if Settings::Mascot.mascot_user_id + raise "Mascot already set" if SiteConfig.mascot_user_id mascot = User.create!(mascot_params) - Settings::Mascot.mascot_user_id = mascot.id + SiteConfig.mascot_user_id = mascot.id end def mascot_params diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index b1f9ad78e..857e48a17 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -739,7 +739,7 @@ <% end %> - <%= form_for(Settings::Mascot.new, url: admin_settings_mascots_path, html: { data: { testid: "mascotSectionForm" } }) do |f| %> + <%= form_for(SiteConfig.new, url: admin_config_path, html: { data: { testid: "mascotSectionForm" } }) do |f| %>
This is where you can manage your posts, but you haven't written anything yet.
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index a85191613..78ac82812 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -25,13 +25,5 @@