Add additional keys to site configuration (#4861) [deploy]
* Add rate_limit_follow_count_daily to SiteConfig * Add favicon_url to SiteConfig * Add logo_svg to SiteConfig * Add staff_user_id to SiteConfig * Add default_site_email to SiteConfig * Add social_networks_handle to SiteConfig * Add ga_view_id and ga_fetch_rate to SiteConfig * Add mailchimp newsletters IDs to SiteConfig * Add periodic_email_digest_max, periodic_email_digest_min to SiteConfig
This commit is contained in:
parent
8140ab6330
commit
b0eec90b24
4 changed files with 284 additions and 10 deletions
|
|
@ -1,7 +1,9 @@
|
|||
class Internal::ConfigsController < Internal::ApplicationController
|
||||
layout "internal"
|
||||
|
||||
def show; end
|
||||
def show
|
||||
@logo_svg = SiteConfig.logo_svg.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def create
|
||||
config_params.keys.each do |key|
|
||||
|
|
@ -13,7 +15,15 @@ class Internal::ConfigsController < Internal::ApplicationController
|
|||
private
|
||||
|
||||
def config_params
|
||||
# put this stuff in the policy or in the model
|
||||
params.require(:site_config).permit(:main_social_image)
|
||||
allowed_params = %i[
|
||||
staff_user_id default_site_email social_networks_handle
|
||||
main_social_image favicon_url logo_svg
|
||||
rate_limit_follow_count_daily
|
||||
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
|
||||
]
|
||||
params.require(:site_config).permit(allowed_params)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,5 +8,32 @@ class SiteConfig < RailsSettings::Base
|
|||
# the cache, or call SiteConfig.clear_cache
|
||||
cache_prefix { "v1" }
|
||||
|
||||
field :main_social_image, default: "https://thepracticaldev.s3.amazonaws.com/i/6hqmcjaxbgbon8ydw93z.png"
|
||||
# staff account
|
||||
field :staff_user_id, type: :integer, default: 1 # will replace DEVTO_USER_ID
|
||||
field :default_site_email, type: :string, default: "yo@dev.to"
|
||||
field :social_networks_handle, type: :string, default: "thepracticaldev" # will replace SITE_TWITTER_HANDLE
|
||||
|
||||
# images
|
||||
field :main_social_image, type: :string, default: "https://thepracticaldev.s3.amazonaws.com/i/6hqmcjaxbgbon8ydw93z.png"
|
||||
field :favicon_url, type: :string, default: "favicon.ico"
|
||||
field :logo_svg, type: :string, default: ""
|
||||
|
||||
# rate limits
|
||||
field :rate_limit_follow_count_daily, type: :integer, default: 500
|
||||
|
||||
# Google Analytics Reporting API v4
|
||||
# <https://developers.google.com/analytics/devguides/reporting/core/v4>
|
||||
field :ga_view_id, type: :string, default: ""
|
||||
field :ga_fetch_rate, type: :integer, default: 25
|
||||
|
||||
# Mailchimp lists IDs
|
||||
# <https://mailchimp.com/developer/>
|
||||
field :mailchimp_newsletter_id, type: :string, default: ""
|
||||
field :mailchimp_sustaining_members_id, type: :string, default: ""
|
||||
field :mailchimp_tag_moderators_id, type: :string, default: ""
|
||||
field :mailchimp_community_moderators_id, type: :string, default: ""
|
||||
|
||||
# Email digest frequency
|
||||
field :periodic_email_digest_max, type: :integer, default: 0
|
||||
field :periodic_email_digest_min, type: :integer, default: 2
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,11 +15,44 @@
|
|||
</style>
|
||||
|
||||
<%= form_for(SiteConfig.new, url: internal_config_path) do |f| %>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Staff</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :staff_user_id %>
|
||||
<%= f.number_field :staff_user_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.staff_user_id,
|
||||
min: 1,
|
||||
placeholder: "1" %>
|
||||
<span class="help-block">User ID of the staff account</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :default_site_email %>
|
||||
<%= f.email_field :default_site_email,
|
||||
class: "form-control",
|
||||
value: SiteConfig.default_site_email,
|
||||
placeholder: "email@staff.com" %>
|
||||
<span class="help-block">Email of the staff account</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :social_networks_handle %>
|
||||
<%= f.text_field :social_networks_handle,
|
||||
class: "form-control",
|
||||
value: SiteConfig.social_networks_handle,
|
||||
placeholder: "thepracticaldev" %>
|
||||
<span class="help-block">Social networks handle (eg. Twitter, GitHub)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Images</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label "Main social image" %>
|
||||
<%= f.label :main_social_image %>
|
||||
<%= f.text_field :main_social_image,
|
||||
class: "form-control",
|
||||
value: SiteConfig.main_social_image,
|
||||
|
|
@ -27,6 +60,125 @@
|
|||
<span class="help-block">Used as the main image in social networks and OpenGraph</span>
|
||||
<img alt="main social image" class="preview" src="<%= SiteConfig.main_social_image %>" width="50%" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :favicon_url %>
|
||||
<%= f.text_field :favicon_url,
|
||||
class: "form-control",
|
||||
value: SiteConfig.favicon_url,
|
||||
placeholder: "https://image.url" %>
|
||||
<span class="help-block">Used as the site favicon</span>
|
||||
<img alt="favicon" class="preview" src="<%= SiteConfig.favicon_url %>" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :logo_svg %>
|
||||
<%= f.text_area :logo_svg,
|
||||
class: "form-control",
|
||||
value: SiteConfig.logo_svg,
|
||||
rows: 6,
|
||||
placeholder: "<svg ...></svg>" %>
|
||||
<span class="help-block">Used as the SVG logo of the community</span>
|
||||
<%= @logo_svg %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Rate limits</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :rate_limit_follow_count_daily %>
|
||||
<%= f.number_field :rate_limit_follow_count_daily,
|
||||
class: "form-control",
|
||||
value: SiteConfig.rate_limit_follow_count_daily,
|
||||
min: 0,
|
||||
placeholder: 500 %>
|
||||
<span class="help-block">Used to limit the amount of users a person can follow daily</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Google Analytics Reporting API v4</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :ga_view_id, "View ID" %>
|
||||
<%= f.text_field :ga_view_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.ga_view_id %>
|
||||
<span class="help-block">Google Analytics Reporting API v4 - View ID</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :ga_fetch_rate, "Fetch rate" %>
|
||||
<%= f.number_field :ga_fetch_rate,
|
||||
class: "form-control",
|
||||
value: SiteConfig.ga_fetch_rate,
|
||||
min: 1,
|
||||
placeholder: 1 %>
|
||||
<span class="help-block">Determines how often the site updates its Google Analytics stats</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Mailchimp Lists IDs</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :mailchimp_newsletter_id, "Main Newsletter" %>
|
||||
<%= f.text_field :mailchimp_newsletter_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.mailchimp_newsletter_id %>
|
||||
<span class="help-block">Main Newsletter ID</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :mailchimp_sustaining_members_id, "Sustaining Members Newsletter" %>
|
||||
<%= f.text_field :mailchimp_sustaining_members_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.mailchimp_sustaining_members_id %>
|
||||
<span class="help-block">Sustaining Members Newsletter ID</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :mailchimp_tag_moderators_id, "Tag Moderators Newsletter" %>
|
||||
<%= f.text_field :mailchimp_tag_moderators_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.mailchimp_tag_moderators_id %>
|
||||
<span class="help-block">Tag Moderators Newsletter ID</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :mailchimp_community_moderators_id, "Community Moderators Newsletter" %>
|
||||
<%= f.text_field :mailchimp_community_moderators_id,
|
||||
class: "form-control",
|
||||
value: SiteConfig.mailchimp_community_moderators_id %>
|
||||
<span class="help-block">Community Moderators Newsletter ID</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Email digest frequency</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<%= f.label :periodic_email_digest_max %>
|
||||
<%= f.number_field :periodic_email_digest_max,
|
||||
class: "form-control",
|
||||
value: SiteConfig.periodic_email_digest_max,
|
||||
placeholder: 0 %>
|
||||
<span class="help-block">Determines the maximum for the periodic email digest</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label :periodic_email_digest_min %>
|
||||
<%= f.number_field :periodic_email_digest_min,
|
||||
class: "form-control",
|
||||
value: SiteConfig.periodic_email_digest_min,
|
||||
placeholder: 2 %>
|
||||
<span class="help-block">Determines the mininum for the periodic email digest</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,96 @@ RSpec.describe "/internal/config", type: :request do
|
|||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "updates main_social_image" do
|
||||
SiteConfig.main_social_image = "https://dummyimage.com/100x100"
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/internal/config", params: { site_config: { main_social_image: expected_image_url } }
|
||||
expect(SiteConfig.main_social_image).to eq(expected_image_url)
|
||||
describe "staff" do
|
||||
it "updates staff_user_id" do
|
||||
post "/internal/config", params: { site_config: { staff_user_id: 2 } }
|
||||
expect(SiteConfig.staff_user_id).to eq(2)
|
||||
end
|
||||
|
||||
it "updates default_site_email" do
|
||||
expected_email = "foo@bar.com"
|
||||
post "/internal/config", params: { site_config: { default_site_email: expected_email } }
|
||||
expect(SiteConfig.default_site_email).to eq(expected_email)
|
||||
end
|
||||
|
||||
it "updates social_networks_handle" do
|
||||
expected_handle = "tpd"
|
||||
post "/internal/config", params: { site_config: { social_networks_handle: expected_handle } }
|
||||
expect(SiteConfig.social_networks_handle).to eq(expected_handle)
|
||||
end
|
||||
end
|
||||
|
||||
describe "images" do
|
||||
it "updates main_social_image" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/internal/config", params: { site_config: { main_social_image: expected_image_url } }
|
||||
expect(SiteConfig.main_social_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates favicon_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/internal/config", params: { site_config: { favicon_url: expected_image_url } }
|
||||
expect(SiteConfig.favicon_url).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates logo_svg" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/internal/config", params: { site_config: { logo_svg: expected_image_url } }
|
||||
expect(SiteConfig.logo_svg).to eq(expected_image_url)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rate limits" do
|
||||
it "updates rate_limit_follow_count_daily" do
|
||||
post "/internal/config", params: { site_config: { rate_limit_follow_count_daily: 3 } }
|
||||
expect(SiteConfig.rate_limit_follow_count_daily).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Google Analytics Reporting API v4" do
|
||||
it "updates ga_view_id" do
|
||||
post "/internal/config", params: { site_config: { ga_view_id: "abc" } }
|
||||
expect(SiteConfig.ga_view_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates ga_fetch_rate" do
|
||||
post "/internal/config", params: { site_config: { ga_fetch_rate: 3 } }
|
||||
expect(SiteConfig.ga_fetch_rate).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Mailchimp lists IDs" do
|
||||
it "updates mailchimp_newsletter_id" do
|
||||
post "/internal/config", params: { site_config: { mailchimp_newsletter_id: "abc" } }
|
||||
expect(SiteConfig.mailchimp_newsletter_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_sustaining_members_id" do
|
||||
post "/internal/config", params: { site_config: { mailchimp_sustaining_members_id: "abc" } }
|
||||
expect(SiteConfig.mailchimp_sustaining_members_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_tag_moderators_id" do
|
||||
post "/internal/config", params: { site_config: { mailchimp_tag_moderators_id: "abc" } }
|
||||
expect(SiteConfig.mailchimp_tag_moderators_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_community_moderators_id" do
|
||||
post "/internal/config", params: { site_config: { mailchimp_community_moderators_id: "abc" } }
|
||||
expect(SiteConfig.mailchimp_community_moderators_id).to eq("abc")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Email digest frequency" do
|
||||
it "updates periodic_email_digest_max" do
|
||||
post "/internal/config", params: { site_config: { periodic_email_digest_max: 1 } }
|
||||
expect(SiteConfig.periodic_email_digest_max).to eq(1)
|
||||
end
|
||||
|
||||
it "updates periodic_email_digest_min" do
|
||||
post "/internal/config", params: { site_config: { periodic_email_digest_min: 3 } }
|
||||
expect(SiteConfig.periodic_email_digest_min).to eq(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue