Add suggested tags to SiteConfig (#5426) [deploy]
* Initial base work * Add suggested tags config * Downcase suggested tag input
This commit is contained in:
parent
1cea7a1ef1
commit
f78b89e763
7 changed files with 50 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ module Api
|
|||
caches_action :index,
|
||||
cache_path: proc { |c| c.params.permit! },
|
||||
expires_in: 10.minutes
|
||||
before_action :set_cache_control_headers, only: %i[onboarding] # essentially static content
|
||||
respond_to :json
|
||||
|
||||
def index
|
||||
|
|
@ -12,7 +13,8 @@ module Api
|
|||
end
|
||||
|
||||
def onboarding
|
||||
@tags = Tag.where(name: Tag::NAMES)
|
||||
set_surrogate_key_header "siteconfig/onboarding-tags"
|
||||
@tags = Tag.where(name: SiteConfig.suggested_tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ class Internal::ConfigsController < Internal::ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
clean_up_params
|
||||
config_params.keys.each do |key|
|
||||
SiteConfig.public_send("#{key}=", config_params[key].strip) unless config_params[key].nil?
|
||||
end
|
||||
bust_relevant_caches
|
||||
redirect_to internal_config_path, notice: "Site configuration was successfully updated."
|
||||
end
|
||||
|
||||
|
|
@ -22,8 +24,17 @@ class Internal::ConfigsController < Internal::ApplicationController
|
|||
ga_view_id ga_fetch_rate
|
||||
mailchimp_newsletter_id mailchimp_sustaining_members_id
|
||||
mailchimp_tag_moderators_id mailchimp_community_moderators_id
|
||||
periodic_email_digest_max periodic_email_digest_min
|
||||
periodic_email_digest_max periodic_email_digest_min suggested_tags
|
||||
]
|
||||
params.require(:site_config).permit(allowed_params)
|
||||
end
|
||||
|
||||
def clean_up_params
|
||||
config = params[:site_config]
|
||||
config[:suggested_tags] = config[:suggested_tags].downcase.delete(" ") if config[:suggested_tags]
|
||||
end
|
||||
|
||||
def bust_relevant_caches
|
||||
CacheBuster.bust("/api/tags/onboarding") # Needs to change when suggested_tags is edited
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,4 +36,7 @@ class SiteConfig < RailsSettings::Base
|
|||
# Email digest frequency
|
||||
field :periodic_email_digest_max, type: :integer, default: 0
|
||||
field :periodic_email_digest_min, type: :integer, default: 2
|
||||
|
||||
# Tags
|
||||
field :suggested_tags, type: :array, default: %w[beginners career computerscience javascript security ruby rails swift kotlin]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,14 +5,6 @@ class Tag < ActsAsTaggableOn::Tag
|
|||
acts_as_followable
|
||||
resourcify
|
||||
|
||||
NAMES = %w[
|
||||
beginners career computerscience git go java javascript react vue webassembly
|
||||
linux productivity python security webdev css php laravel opensource npm a11y
|
||||
ruby cpp dotnet swift testing devops vim kotlin rust elixir graphql blockchain sre
|
||||
scala vscode docker kubernetes aws android ios angular csharp typescript django rails
|
||||
clojure ubuntu elm gamedev flutter dart bash machinelearning sql
|
||||
].freeze
|
||||
|
||||
ALLOWED_CATEGORIES = %w[uncategorized language library tool site_mechanic location subcommunity].freeze
|
||||
|
||||
attr_accessor :tag_moderator_id, :remove_moderator_id
|
||||
|
|
|
|||
|
|
@ -174,6 +174,20 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">Tags</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :suggested_tags %>
|
||||
<%= f.text_field :suggested_tags,
|
||||
class: "form-control",
|
||||
value: SiteConfig.suggested_tags.join(","),
|
||||
placeholder: "List of valid tags: comma separated, letters only e.g. beginners,javascript,ruby,swift,kotlin" %>
|
||||
<div class="alert alert-info">Determines which tags are suggested to new users during onboarding (comma separated, letters only)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-3">
|
||||
<%= f.submit "Update Site Configuration", class: "btn btn-primary" %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -110,5 +110,17 @@ RSpec.describe "/internal/config", type: :request do
|
|||
expect(SiteConfig.periodic_email_digest_min).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Tags" do
|
||||
it "removes space suggested_tags" do
|
||||
post "/internal/config", params: { site_config: { suggested_tags: "hey, haha,hoho, bobo fofo" } }
|
||||
expect(SiteConfig.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "downcases suggested_tags" do
|
||||
post "/internal/config", params: { site_config: { suggested_tags: "hey, haha,hoHo, Bobo Fofo" } }
|
||||
expect(SiteConfig.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,5 +19,11 @@ RSpec.describe "ArticlesApi", type: :request do
|
|||
expect(response.body).to include("[")
|
||||
expect(response.body).to include(tag.name)
|
||||
end
|
||||
|
||||
it "does not return incorrect onboarding tag objects" do
|
||||
tag = create(:tag, name: "dsdsdsdsdsdssddsdsds")
|
||||
get "/api/tags/onboarding"
|
||||
expect(response.body).not_to include(tag.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue