diff --git a/app/controllers/internal/configs_controller.rb b/app/controllers/internal/configs_controller.rb index f8c15c948..e890fc61a 100644 --- a/app/controllers/internal/configs_controller.rb +++ b/app/controllers/internal/configs_controller.rb @@ -10,7 +10,11 @@ class Internal::ConfigsController < Internal::ApplicationController def create clean_up_params config_params.keys.each do |key| - SiteConfig.public_send("#{key}=", config_params[key].strip) unless config_params[key].nil? + if config_params[key].respond_to?(:to_h) + SiteConfig.public_send("#{key}=", config_params[key].to_h) unless config_params[key].empty? + else + SiteConfig.public_send("#{key}=", config_params[key].strip) unless config_params[key].nil? + end end bust_relevant_caches redirect_to internal_config_path, notice: "Site configuration was successfully updated." @@ -20,7 +24,7 @@ class Internal::ConfigsController < Internal::ApplicationController def config_params allowed_params = %i[ - default_site_email social_networks_handle mascot_user_id + default_site_email mascot_user_id campaign_hero_html_variant_name campaign_sidebar_enabled campaign_featured_tags campaign_sidebar_image main_social_image favicon_url logo_svg logo_png primary_sticker_image_url @@ -34,7 +38,7 @@ class Internal::ConfigsController < Internal::ApplicationController rate_limit_comment_creation rate_limit_published_article_creation rate_limit_image_upload rate_limit_email_recipient sidebar_tags ] - params.require(:site_config).permit(allowed_params) + params.require(:site_config).permit(allowed_params, social_media_handles: SiteConfig.social_media_handles.keys) end def extra_authorization_and_confirmation diff --git a/app/models/site_config.rb b/app/models/site_config.rb index b9c40897f..3319b4f3f 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -11,18 +11,22 @@ class SiteConfig < RailsSettings::Base # the cache, or call SiteConfig.clear_cache cache_prefix { "v1" } - # site content + # Community Content field :community_description, type: :string, default: "A constructive and inclusive social network. Open source and radically transparent." field :community_member_description, type: :string, default: "amazing humans who code." field :tagline, type: :string, default: "We're a place where coders share, stay up-to-date and grow their careers." + field :mascot_user_id, type: :integer, default: 1 - # staff account + # Social Media and Email field :staff_user_id, type: :integer, default: 1 field :default_site_email, type: :string, default: "yo@dev.to" - field :social_networks_handle, type: :string, default: "thepracticaldev" - - # mascot account - field :mascot_user_id, type: :integer, default: 1 + field :social_media_handles, type: :hash, default: { + twitter: nil, + facebook: nil, + github: nil, + instagram: nil, + twitch: nil + } # Authentication field :authentication_providers, type: :array, default: %w[twitter github] @@ -30,13 +34,13 @@ class SiteConfig < RailsSettings::Base # Broadcast field :welcome_notifications_live_at, type: :date - # campaign + # Campaign field :campaign_hero_html_variant_name, type: :string, default: "" field :campaign_featured_tags, type: :array, default: %w[] field :campaign_sidebar_enabled, type: :boolean, default: 0 field :campaign_sidebar_image, type: :string, default: nil - # images + # 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_png, type: :string, default: "https://practicaldev-herokuapp-com.freetls.fastly.net/assets/devlogo-pwa-512.png" @@ -45,7 +49,7 @@ class SiteConfig < RailsSettings::Base field :mascot_image_url, type: :string, default: "https://practicaldev-herokuapp-com.freetls.fastly.net/assets/sloan.png" field :mascot_image_description, type: :string, default: "Sloan, the sloth mascot" - # rate limits + # Rate Limits field :rate_limit_follow_count_daily, type: :integer, default: 500 field :rate_limit_comment_creation, type: :integer, default: 9 field :rate_limit_published_article_creation, type: :integer, default: 9 diff --git a/app/views/articles/_sidebar.html.erb b/app/views/articles/_sidebar.html.erb index 6970a4637..0bbf00110 100644 --- a/app/views/articles/_sidebar.html.erb +++ b/app/views/articles/_sidebar.html.erb @@ -29,22 +29,15 @@

Key links

