Add admin config to always show manually selected users on "Suggested people to follow" list (#10917) [deploy]

* Fix missing spaces in description of suggested_users

* Add config to use suggested_users instead of auto-generated suggestions

* Improve determine_follow_suggestions method

* Update app/lib/constants/site_config.rb

Improve the wording of the description of prefer_manual_suggested_users

Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>

* Apply new style to prefer_manual_suggested_users checkbox

Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
This commit is contained in:
y yam 2020-10-29 02:36:49 +09:00 committed by GitHub
parent 531f26bad6
commit fc22e2c4ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 14 deletions

View file

@ -80,6 +80,7 @@ module Admin
onboarding_taskcard_image
suggested_tags
suggested_users
prefer_manual_suggested_users
].freeze
JOB_PARAMS =

View file

@ -260,6 +260,8 @@ class UsersController < ApplicationController
end
def determine_follow_suggestions(current_user)
return default_suggested_users if SiteConfig.prefer_manual_suggested_users? && default_suggested_users
recent_suggestions = Suggester::Users::Recent.new(
current_user,
attributes_to_select: INDEX_ATTRIBUTES_FOR_SERIALIZATION,

View file

@ -303,11 +303,15 @@ module Constants
placeholder: "List of valid tags: comma separated, letters only e.g. beginners,javascript,ruby,swift,kotlin"
},
suggested_users: {
description: "Determines which users are suggested to follow to new users during onboarding (comma" \
"separated, letters only). Please note that these users will be shown as a fallback if no" \
description: "Determines which users are suggested to follow to new users during onboarding (comma " \
"separated, letters only). Please note that these users will be shown as a fallback if no " \
"recently-active commenters or producers can be suggested",
placeholder: "List of valid usernames: comma separated, letters only e.g. ben,jess,peter,maestromac,andy,liana"
},
prefer_manual_suggested_users: {
description: "Always show suggested users as suggested people to follow even when " \
"auto-suggestion is available"
},
tag_feed_minimum_score: {
description: "Minimum score needed for a post to show up on default tag page.",
placeholder: "0"

View file

@ -132,6 +132,7 @@ class SiteConfig < RailsSettings::Base
field :onboarding_taskcard_image, type: :string
field :suggested_tags, type: :array, default: %w[]
field :suggested_users, type: :array, default: %w[]
field :prefer_manual_suggested_users, type: :boolean, default: false
# Rate limits and spam prevention
field :rate_limit_follow_count_daily, type: :integer, default: 500

View file

@ -1109,6 +1109,16 @@
placeholder: Constants::SiteConfig::DETAILS[:suggested_users][:placeholder] %>
</div>
<div class="crayons-field crayons-field--checkbox">
<%= f.check_box :prefer_manual_suggested_users, checked: SiteConfig.prefer_manual_suggested_users, class: "crayons-checkbox" %>
<div class="mt-0">
<%= admin_config_label :prefer_manual_suggested_users %>
<p class="crayons-field__description">
<%= Constants::SiteConfig::DETAILS[:prefer_manual_suggested_users][:description] %>
</p>
</div>
</div>
<%= render "form_submission", f: f %>
</fieldset>
</div>

View file

@ -474,6 +474,20 @@ RSpec.describe "/admin/config", type: :request do
}
expect(SiteConfig.suggested_users).to eq(%w[piglet tigger eeyore christopherrobin kanga roo])
end
it "updates prefer_manual_suggested_users to true" do
prefer_manual = true
post "/admin/config", params: { site_config: { prefer_manual_suggested_users: prefer_manual },
confirmation: confirmation_message }
expect(SiteConfig.prefer_manual_suggested_users).to eq(prefer_manual)
end
it "updates prefer_manual_suggested_users to false" do
prefer_manual = false
post "/admin/config", params: { site_config: { prefer_manual_suggested_users: prefer_manual },
confirmation: confirmation_message }
expect(SiteConfig.prefer_manual_suggested_users).to eq(prefer_manual)
end
end
describe "Rate Limits and spam" do

View file

@ -39,14 +39,17 @@ RSpec.describe "Users", type: :request do
end
context "when follow_suggestions params are present" do
it "returns follow suggestions for an authenticated user" do
user = create(:user)
tag = create(:tag)
let(:user) { create(:user) }
let(:tag) { create(:tag) }
let(:other_user) { create(:user) }
before do
# Prepare auto-generated user suggestions
user.follow(tag)
other_user = create(:user)
create(:article, user: other_user, tags: [tag.name])
end
it "returns follow suggestions for an authenticated user" do
sign_in user
get users_path(state: "follow_suggestions")
@ -56,13 +59,6 @@ RSpec.describe "Users", type: :request do
end
it "returns follow suggestions that have profile images" do
user = create(:user)
tag = create(:tag)
user.follow(tag)
other_user = create(:user)
create(:article, user: other_user, tags: [tag.name])
sign_in user
get users_path(state: "follow_suggestions")
@ -70,6 +66,24 @@ RSpec.describe "Users", type: :request do
response_user = response.parsed_body.first
expect(response_user["profile_image_url"]).to eq(other_user.profile_image_url)
end
it "returns the default suggested_users from SiteConfig if prefer_manual_suggested_users is true" do
allow(SiteConfig).to receive(:prefer_manual_suggested_users).and_return(true)
sign_in user
get users_path(state: "follow_suggestions")
expect(response).to have_http_status(:ok)
expect(response.parsed_body.first).to include(
"id" => suggested_user.id,
"name" => suggested_user.name,
"username" => suggested_user.username,
"summary" => suggested_user.summary,
"profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
"following" => false,
)
end
end
context "when sidebar_suggestions params are present" do