From c91c07920fe85e1c35496f02bec552ff61a1941b Mon Sep 17 00:00:00 2001 From: Jacob Herrington Date: Tue, 27 Oct 2020 11:45:52 -0500 Subject: [PATCH] Add config option for Forem collective noun (#11107) Not everyone will want to use "Community" to describe their Forem, so now they have some flexibility there. --- app/controllers/admin/configs_controller.rb | 2 ++ app/helpers/application_helper.rb | 4 ++- .../admin/controllers/config_controller.js | 30 ++++++++++++------- app/lib/constants/site_config.rb | 4 +++ app/mailers/devise_mailer.rb | 3 +- app/models/site_config.rb | 2 ++ app/views/admin/configs/show.html.erb | 15 +++++++++- app/views/onboardings/show.html.erb | 2 +- app/views/pages/badge.html.erb | 2 +- .../_bronze_sponsor_copy.html.erb | 4 +-- .../partnerships/_gold_sponsor_copy.html.erb | 2 +- .../_silver_sponsor_copy.html.erb | 2 +- .../partnerships/_tag_sponsor_copy.html.erb | 2 +- spec/helpers/application_helper_spec.rb | 8 ++++- spec/requests/admin/configs_spec.rb | 8 ++++- spec/requests/articles/articles_show_spec.rb | 2 +- spec/requests/service_worker_spec.rb | 2 +- 17 files changed, 69 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb index 0ac8f1ae7..1e2867866 100644 --- a/app/controllers/admin/configs_controller.rb +++ b/app/controllers/admin/configs_controller.rb @@ -14,6 +14,8 @@ module Admin COMMUNITY_PARAMS = %i[ community_name + collective_noun + collective_noun_disabled community_description community_member_label community_copyright_start_year diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c9f02f08e..6bfc13eea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -185,7 +185,9 @@ module ApplicationHelper end def community_qualified_name - "#{community_name} Community" + return "#{community_name} #{SiteConfig.collective_noun}" unless SiteConfig.collective_noun_disabled + + community_name end def release_adjusted_cache_key(path) diff --git a/app/javascript/admin/controllers/config_controller.js b/app/javascript/admin/controllers/config_controller.js index 3242d32f7..d7b3fd304 100644 --- a/app/javascript/admin/controllers/config_controller.js +++ b/app/javascript/admin/controllers/config_controller.js @@ -3,19 +3,27 @@ import { Controller } from 'stimulus'; const recaptchaFields = document.querySelector('#recaptchaContainer'); export default class ConfigController extends Controller { - static targets = ['inviteOnlyMode', 'authenticationProviders', 'requireCaptchaForEmailPasswordRegistration']; + static targets = [ + 'authenticationProviders', + 'collectiveNoun', + 'requireCaptchaForEmailPasswordRegistration', + ]; - disableAuthenticationOptions() { - if (this.inviteOnlyModeTarget.checked) { - this.authenticationProvidersTarget.disabled = true; + disableTargetField(event) { + const targetElementName = event.target.dataset.disableTarget; + const targetElement = this[`${targetElementName}Target`]; + const newValue = event.target.checked; + targetElement.disabled = newValue; + + // Disable the button generated by ERB for select tags + if (targetElement.nodeName === 'SELECT') { + const snakeCaseName = targetElementName.replace( + /[A-Z]/g, + (letter) => `_${letter.toLowerCase()}`, + ); document.querySelector( - 'button[data-id=site_config_authentication_providers]', - ).disabled = true; - } else { - this.authenticationProvidersTarget.disabled = false; - document.querySelector( - 'button[data-id=site_config_authentication_providers]', - ).disabled = false; + `button[data-id=site_config_${snakeCaseName}]`, + ).disabled = newValue; } } diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index 15f44cf15..7aefce1a7 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -49,6 +49,10 @@ module Constants description: "https://url.com/lander", placeholder: "URL campaign sidebar image will link to" }, + collective_noun: { + description: "Used to describe your collective identity.", + placeholder: "Herd" + }, community_copyright_start_year: { description: "Used to mark the year this forem was started.", placeholder: Time.zone.today.year.to_s diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index 3d9b655ff..da1c85e18 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -2,7 +2,8 @@ class DeviseMailer < Devise::Mailer before_action :use_site_config_values def use_site_config_values - Devise.mailer_sender = "#{SiteConfig.community_name} Community <#{SiteConfig.email_addresses[:default]}>" + Devise.mailer_sender = + "#{SiteConfig.community_name} #{SiteConfig.collective_noun} <#{SiteConfig.email_addresses[:default]}>" ActionMailer::Base.default_url_options[:host] = SiteConfig.app_domain end end diff --git a/app/models/site_config.rb b/app/models/site_config.rb index cdd59a392..fca2f407a 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -48,6 +48,8 @@ class SiteConfig < RailsSettings::Base # Community Content field :community_name, type: :string, default: ApplicationConfig["COMMUNITY_NAME"] || "New Forem" + field :collective_noun, type: :string, default: "Community" + field :collective_noun_disabled, type: :boolean, default: false field :community_description, type: :string field :community_member_label, type: :string, default: "user" field :tagline, type: :string diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index 22559633e..f2045b8cb 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -141,7 +141,7 @@
- <%= f.check_box :invite_only_mode, checked: SiteConfig.invite_only_mode, data: { action: "config#disableAuthenticationOptions", target: "config.inviteOnlyMode" }, class: "crayons-checkbox" %> + <%= f.check_box :invite_only_mode, checked: SiteConfig.invite_only_mode, data: { action: "config#disableTargetField", disable_target: "authenticationProviders" }, class: "crayons-checkbox" %>
<%= admin_config_label :invite_only_mode %> <%= admin_config_description Constants::SiteConfig::DETAILS[:invite_only_mode][:description] %> @@ -463,6 +463,19 @@ placeholder: Constants::SiteConfig::DETAILS[:community_name][:placeholder] %>
+
+ <%= admin_config_label :collective_noun %> + <%= admin_config_description Constants::SiteConfig::DETAILS[:collective_noun][:description] %> + <%= f.text_field :collective_noun, + class: "crayons-textfield", + value: SiteConfig.collective_noun, + placeholder: Constants::SiteConfig::DETAILS[:collective_noun][:placeholder], + disabled: SiteConfig.collective_noun_disabled, + data: { target: "config.collectiveNoun" } %> + <%= admin_config_label :collective_noun_disabled %> + <%= f.check_box :collective_noun_disabled, checked: SiteConfig.collective_noun_disabled, data: { action: "config#disableTargetField", disable_target: "collectiveNoun" }, class: "crayons-checkbox" %> +
+
<%= admin_config_label :tagline %> <%= admin_config_description Constants::SiteConfig::DETAILS[:tagline][:description] %> diff --git a/app/views/onboardings/show.html.erb b/app/views/onboardings/show.html.erb index 592eff8e3..1a8010921 100644 --- a/app/views/onboardings/show.html.erb +++ b/app/views/onboardings/show.html.erb @@ -12,7 +12,7 @@
diff --git a/app/views/pages/badge.html.erb b/app/views/pages/badge.html.erb index 8aa3197d4..608a014e7 100644 --- a/app/views/pages/badge.html.erb +++ b/app/views/pages/badge.html.erb @@ -4,7 +4,7 @@ - <%= community_name %> Community ❤️ + <%= community_qualified_name %> ❤️ <%= @html_variant.html.html_safe %> diff --git a/app/views/partnerships/_bronze_sponsor_copy.html.erb b/app/views/partnerships/_bronze_sponsor_copy.html.erb index 2216d49d2..758991b4f 100644 --- a/app/views/partnerships/_bronze_sponsor_copy.html.erb +++ b/app/views/partnerships/_bronze_sponsor_copy.html.erb @@ -1,7 +1,7 @@

Bronze Sponsorship

- Thank you for supporting the <%= community_name %> Community! Here’s what to expect with a Bronze Sponsorship: + Thank you for supporting the <%= community_qualified_name %>! Here’s what to expect with a Bronze Sponsorship:

@@ -20,7 +20,7 @@ 🏆 Special flair on your organization profile page

- As a Bronze sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_name %> Community and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community. + As a Bronze sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_qualified_name %> and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community.

<% if user_signed_in? %>

Bronze sponsorship costs 100 credits/mo ($250 when purchased in bulk)

diff --git a/app/views/partnerships/_gold_sponsor_copy.html.erb b/app/views/partnerships/_gold_sponsor_copy.html.erb index 9d11acc59..d2369e9a1 100644 --- a/app/views/partnerships/_gold_sponsor_copy.html.erb +++ b/app/views/partnerships/_gold_sponsor_copy.html.erb @@ -37,7 +37,7 @@ It will also include a call-to-action to follow your organization directly in th 🏆 Special flair on your organization profile page

-As a Gold sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_name %> Community and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community. +As a Gold sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_qualified_name %> and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community.

<% unless user_signed_in? %>

Email <%= email_link(:business) %> for pricing information

diff --git a/app/views/partnerships/_silver_sponsor_copy.html.erb b/app/views/partnerships/_silver_sponsor_copy.html.erb index c71790312..750e8a39e 100644 --- a/app/views/partnerships/_silver_sponsor_copy.html.erb +++ b/app/views/partnerships/_silver_sponsor_copy.html.erb @@ -19,7 +19,7 @@ 🏆 Special flair on your organization profile page

- As a Silver sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_name %> Community and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community. + As a Silver sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_qualified_name %> and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, you’ll have bragging rights and company pride knowing that you’re supporting a wonderful community.

<% if user_signed_in? %>

Silver sponsorship costs 500 credits/mo ($1,250 when purchased in bulk)

diff --git a/app/views/partnerships/_tag_sponsor_copy.html.erb b/app/views/partnerships/_tag_sponsor_copy.html.erb index dc9d8f715..0946510e0 100644 --- a/app/views/partnerships/_tag_sponsor_copy.html.erb +++ b/app/views/partnerships/_tag_sponsor_copy.html.erb @@ -15,7 +15,7 @@ Target your messaging with a tag sponsorship. This is a great way to increase y Placement on our tag overview page

- Members of the <%= community_name %> Community head to the dedicated tags page to explore new areas of the site, and to manage which tags they follow. Your company will be listed as a sponsor directly alongside the tag you support. This placement provides visibility to all members, even if they don’t directly engage within your tag. + Members of the <%= community_qualified_name %> head to the dedicated tags page to explore new areas of the site, and to manage which tags they follow. Your company will be listed as a sponsor directly alongside the tag you support. This placement provides visibility to all members, even if they don’t directly engage within your tag.

Special flair on your organization profile page diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6049a5d06..187485b31 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -12,7 +12,13 @@ RSpec.describe ApplicationHelper, type: :helper do describe "#community_qualified_name" do it "equals to the full qualified community name" do - expected_name = "#{SiteConfig.community_name} Community" + allow(SiteConfig).to receive(:collective_noun_disabled).and_return(true) + expected_name = SiteConfig.community_name.to_s + expect(helper.community_qualified_name).to eq(expected_name) + + allow(SiteConfig).to receive(:collective_noun).and_return("Flock") + allow(SiteConfig).to receive(:collective_noun_disabled).and_return(false) + expected_name = "#{SiteConfig.community_name} #{SiteConfig.collective_noun}" expect(helper.community_qualified_name).to eq(expected_name) end end diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb index 62537886a..0c1ef70db 100644 --- a/spec/requests/admin/configs_spec.rb +++ b/spec/requests/admin/configs_spec.rb @@ -105,6 +105,13 @@ RSpec.describe "/admin/config", type: :request do expect(SiteConfig.community_name).to eq(name_magoo) end + it "updates the collective_noun" do + collective_noun = "Rhumba" + post "/admin/config", params: { site_config: { collective_noun: collective_noun }, + confirmation: confirmation_message } + expect(SiteConfig.collective_noun).to eq(collective_noun) + end + it "updates the community_member_label" do name = "developer" post "/admin/config", params: { site_config: { community_member_label: name }, @@ -664,7 +671,6 @@ RSpec.describe "/admin/config", type: :request do expect(SiteConfig.home_feed_minimum_score).to eq(home_feed_minimum_score) end - it "updates the brand color if proper hex" do hex = "#0a0a0a" # dark enough post "/admin/config", params: { site_config: { primary_brand_color_hex: hex }, diff --git a/spec/requests/articles/articles_show_spec.rb b/spec/requests/articles/articles_show_spec.rb index b9bc82507..f984129e0 100644 --- a/spec/requests/articles/articles_show_spec.rb +++ b/spec/requests/articles/articles_show_spec.rb @@ -36,7 +36,7 @@ RSpec.describe "ArticlesShow", type: :request do "publisher" => { "@context" => "http://schema.org", "@type" => "Organization", - "name" => "#{SiteConfig.community_name} Community", + "name" => "#{SiteConfig.community_name} #{SiteConfig.collective_noun}", "logo" => { "@context" => "http://schema.org", "@type" => "ImageObject", diff --git a/spec/requests/service_worker_spec.rb b/spec/requests/service_worker_spec.rb index edb116a35..91ef097b4 100644 --- a/spec/requests/service_worker_spec.rb +++ b/spec/requests/service_worker_spec.rb @@ -21,7 +21,7 @@ RSpec.describe "ServiceWorker", type: :request do describe "GET /manifest.json" do it "renders file with proper text" do get "/manifest.json" - expect(response.body).to include("\"name\": \"#{SiteConfig.community_name} Community\"") + expect(response.body).to include("\"name\": \"#{SiteConfig.community_name} #{SiteConfig.collective_noun}\"") end it "renders json file" do