- - <%= inline_svg_tag("twitter.svg", aria: true, title: "Twitter", class: "crayons-icon") %> - - - <%= inline_svg_tag("github.svg", aria: true, title: "Github", class: "crayons-icon") %> - - - <%= inline_svg_tag("instagram.svg", aria: true, title: "Instagram", class: "crayons-icon") %> - - - <%= inline_svg_tag("facebook.svg", aria: true, title: "Facebook", class: "crayons-icon") %> - - - <%= inline_svg_tag("twitch.svg", aria: true, title: "Twitch", class: "crayons-icon") %> - + <% SiteConfig.social_media_handles.keys.each do |social_media_type| %> + <% if SiteConfig.social_media_handles[social_media_type].present? %> + " target="_blank" rel="noopener"> + <%= inline_svg_tag("#{social_media_type}.svg", aria: true, title: "#{social_media_type.capitalize}", class: "crayons-icon") %> + + <% end %> + <% end %>
+ - + <% end %> <% if (article.decorate.cached_tag_list_array & Tag.bufferized_tags).any? %> diff --git a/app/views/internal/configs/show.html.erb b/app/views/internal/configs/show.html.erb index 530ad38e3..855eca369 100644 --- a/app/views/internal/configs/show.html.erb +++ b/app/views/internal/configs/show.html.erb @@ -88,14 +88,19 @@ placeholder: "email@staff.com" %>
Email of the staff account
-
- <%= f.label :social_networks_handle %> - <%= f.text_field :social_networks_handle, - class: "form-control", - value: SiteConfig.social_networks_handle, - placeholder: "thepracticaldev" %> -
Social networks handle (eg. Twitter, GitHub)
+ <%= f.fields_for :social_media_handles do |social_media_field| %> + <% SiteConfig.social_media_handles.keys.each do |social_media_platform| %> +
+ <%= social_media_field.label social_media_platform %> + <%= social_media_field.text_field social_media_platform, + class: "form-control", + value: SiteConfig.social_media_handles[social_media_platform], + placeholder: "" %> +
<%= social_media_platform.capitalize() %> Username
+
+ <% end %> + <% end %>
diff --git a/app/views/moderations/mod.html.erb b/app/views/moderations/mod.html.erb index 968a77aac..d870a4d48 100644 --- a/app/views/moderations/mod.html.erb +++ b/app/views/moderations/mod.html.erb @@ -158,7 +158,7 @@ <% if @moderatable.last_buffered.blank? %>
<%= form_for(BufferUpdate.new) do |f| %> -

Suggest a Tweet for @<%= SiteConfig.social_networks_handle %>

+

Suggest a Tweet for @<%= SiteConfig.social_media_handles["twitter"] %>

<%= f.hidden_field :article_id, value: @moderatable.id %> <%= f.text_area :body_text, maxlength: 220, placeholder: "Can be a TLDR of the post, an interesting quote from the post, or bullet points from topics covered in the post, etc." %> <%= f.submit "Share Tweet Suggestion" %> diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 2a85426b3..fa39ddec7 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -12,7 +12,7 @@ - + "> <% end %> diff --git a/app/views/pages/about.html.erb b/app/views/pages/about.html.erb index 35c6d2aa7..6e14397d7 100644 --- a/app/views/pages/about.html.erb +++ b/app/views/pages/about.html.erb @@ -13,7 +13,7 @@ - + "> @@ -92,7 +92,7 @@

The platform was created in 2016. The Twitter account, - @ThePracticalDev was around before then. We are based out of New York City. + ">@<%= SiteConfig.social_media_handles["twitter"] %> was around before then. We are based out of New York City.

diff --git a/app/views/pages/badges.html.erb b/app/views/pages/badges.html.erb index ddc94cf4a..daabaa91d 100644 --- a/app/views/pages/badges.html.erb +++ b/app/views/pages/badges.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/pages/bounty.html.erb b/app/views/pages/bounty.html.erb index fb4967d84..4ab2cb1c6 100644 --- a/app/views/pages/bounty.html.erb +++ b/app/views/pages/bounty.html.erb @@ -10,7 +10,7 @@ - + "> <% end %> diff --git a/app/views/pages/code_of_conduct.html.erb b/app/views/pages/code_of_conduct.html.erb index 3de1e2e7e..87b3b1690 100644 --- a/app/views/pages/code_of_conduct.html.erb +++ b/app/views/pages/code_of_conduct.html.erb @@ -11,7 +11,7 @@ <%# %> - + "> <%# %> <%# %> diff --git a/app/views/pages/contact.html.erb b/app/views/pages/contact.html.erb index ffe6fc35e..59488be15 100644 --- a/app/views/pages/contact.html.erb +++ b/app/views/pages/contact.html.erb @@ -13,7 +13,7 @@ - + "> @@ -33,7 +33,7 @@ Email: <%= SiteConfig.default_site_email %> 😁

- Twitter: @<%= SiteConfig.social_networks_handle %> πŸ‘» + Twitter: ">@<%= SiteConfig.social_media_handles["twitter"] %> πŸ‘»

Report a vulnerability: dev.to/security πŸ› diff --git a/app/views/pages/faq.html.erb b/app/views/pages/faq.html.erb index 5aba81d37..3fa3f5d65 100644 --- a/app/views/pages/faq.html.erb +++ b/app/views/pages/faq.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/pages/generator.html.erb b/app/views/pages/generator.html.erb index 773815db8..f86c05681 100644 --- a/app/views/pages/generator.html.erb +++ b/app/views/pages/generator.html.erb @@ -16,7 +16,7 @@ - + "> @@ -38,7 +38,7 @@

But don't thank - @ThePracticalDev for this one

+ ">@<%= SiteConfig.social_media_handles["twitter"] %> for this one

This tool was created with love by Charles Berlin (@AModelEngineer)

@@ -113,7 +113,7 @@

If you have any feedback, you can direct message - @ThePracticalDev any time!

+ " >@<%= SiteConfig.social_media_handles["twitter"] %> any time! Add to Slack
diff --git a/app/views/pages/information.html.erb b/app/views/pages/information.html.erb index ba99e8bb3..147093073 100644 --- a/app/views/pages/information.html.erb +++ b/app/views/pages/information.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/pages/privacy.html.erb b/app/views/pages/privacy.html.erb index 2ab3abbc8..21c7815b3 100644 --- a/app/views/pages/privacy.html.erb +++ b/app/views/pages/privacy.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/pages/report-abuse.html.erb b/app/views/pages/report-abuse.html.erb index 3afa918dc..b6eacb4ca 100644 --- a/app/views/pages/report-abuse.html.erb +++ b/app/views/pages/report-abuse.html.erb @@ -8,7 +8,7 @@ - + "> <% end %> diff --git a/app/views/pages/rlyweb.html.erb b/app/views/pages/rlyweb.html.erb index a5b827875..6dcc3c1ce 100644 --- a/app/views/pages/rlyweb.html.erb +++ b/app/views/pages/rlyweb.html.erb @@ -16,7 +16,7 @@ - + "> @@ -56,7 +56,7 @@

Insult your co-workers with snarky O RLY parody book covers!

PS. There are a few known edge cases that do not generate. Some characters and long words won't work, etc. If you want to report an issue, feel free DM - @ThePracticalDev on Twitter.

+ @<%= SiteConfig.social_media_handles["twitter"] %> on Twitter.

Animal Codes

@@ -124,7 +124,7 @@
16
-

But don't thank @ThePracticalDev for this one +

But don't thank ">@<%= SiteConfig.social_media_handles["twitter"] %> for this one

This tool was created with love by Charles Berlin (@AModelEngineer)

diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index 2700dd332..e8e06646c 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -12,7 +12,7 @@ - + "> "> diff --git a/app/views/pages/terms.html.erb b/app/views/pages/terms.html.erb index 264dfa9c4..64cdc380f 100644 --- a/app/views/pages/terms.html.erb +++ b/app/views/pages/terms.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/podcast_episodes/_meta.html.erb b/app/views/podcast_episodes/_meta.html.erb index aaa041d2b..59d75508f 100644 --- a/app/views/podcast_episodes/_meta.html.erb +++ b/app/views/podcast_episodes/_meta.html.erb @@ -15,7 +15,7 @@ - + "> @@ -37,8 +37,8 @@ - - + "> + "> diff --git a/app/views/podcast_episodes/show.html.erb b/app/views/podcast_episodes/show.html.erb index 2df8ddd25..cb9a91d25 100644 --- a/app/views/podcast_episodes/show.html.erb +++ b/app/views/podcast_episodes/show.html.erb @@ -11,7 +11,7 @@ - + "> diff --git a/app/views/reading_list_items/index.html.erb b/app/views/reading_list_items/index.html.erb index d60bc55ab..449c994e0 100644 --- a/app/views/reading_list_items/index.html.erb +++ b/app/views/reading_list_items/index.html.erb @@ -12,7 +12,7 @@ - + "> <% end %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index cf2217a48..b18bba26d 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -13,7 +13,7 @@ - + "> diff --git a/app/views/users/_meta.html.erb b/app/views/users/_meta.html.erb index 853435ff7..fe7b808aa 100644 --- a/app/views/users/_meta.html.erb +++ b/app/views/users/_meta.html.erb @@ -10,7 +10,7 @@ - +"> diff --git a/app/views/videos/index.html.erb b/app/views/videos/index.html.erb index c3bd7cafa..e8fcffd02 100644 --- a/app/views/videos/index.html.erb +++ b/app/views/videos/index.html.erb @@ -12,7 +12,7 @@ - + "> "> diff --git a/lib/tasks/temporary/social_media_handles.rake b/lib/tasks/temporary/social_media_handles.rake new file mode 100644 index 000000000..9b1feb319 --- /dev/null +++ b/lib/tasks/temporary/social_media_handles.rake @@ -0,0 +1,8 @@ +namespace :temporary do + namespace :social_media do + desc "Update DEV's social media handles" + task update_handles: :environment do + SiteConfig.public_send("social_media_handles=", {twitter: "thepracticaldev", facebook: "thepracticaldev", github: "thepracticaldev", instagram: "thepracticaldev", twitch: "thepracticaldev"}) + end + end +end diff --git a/spec/requests/internal/configs_spec.rb b/spec/requests/internal/configs_spec.rb index 8955968d1..a0c682130 100644 --- a/spec/requests/internal/configs_spec.rb +++ b/spec/requests/internal/configs_spec.rb @@ -73,11 +73,12 @@ RSpec.describe "/internal/config", type: :request do 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 }, + it "updates social_media_handles" do + expected_handle = {"facebook"=>"tpd", "github"=>"", "instagram"=>"", "twitch"=>"", "twitter"=>""} + post "/internal/config", params: { site_config: { social_media_handles: expected_handle }, confirmation: confirmation_message } - expect(SiteConfig.social_networks_handle).to eq(expected_handle) + expect(SiteConfig.social_media_handles[:facebook]).to eq("tpd") + expect(SiteConfig.social_media_handles[:github]).to eq("") end end