From f4a10e4a4474a547913235d110f5d2b30371c294 Mon Sep 17 00:00:00 2001 From: Alexis Moody Date: Fri, 16 Oct 2020 14:40:25 -0400 Subject: [PATCH] [deploy] Adds a new admin setting for experience levels. (#10870) * Adds a new admin setting for experience levels. This is used in the post management UI to determine the range of experience. These values fallback to the ones we currently see in DEV, Total Newbies and Senior Devs. There is also a removal of the word coding when talking about experience level, since the context for each forem instance should be implied when referencing experience. * Cleans up experience defaults * Fixes instance_of usage --- app/controllers/admin/configs_controller.rb | 2 ++ app/controllers/organizations_controller.rb | 2 +- app/lib/constants/site_config.rb | 8 +++++++ app/models/site_config.rb | 2 ++ app/views/admin/configs/show.html.erb | 17 ++++++++++++++ app/views/articles/manage.html.erb | 22 +++++++++---------- app/views/events/index.html.erb | 1 - .../notify_mailer/trusted_role_email.html.erb | 2 +- app/views/users/_ux.html.erb | 2 +- docs/backend/auth-facebook.md | 4 ++-- docs/backend/auth-github.md | 4 ++-- docs/backend/auth-twitter.md | 8 +++---- docs/installation/containers.md | 4 ++-- docs/installation/linux.md | 4 ++-- docs/installation/mac.md | 4 ++-- docs/installation/windows.md | 4 ++-- spec/requests/admin/configs_spec.rb | 14 ++++++++++++ 17 files changed, 73 insertions(+), 31 deletions(-) diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb index bd8e64f29..a650d1179 100644 --- a/app/controllers/admin/configs_controller.rb +++ b/app/controllers/admin/configs_controller.rb @@ -18,6 +18,8 @@ module Admin community_copyright_start_year staff_user_id tagline + experience_low + experience_high ].freeze NEWSLETTER_PARAMS = diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index daf07666a..7b9b403ac 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -106,7 +106,7 @@ class OrganizationsController < ApplicationController def organization_params params.require(:organization).permit(permitted_params) .transform_values do |value| - if value.class.name == "String" + if value.instance_of?(String) ActionController::Base.helpers.strip_tags(value) else value diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index d711a42fe..43d6614ad 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -83,6 +83,14 @@ 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" + }, facebook_key: { description: "The \"App ID\" portion of the Basic Settings section of the App page on the Facebook Developer Portal", diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 797180054..bb96d7725 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -50,6 +50,8 @@ class SiteConfig < RailsSettings::Base default: ApplicationConfig["COMMUNITY_COPYRIGHT_START_YEAR"] || Time.zone.today.year field :staff_user_id, type: :integer, default: 1 + field :experience_low, type: :string, default: "Total Newbies" + field :experience_high, type: :string, default: "Experienced Users" # Emails field :email_addresses, type: :hash, default: { diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index 05659cd36..c2900f573 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -456,6 +456,23 @@
<%= Constants::SiteConfig::DETAILS[:staff_user_id][:description] %>
+
+ <%= admin_config_label :experience_low %> + <%= f.text_field :experience_low, + class: "form-control", + value: SiteConfig.experience_low, + placeholder: Constants::SiteConfig::DETAILS[:experience_low][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:experience_low][:description] %>
+
+ +
+ <%= admin_config_label :experience_high %> + <%= f.text_field :experience_high, + class: "form-control", + value: SiteConfig.experience_high, + placeholder: Constants::SiteConfig::DETAILS[:experience_high][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:experience_high][:description] %>
+
<%= render "form_submission", f: f %> diff --git a/app/views/articles/manage.html.erb b/app/views/articles/manage.html.erb index 460b5565b..743c43545 100644 --- a/app/views/articles/manage.html.erb +++ b/app/views/articles/manage.html.erb @@ -51,23 +51,23 @@ <%= f.hidden_field :article_id, value: @article.id %> <%= f.hidden_field :group, value: "experience_level" %> - - - + + + - - - - + + + + - - - + + +

Who is this post most relevant for?

-

👈 Total NewbiesSenior Devs 👉

+

👈 <%= SiteConfig.experience_low %><%= SiteConfig.experience_high %> 👉

<% end %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index cb932caa7..0ef94ee0c 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -16,7 +16,6 @@ -

diff --git a/app/views/mailers/notify_mailer/trusted_role_email.html.erb b/app/views/mailers/notify_mailer/trusted_role_email.html.erb index 90dfd8faf..a494f597e 100644 --- a/app/views/mailers/notify_mailer/trusted_role_email.html.erb +++ b/app/views/mailers/notify_mailer/trusted_role_email.html.erb @@ -5,7 +5,7 @@ We are happy to let you know that your <%= community_name %> account has just been upgraded to "trusted" status.

- This gives you the power to privately downvote content which is low quality or spam and harassment, alongside a bit of additional functionality to help ensure the success of the community. Anywhere you now see a shield on the site indicates a place you can go to join our community's crowd-sourced moderation initiative. + This gives you the power to privately downvote content which is low quality or spam and harassment, alongside a bit of additional functionality to help ensure the success of the community. Anywhere you now see a shield on the site indicates a place you can go to join our community's crowd-sourced moderation initiative.

You may occasionally receive notifications about optional moderation actions, but you can unsubscribe if you do not want to receive these notices. diff --git a/app/views/users/_ux.html.erb b/app/views/users/_ux.html.erb index ba1202d1b..8a3f6d364 100644 --- a/app/views/users/_ux.html.erb +++ b/app/views/users/_ux.html.erb @@ -47,7 +47,7 @@

Content Customization

- <%= f.label :experience_level, "What is your approximate coding experience level (1-5)?", class: "crayons-field__label" %> + <%= f.label :experience_level, "What is your approximate experience level (1-5)?", class: "crayons-field__label" %>
<% user_experience_levels.each_with_index do |exp, i| %> <%= render partial: "experience_selector", locals: { f: f, exp: exp, i: i, label: user_experience_labels } %> diff --git a/docs/backend/auth-facebook.md b/docs/backend/auth-facebook.md index 60ec88905..f9b7d2fcc 100644 --- a/docs/backend/auth-facebook.md +++ b/docs/backend/auth-facebook.md @@ -44,8 +44,8 @@ application. ![facebook-5](https://user-images.githubusercontent.com/37842/90913319-b5f20b80-e3a1-11ea-866a-0b06cf3296c7.png) 7. From the basic settings screen dashboard copy the **App ID** and **App - Secret** values to your `.env` file accordingly (name of Facebook - key -> name of our `SiteConfig` variable). + Secret** values to your `.env` file accordingly (name of Facebook key -> name + of our `SiteConfig` variable). ```text APP ID -> FACEBOOK_APP_ID diff --git a/docs/backend/auth-github.md b/docs/backend/auth-github.md index 78221a8ce..ac9e4462e 100644 --- a/docs/backend/auth-github.md +++ b/docs/backend/auth-github.md @@ -18,8 +18,8 @@ keys. Then you'll need to provide these keys to the Rails application. ![github-1](https://user-images.githubusercontent.com/22895284/51085500-877a6c00-173a-11e9-913a-0dccad234cf3.png) 3. You will be redirected to the app's **Developer settings**. Here you will - find the keys. Add them to your `.env` file accordingly (name of GitHub key -> name of our - `ENV` variable): + find the keys. Add them to your `.env` file accordingly (name of GitHub key + -> name of our `ENV` variable): ```text Client ID -> GITHUB_KEY diff --git a/docs/backend/auth-twitter.md b/docs/backend/auth-twitter.md index 62bf9007d..89f71e54a 100644 --- a/docs/backend/auth-twitter.md +++ b/docs/backend/auth-twitter.md @@ -84,10 +84,10 @@ application. ![twitter-7](https://user-images.githubusercontent.com/22895284/51078803-9a9a2700-16bb-11e9-8f27-dbfe04b52031.png) -10. From the same dashboard access the **Keys and tokens** and add them to your `.env` file accordingly - (name of Twitter key -> name of our `ENV` variable). Be sure to - copy the _access token_ and _access token secret_ right away because it will - be hidden from you in the future. +10. From the same dashboard access the **Keys and tokens** and add them to your + `.env` file accordingly (name of Twitter key -> name of our `ENV` variable). + Be sure to copy the _access token_ and _access token secret_ right away + because it will be hidden from you in the future. ```text API key -> TWITTER_KEY diff --git a/docs/installation/containers.md b/docs/installation/containers.md index cd5cabcf4..934dde6d0 100644 --- a/docs/installation/containers.md +++ b/docs/installation/containers.md @@ -61,8 +61,8 @@ with Podman. You can install it by following these `git clone https://github.com//forem.git` 1. Set up your environment variables/secrets - - Take a look at `.env_sample`. This file lists all the `ENV` variables we use - and provides a fake default for any missing keys. + - Take a look at `.env_sample`. This file lists all the `ENV` variables we + use and provides a fake default for any missing keys. - The [backend guide](/backend) will show you how to get free API keys for additional services that may be required to run certain parts of the app. - For any key that you wish to enter/replace: diff --git a/docs/installation/linux.md b/docs/installation/linux.md index b42697fc4..e15895f3b 100644 --- a/docs/installation/linux.md +++ b/docs/installation/linux.md @@ -89,8 +89,8 @@ NOTE: Make sure to download **the OSS version**, `elasticsearch-oss`. 1. Install bundler with `gem install bundler` 1. Set up your environment variables/secrets - - Take a look at `.env_sample`. This file lists all the `ENV` variables we use - and provides a fake default for any missing keys. + - Take a look at `.env_sample`. This file lists all the `ENV` variables we + use and provides a fake default for any missing keys. - If you use a remote computer as dev env, you need to set `APP_DOMAIN` variable to the remote computer's domain name. - The [backend guide](/backend) will show you how to get free API keys for diff --git a/docs/installation/mac.md b/docs/installation/mac.md index c1d59c05f..84f3a434b 100644 --- a/docs/installation/mac.md +++ b/docs/installation/mac.md @@ -209,8 +209,8 @@ your local Elasticsearch installation, for example: 3. Install bundler with `gem install bundler` 4. Set up your environment variables/secrets - - Take a look at `.env_sample` to see all the `ENV` variables we use and the fake - default provided for any missing keys. + - Take a look at `.env_sample` to see all the `ENV` variables we use and the + fake default provided for any missing keys. - If you use a remote computer as dev env, you need to set `APP_DOMAIN` variable to the remote computer's domain name. - The [backend guide](/backend) will show you how to get free API keys for diff --git a/docs/installation/windows.md b/docs/installation/windows.md index 34965588e..7f062c4b3 100644 --- a/docs/installation/windows.md +++ b/docs/installation/windows.md @@ -256,8 +256,8 @@ To install Elasticsearch perform the following steps: 1. Install bundler with `gem install bundler` 1. Set up your environment variables/secrets - - Take a look at `.env_sample`. This file lists all the `ENV` variables we use - and provides a fake default for any missing keys. + - Take a look at `.env_sample`. This file lists all the `ENV` variables we + use and provides a fake default for any missing keys. - If you use a remote computer as dev env, you need to set `APP_DOMAIN` variable to the remote computer's domain name. - The [backend guide](/backend) will show you how to get free API keys for diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb index 411c93e7d..c246be51e 100644 --- a/spec/requests/admin/configs_spec.rb +++ b/spec/requests/admin/configs_spec.rb @@ -141,6 +141,20 @@ RSpec.describe "/admin/config", type: :request do post "/admin/config", params: { site_config: { staff_user_id: 22 }, confirmation: confirmation_message } expect(SiteConfig.staff_user_id).to eq(22) end + + it "updates the experience_low" do + experience_low = "Noobs" + post "/admin/config", params: { site_config: { experience_low: experience_low }, + confirmation: confirmation_message } + expect(SiteConfig.experience_low).to eq(experience_low) + end + + it "updates the experience_high" do + experience_high = "Advanced Peeps" + post "/admin/config", params: { site_config: { experience_high: experience_high }, + confirmation: confirmation_message } + expect(SiteConfig.experience_high).to eq(experience_high) + end end describe "Emails" do