diff --git a/app/controllers/admin/settings/communities_controller.rb b/app/controllers/admin/settings/communities_controller.rb
new file mode 100644
index 000000000..3a9ae4e5f
--- /dev/null
+++ b/app/controllers/admin/settings/communities_controller.rb
@@ -0,0 +1,36 @@
+module Admin
+ module Settings
+ class CommunitiesController < 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
+
+ private
+
+ def settings_params
+ params
+ .require(:settings_community)
+ .permit(*::Settings::Community.keys)
+ end
+
+ def upsert_config(configs)
+ errors = []
+ configs.each do |key, value|
+ ::Settings::Community.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/concerns/verify_setup_completed.rb b/app/controllers/concerns/verify_setup_completed.rb
index a672135c8..001a92500 100644
--- a/app/controllers/concerns/verify_setup_completed.rb
+++ b/app/controllers/concerns/verify_setup_completed.rb
@@ -4,13 +4,13 @@ module VerifySetupCompleted
module_function
- MANDATORY_CONFIGS = %i[
- community_name
- community_description
+ MANDATORY_CONFIGS = {
+ community_name: Settings::Community,
+ community_description: Settings::Community,
- suggested_tags
- suggested_users
- ].freeze
+ suggested_tags: SiteConfig,
+ suggested_users: SiteConfig
+ }.freeze
included do
# rubocop:disable Rails/LexicallyScopedActionFilter
@@ -23,7 +23,9 @@ module VerifySetupCompleted
end
def missing_configs
- @missing_configs ||= MANDATORY_CONFIGS.reject { |config| SiteConfig.public_send(config).present? }
+ @missing_configs ||= MANDATORY_CONFIGS.reject do |config, settings_model|
+ settings_model.public_send(config).present?
+ end.keys
end
private
diff --git a/app/controllers/email_subscriptions_controller.rb b/app/controllers/email_subscriptions_controller.rb
index cd522e744..6286acaf7 100644
--- a/app/controllers/email_subscriptions_controller.rb
+++ b/app/controllers/email_subscriptions_controller.rb
@@ -15,11 +15,11 @@ class EmailSubscriptionsController < ApplicationController
def preferred_email_name
{
- email_digest_periodic: "#{SiteConfig.community_name} digest emails",
+ email_digest_periodic: "#{Settings::Community.community_name} digest emails",
email_comment_notifications: "comment notifications",
email_follower_notifications: "follower notifications",
email_mention_notifications: "mention notifications",
- email_connect_messages: "#{SiteConfig.community_name} connect messages",
+ email_connect_messages: "#{Settings::Community.community_name} connect messages",
email_unread_notifications: "unread notifications",
email_badge_notifications: "badge notifications"
}.freeze
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index e43dc590b..d5c7fb189 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -122,6 +122,7 @@ class SearchController < ApplicationController
# TODO: [@rhymes] the homepage feed uses `feed_content_search` as an index,
# we should eventually move it to a JSON result
# in ArticlesController#Homepage or HomepageController#show
+ # rubocop:disable Metric/PerceivedComplexity
def feed_content
class_name = feed_params[:class_name].to_s.inquiry
@@ -176,6 +177,7 @@ class SearchController < ApplicationController
render json: { result: result }
end
+ # rubocop:enable Metric/PerceivedComplexity
def reactions
if FeatureFlag.enabled?(:search_2_reading_list)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3855c64a5..e585af343 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -168,11 +168,11 @@ module ApplicationHelper
end
def community_name
- @community_name ||= SiteConfig.community_name
+ @community_name ||= Settings::Community.community_name
end
def community_emoji
- @community_emoji ||= SiteConfig.community_emoji
+ @community_emoji ||= Settings::Community.community_emoji
end
def release_adjusted_cache_key(path)
@@ -183,7 +183,7 @@ module ApplicationHelper
end
def copyright_notice
- start_year = SiteConfig.community_copyright_start_year.to_s
+ start_year = Settings::Community.copyright_start_year.to_s
current_year = Time.current.year.to_s
return start_year if current_year == start_year
return current_year if start_year.strip.length < 4 # 978 is not a valid year!
@@ -206,7 +206,7 @@ module ApplicationHelper
end
def community_members_label
- SiteConfig.community_member_label.pluralize
+ Settings::Community.member_label.pluralize
end
def meta_keywords_default
diff --git a/app/helpers/feedback_messages_helper.rb b/app/helpers/feedback_messages_helper.rb
index 3177557e1..d70720286 100644
--- a/app/helpers/feedback_messages_helper.rb
+++ b/app/helpers/feedback_messages_helper.rb
@@ -2,44 +2,44 @@ module FeedbackMessagesHelper
OFFENDER_EMAIL_BODY = <<~HEREDOC.freeze
Hello,
- It has been brought to our attention that you have violated the #{SiteConfig.community_name} Code of Conduct and/or Terms of Use.
+ It has been brought to our attention that you have violated the #{Settings::Community.community_name} Code of Conduct and/or Terms of Use.
- If this behavior continues, we may need to suspend your #{SiteConfig.community_name} account.
+ If this behavior continues, we may need to suspend your #{Settings::Community.community_name} account.
If you think that there's been a mistake, please reply to this email and we will take another look.
- #{SiteConfig.community_name} Team
+ #{Settings::Community.community_name} Team
HEREDOC
REPORTER_EMAIL_BODY = <<~HEREDOC.freeze
Hi there,
- Thank you for flagging content that may be in violation of the #{SiteConfig.community_name} Code of Conduct and/or our Terms of Use. We are looking into your report and will take appropriate action.
+ Thank you for flagging content that may be in violation of the #{Settings::Community.community_name} Code of Conduct and/or our Terms of Use. We are looking into your report and will take appropriate action.
We appreciate your help as we work to foster a positive and inclusive environment for all!
- #{SiteConfig.community_name} Team
+ #{Settings::Community.community_name} Team
HEREDOC
AFFECTED_EMAIL_BODY = <<~HEREDOC.freeze
Hi there,
- We noticed some comments (made by others) on your post that violate the #{SiteConfig.community_name} Code of Conduct and/or our Terms of Use. We have zero tolerance for such behavior and are taking appropriate action.
+ We noticed some comments (made by others) on your post that violate the #{Settings::Community.community_name} Code of Conduct and/or our Terms of Use. We have zero tolerance for such behavior and are taking appropriate action.
Thanks for being awesome, and please don't hesitate to email us with any questions! We welcome all feedback and ideas as we continue working to foster an open and inclusive community.
- #{SiteConfig.community_name} Team
+ #{Settings::Community.community_name} Team
HEREDOC
def offender_email_details
body = format(OFFENDER_EMAIL_BODY)
- { subject: "#{SiteConfig.community_name} Code of Conduct Violation", body: body }.freeze
+ { subject: "#{Settings::Community.community_name} Code of Conduct Violation", body: body }.freeze
end
def reporter_email_details
body = format(REPORTER_EMAIL_BODY)
- { subject: "#{SiteConfig.community_name} Report", body: body }.freeze
+ { subject: "#{Settings::Community.community_name} Report", body: body }.freeze
end
def affected_email_details
body = format(AFFECTED_EMAIL_BODY)
- { subject: "Courtesy Notice from #{SiteConfig.community_name}", body: body }.freeze
+ { subject: "Courtesy Notice from #{Settings::Community.community_name}", body: body }.freeze
end
end
diff --git a/app/lib/constants/settings/community.rb b/app/lib/constants/settings/community.rb
new file mode 100644
index 000000000..54751f25b
--- /dev/null
+++ b/app/lib/constants/settings/community.rb
@@ -0,0 +1,36 @@
+module Constants
+ module Settings
+ module Community
+ DETAILS = {
+ community_description: {
+ description: "Used in meta description tags etc.",
+ placeholder: "A fabulous community of kind and welcoming people."
+ },
+ community_emoji: {
+ description: "Used in the title tags across the site alongside the community name",
+ placeholder: ""
+ },
+ community_name: {
+ description: "Used as the primary name for your Forem, e.g. DEV, DEV Community, The DEV Community, etc.",
+ placeholder: "New Forem"
+ },
+ copyright_start_year: {
+ description: "Used to mark the year this forem was started.",
+ placeholder: Time.zone.today.year.to_s
+ },
+ member_label: {
+ description: "Used to determine what a member will be called e.g developer, hobbyist etc.",
+ placeholder: "user"
+ },
+ staff_user_id: {
+ description: "Account ID which acts as automated 'staff'— used principally for welcome thread.",
+ placeholder: ""
+ },
+ tagline: {
+ description: "Used in signup modal.",
+ placeholder: "We're a place where coders share, stay up-to-date and grow their careers."
+ }
+ }.freeze
+ end
+ end
+end
diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb
index b2bdd4c4a..65a82807c 100644
--- a/app/lib/constants/site_config.rb
+++ b/app/lib/constants/site_config.rb
@@ -4,26 +4,6 @@ module Constants
SVG_PLACEHOLDER = "".freeze
DETAILS = {
- community_copyright_start_year: {
- description: "Used to mark the year this forem was started.",
- placeholder: Time.zone.today.year.to_s
- },
- community_description: {
- description: "Used in meta description tags etc.",
- placeholder: "A fabulous community of kind and welcoming people."
- },
- community_emoji: {
- description: "Used in the title tags across the site alongside the community name",
- placeholder: ""
- },
- community_member_label: {
- description: "Used to determine what a member will be called e.g developer, hobbyist etc.",
- placeholder: "user"
- },
- community_name: {
- description: "Used as the primary name for your Forem, e.g. DEV, DEV Community, The DEV Community, etc.",
- placeholder: "New Forem"
- },
credit_prices_in_cents: {
small: {
description: "Price for small credit purchase (<10 credits).",
@@ -49,14 +29,6 @@ module Constants
description: "Email address",
placeholder: ""
},
- experience_low: {
- description: "The label for the bottom of the experience level range of a post",
- placeholder: "Total Newbies"
- },
- experience_high: {
- description: "The label for the top of the experience level range of a post",
- placeholder: "Senior Devs"
- },
favicon_url: {
description: "Used as the site favicon",
placeholder: IMAGE_PLACEHOLDER
@@ -151,10 +123,6 @@ module Constants
description: "Determines the heading text of the main sponsors sidebar above the list of sponsors.",
placeholder: "Community Sponsors"
},
- staff_user_id: {
- description: "Account ID which acts as automated 'staff'— used principally for welcome thread.",
- placeholder: ""
- },
stripe_api_key: {
description: "Secret Stripe key for receiving payments. " \
"See: https://stripe.com/docs/keys",
@@ -184,10 +152,6 @@ module Constants
description: "Minimum score needed for a post to show up on default tag page.",
placeholder: "0"
},
- tagline: {
- description: "Used in signup modal.",
- placeholder: "We're a place where coders share, stay up-to-date and grow their careers."
- },
twitter_hashtag: {
description: "Used as the twitter hashtag of the community",
placeholder: "#DEVCommunity"
diff --git a/app/liquid_tags/reddit_tag.rb b/app/liquid_tags/reddit_tag.rb
index 209948cc5..5b0ff4be9 100644
--- a/app/liquid_tags/reddit_tag.rb
+++ b/app/liquid_tags/reddit_tag.rb
@@ -34,7 +34,7 @@ class RedditTag < LiquidTagBase
# Requests to Reddit require a custom `User-Agent` header to prevent 429 errors
json = HTTParty.get("#{@url}.json",
- headers: { "User-Agent" => "#{SiteConfig.community_name} (#{URL.url})" })
+ headers: { "User-Agent" => "#{Settings::Community.community_name} (#{URL.url})" })
# The JSON response is an array with two items.
# The first one is the post itself, the second one are the comments
diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb
index d181c59ad..32ab8a333 100644
--- a/app/mailers/digest_mailer.rb
+++ b/app/mailers/digest_mailer.rb
@@ -26,7 +26,7 @@ class DigestMailer < ApplicationMailer
end
def email_end_phrase
- community_name = SiteConfig.community_name
+ community_name = Settings::Community.community_name
# "more trending posts" won the previous split test
# Included more often as per explore-exploit algorithm
[
diff --git a/app/mailers/notify_mailer.rb b/app/mailers/notify_mailer.rb
index ac2293b13..2a62c3681 100644
--- a/app/mailers/notify_mailer.rb
+++ b/app/mailers/notify_mailer.rb
@@ -46,7 +46,7 @@ class NotifyMailer < ApplicationMailer
@unread_notifications_count = @user.notifications.unread.count
@unsubscribe = generate_unsubscribe_token(@user.id, :email_unread_notifications)
- subject = "🔥 You have #{@unread_notifications_count} unread notifications on #{SiteConfig.community_name}"
+ subject = "🔥 You have #{@unread_notifications_count} unread notifications on #{Settings::Community.community_name}"
mail(to: @user.email, subject: subject)
end
@@ -66,7 +66,7 @@ class NotifyMailer < ApplicationMailer
end
def feedback_response_email
- mail(to: params[:email_to], subject: "Thanks for your report on #{SiteConfig.community_name}")
+ mail(to: params[:email_to], subject: "Thanks for your report on #{Settings::Community.community_name}")
end
def feedback_message_resolution_email
@@ -108,7 +108,7 @@ class NotifyMailer < ApplicationMailer
def account_deleted_email
@name = params[:name]
- subject = "#{SiteConfig.community_name} - Account Deletion Confirmation"
+ subject = "#{Settings::Community.community_name} - Account Deletion Confirmation"
mail(to: params[:email], subject: subject)
end
@@ -125,7 +125,7 @@ class NotifyMailer < ApplicationMailer
@name = user.name
@token = params[:token]
- subject = "#{SiteConfig.community_name} - Account Deletion Requested"
+ subject = "#{Settings::Community.community_name} - Account Deletion Requested"
mail(to: user.email, subject: subject)
end
@@ -149,13 +149,13 @@ class NotifyMailer < ApplicationMailer
def trusted_role_email
@user = params[:user]
- subject = "Congrats! You're now a \"trusted\" user on #{SiteConfig.community_name}!"
+ subject = "Congrats! You're now a \"trusted\" user on #{Settings::Community.community_name}!"
mail(to: @user.email, subject: subject)
end
def subjects
{
- new_follower_email: "just followed you on #{SiteConfig.community_name}".freeze
+ new_follower_email: "just followed you on #{Settings::Community.community_name}".freeze
}.freeze
end
end
diff --git a/app/mailers/verification_mailer.rb b/app/mailers/verification_mailer.rb
index 793ba01a5..644549122 100644
--- a/app/mailers/verification_mailer.rb
+++ b/app/mailers/verification_mailer.rb
@@ -1,6 +1,6 @@
class VerificationMailer < ApplicationMailer
default from: lambda {
- "#{SiteConfig.community_name} Email Verification <#{SiteConfig.email_addresses[:default]}>"
+ "#{Settings::Community.community_name} Email Verification <#{SiteConfig.email_addresses[:default]}>"
}
def account_ownership_verification_email
@@ -8,6 +8,6 @@ class VerificationMailer < ApplicationMailer
email_authorization = EmailAuthorization.create!(user: @user, type_of: "account_ownership")
@confirmation_token = email_authorization.confirmation_token
- mail(to: @user.email, subject: "Verify Your #{SiteConfig.community_name} Account Ownership")
+ mail(to: @user.email, subject: "Verify Your #{Settings::Community.community_name} Account Ownership")
end
end
diff --git a/app/models/article.rb b/app/models/article.rb
index e1059c896..68b2c1bb5 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -181,7 +181,8 @@ class Article < ApplicationRecord
published
.where(user_id: User.with_role(:super_admin)
.union(User.with_role(:admin))
- .union(id: [SiteConfig.staff_user_id, Settings::Mascot.mascot_user_id].compact)
+ .union(id: [Settings::Community.staff_user_id,
+ Settings::Mascot.mascot_user_id].compact)
.select(:id)).order(published_at: :desc).tagged_with(tag_name)
}
diff --git a/app/models/settings/community.rb b/app/models/settings/community.rb
new file mode 100644
index 000000000..50edeeb05
--- /dev/null
+++ b/app/models/settings/community.rb
@@ -0,0 +1,19 @@
+module Settings
+ class Community < RailsSettings::Base
+ self.table_name = :settings_communities
+
+ # The configuration is cached, change this if you want to force update
+ # the cache, or call Settings::Community.clear_cache
+ cache_prefix { "v1" }
+
+ field :copyright_start_year,
+ type: :integer,
+ default: ApplicationConfig["COMMUNITY_COPYRIGHT_START_YEAR"] || Time.zone.today.year
+ field :community_description, type: :string
+ field :community_emoji, type: :string, default: "🌱", validates: { emoji_only: true }
+ field :community_name, type: :string, default: ApplicationConfig["COMMUNITY_NAME"] || "New Forem"
+ field :member_label, type: :string, default: "user"
+ field :staff_user_id, type: :integer, default: 1
+ field :tagline, type: :string
+ end
+end
diff --git a/app/models/site_config.rb b/app/models/site_config.rb
index cfe34fcf3..1b0f6c41d 100644
--- a/app/models/site_config.rb
+++ b/app/models/site_config.rb
@@ -48,6 +48,8 @@ class SiteConfig < RailsSettings::Base
field :campaign_articles_require_approval, type: :boolean, default: 0
field :campaign_articles_expiry_time, type: :integer, default: 4
# Community Content
+ # NOTE: @citizen428 All these settings will be removed once we full migrated
+ # to Settings::Community across the fleet.
field :community_name, type: :string, default: ApplicationConfig["COMMUNITY_NAME"] || "New Forem"
field :community_emoji, type: :string, default: "🌱", validates: { emoji_only: true }
# collective_noun and collective_noun_disabled have been added back temporarily for
diff --git a/app/models/user.rb b/app/models/user.rb
index 365a56cda..f349fa2d4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -308,7 +308,7 @@ class User < ApplicationRecord
after_commit :remove_from_elasticsearch, on: [:destroy]
def self.dev_account
- find_by(id: SiteConfig.staff_user_id)
+ find_by(id: Settings::Community.staff_user_id)
end
def self.mascot_account
diff --git a/app/services/badges/award_yearly_club.rb b/app/services/badges/award_yearly_club.rb
index caa394b33..e78584aea 100644
--- a/app/services/badges/award_yearly_club.rb
+++ b/app/services/badges/award_yearly_club.rb
@@ -11,7 +11,7 @@ module Badges
}.freeze
MESSAGE_TEMPLATE =
- "Happy #{SiteConfig.community_name} birthday! " \
+ "Happy #{Settings::Community.community_name} birthday! " \
"Can you believe it's been %d %s already?!".freeze
def self.call
@@ -19,7 +19,7 @@ module Badges
end
def call
- total_years = Time.current.year - SiteConfig.community_copyright_start_year.to_i
+ total_years = Time.current.year - Settings::Community.copyright_start_year.to_i
(1..total_years).each do |i|
::Badges::Award.call(
User.registered.where(created_at: i.year.ago - 2.days...i.year.ago),
diff --git a/app/services/edge_cache/bust_article.rb b/app/services/edge_cache/bust_article.rb
index 0de88a3c5..3199ffa2e 100644
--- a/app/services/edge_cache/bust_article.rb
+++ b/app/services/edge_cache/bust_article.rb
@@ -22,7 +22,7 @@ module EdgeCache
bust_tag_pages(cache_bust, article)
end
- def self.paths_for(article)
+ def self.paths_for(article, &block)
paths = [
article.path,
"/#{article.user.username}",
@@ -35,9 +35,7 @@ module EdgeCache
"/api/articles/#{article.id}",
]
- paths.each do |path|
- yield path
- end
+ paths.each(&block)
yield "/#{article.organization.slug}" if article.organization.present?
diff --git a/app/services/settings/upsert.rb b/app/services/settings/upsert.rb
index 7cc6526af..3ead117c8 100644
--- a/app/services/settings/upsert.rb
+++ b/app/services/settings/upsert.rb
@@ -1,6 +1,5 @@
module Settings
class Upsert
- EMOJI_ONLY_FIELDS = %w[community_emoji].freeze
VALID_DOMAIN = /^[a-zA-Z0-9]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/.freeze
PARAMS_TO_BE_CLEANED = %i[sidebar_tags suggested_tags suggested_users].freeze
diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb
index b44ca5049..97b91daa9 100644
--- a/app/views/admin/configs/show.html.erb
+++ b/app/views/admin/configs/show.html.erb
@@ -36,41 +36,42 @@
<%= form_for(SiteConfig.new, url: admin_config_path) do |f| %>