Generalized shop url by creating SiteConfig field for it (#7262)

* added shop_url to SiteConfig

* fixed issue in show config erb file

* add spec for shop_url SideConfig

* added spec

* handles blank shop_url case

* code review changes
This commit is contained in:
Jitendra Rajpurohit 2020-04-16 01:58:34 +05:30 committed by GitHub
parent 467e0a1b5e
commit 7656d10e2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 69 deletions

View file

@ -38,7 +38,7 @@ class Internal::ConfigsController < Internal::ApplicationController
mailchimp_tag_moderators_id mailchimp_community_moderators_id
periodic_email_digest_max periodic_email_digest_min suggested_tags
rate_limit_comment_creation rate_limit_published_article_creation
rate_limit_image_upload rate_limit_email_recipient sidebar_tags
rate_limit_image_upload rate_limit_email_recipient sidebar_tags shop_url
]
params.require(:site_config).permit(allowed_params, social_media_handles: SiteConfig.social_media_handles.keys)
end

View file

@ -81,6 +81,9 @@ class SiteConfig < RailsSettings::Base
field :suggested_tags, type: :array, default: %w[beginners career computerscience javascript security ruby rails swift kotlin]
field :sidebar_tags, type: :array, default: %w[help challenge discuss explainlikeimfive meta watercooler]
# Shop
field :shop_url, type: :string, default: "https://shop.dev.to"
# Helpful methods
def self.auth_allowed?(provider)
authentication_providers.include?(provider)

View file

@ -25,12 +25,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Community Content",
state: "collapse",
target: "contentBodyContainer",
expanded: "false"
} %>
locals: {
header: "Community Content",
state: "collapse",
target: "contentBodyContainer",
expanded: "false"
} %>
<div id="contentBodyContainer" class="card-body collapse hide" aria-labelledby="contentBodyContainer">
<div class="form-group">
<%= f.label :community_description, "Community description" %>
@ -73,12 +73,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Social Media and Email",
state: "collapse",
target: "socialMediaBodyContainer",
expanded: "false"
} %>
locals: {
header: "Social Media and Email",
state: "collapse",
target: "socialMediaBodyContainer",
expanded: "false"
} %>
<div id="socialMediaBodyContainer" class="card-body collapse hide" aria-labelledby="socialMediaBodyContainer">
<div class="form-group">
<%= f.label :default_site_email %>
@ -94,10 +94,10 @@
<div>
<%= 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: "" %>
<div class="alert alert-info"><%= social_media_platform.capitalize() %> Username</div>
class: "form-control",
value: SiteConfig.social_media_handles[social_media_platform],
placeholder: "" %>
<div class="alert alert-info"><%= social_media_platform.capitalize %> Username</div>
</div>
<% end %>
<% end %>
@ -107,12 +107,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Authentication",
state: "collapse",
target: "authenticationBodyContainer",
expanded: "false"
} %>
locals: {
header: "Authentication",
state: "collapse",
target: "authenticationBodyContainer",
expanded: "false"
} %>
<div id="authenticationBodyContainer" class="card-body collapse hide" aria-labelledby="authenticationBodyContainer">
<div class="form-group">
<%= f.label :authentication_providers, "Authentication providers" %>
@ -127,12 +127,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Campaign",
state: "collapse",
target: "campaignBodyContainer",
expanded: "false"
} %>
locals: {
header: "Campaign",
state: "collapse",
target: "campaignBodyContainer",
expanded: "false"
} %>
<div id="campaignBodyContainer" class="card-body collapse hide" aria-labelledby="campaignBodyContainer">
<div class="form-group">
<%= f.label :campaign_hero_html_variant_name %>
@ -178,12 +178,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Images",
state: "collapse",
target: "imagesBodyContainer",
expanded: "false"
} %>
locals: {
header: "Images",
state: "collapse",
target: "imagesBodyContainer",
expanded: "false"
} %>
<div id="imagesBodyContainer" class="card-body collapse hide" aria-labelledby="imagesBodyContainer">
<div class="form-group">
<%= f.label :main_social_image %>
@ -270,12 +270,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Rate limits",
state: "collapse",
target: "rateLimitsBodyContainer",
expanded: "false"
} %>
locals: {
header: "Rate limits",
state: "collapse",
target: "rateLimitsBodyContainer",
expanded: "false"
} %>
<div id="rateLimitsBodyContainer" class="card-body collapse hide" aria-labelledby="rateLimitsBodyContainer">
<div class="form-group">
<%= f.label :rate_limit_follow_count_daily %>
@ -331,12 +331,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Google Analytics Reporting API v4",
state: "collapse",
target: "gaBodyContainer",
expanded: "false"
} %>
locals: {
header: "Google Analytics Reporting API v4",
state: "collapse",
target: "gaBodyContainer",
expanded: "false"
} %>
<div id="gaBodyContainer" class="card-body collapse hide" aria-labelledby="gaBodyContainer">
<div class="form-group">
<%= f.label :ga_view_id, "View ID" %>
@ -360,12 +360,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Mailchimp Lists IDs",
state: "collapse",
target: "mailchimpListBodyContainer",
expanded: "false"
} %>
locals: {
header: "Mailchimp Lists IDs",
state: "collapse",
target: "mailchimpListBodyContainer",
expanded: "false"
} %>
<div id="mailchimpListBodyContainer" class="card-body collapse hide" aria-labelledby="mailchimpListBodyContainer">
<div class="form-group">
<%= f.label :mailchimp_newsletter_id, "Main Newsletter" %>
@ -403,12 +403,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Email digest frequency",
state: "collapse",
target: "emailDigestBodyContainer",
expanded: "false"
} %>
locals: {
header: "Email digest frequency",
state: "collapse",
target: "emailDigestBodyContainer",
expanded: "false"
} %>
<div id="emailDigestBodyContainer" class="card-body collapse hide" aria-labelledby="emailDigestBodyContainer">
<div class="form-group">
<%= f.label :periodic_email_digest_max %>
@ -432,12 +432,12 @@
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Tags",
state: "collapse",
target: "tagsBodyContainer",
expanded: "false"
} %>
locals: {
header: "Tags",
state: "collapse",
target: "tagsBodyContainer",
expanded: "false"
} %>
<div id="tagsBodyContainer" class="card-body collapse hide" aria-labelledby="tagsBodyContainer">
<div class="form-group">
<%= f.label :suggested_tags %>
@ -458,6 +458,27 @@
</div>
</div>
</div>
<div class="card mt-3">
<%= render partial: "card_header",
locals: {
header: "Shop",
state: "collapse",
target: "shopBodyContainer",
expanded: "false"
} %>
<div id="shopBodyContainer" class="card-body collapse hide" aria-labelledby="shopBodyContainer">
<div class="form-group">
<%= f.label :shop_url %>
<%= f.text_field :shop_url,
class: "form-control",
value: SiteConfig.shop_url,
placeholder: "Shop url" %>
<div class="alert alert-info">Used as the shop url of the community</div>
</div>
</div>
</div>
<% if current_user.has_role?(:single_resource_admin, Config) %>
<div class="card mt-3">
<div class="card-header">Confirm and Submit</div>

View file

@ -43,7 +43,9 @@
<ul class="key-links">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="https://shop.dev.to/"><%= community_name %> Shop</a></li>
<% if SiteConfig.shop_url.present? %>
<li><a href="<%= SiteConfig.shop_url %>"><%= community_name %> Shop</a></li>
<% end %>
<li><a href="/sponsors">Sponsors</a></li>
<li><a href="/faq">FAQ</a></li>
<li><a href="/privacy">Privacy Policy</a></li>

View file

@ -104,11 +104,20 @@
<p><strong>Payment processing</strong>
<br>
<%= community_name %> does not process payments directly — we rely on third-party services such as Stripe, Shopify, and Paypal to receive payments and store any payment information.
<a href="https://shop.dev.to">The <%= community_name %> Shop</a> is run through Shopify, a third-party e-commerce platform with their own Privacy Policy.
<% if SiteConfig.shop_url.present? %>
<a href="<%= SiteConfig.shop_url %>">The <%= community_name %> Shop</a> is run through Shopify, a third-party e-commerce platform with their own Privacy Policy.
<% end %>
</p>
<p><strong>Third-Party Embeds</strong>
<br>
Some of the content that you see displayed on <%= community_name %> is not hosted by <%= community_name %>. These “embeds” are hosted by a third-party and embedded in <%= community_name %>. For example: YouTube videos, Codepens, Twitter tweets, or GitHub code that appear within a <%= community_name %> post. These files send data to the hosted site just as if you were visiting that site directly (for example, when you load a <%= community_name %> post page with a YouTube video embedded in it, YouTube receives data about your activity). <%= community_name %> does not control what data third parties collect in cases like this, or what they will do with it. Third-party embeds on <%= community_name %> are not covered by this privacy policy; they are covered by the privacy policy of the third-party service. Be mindful when interacting with these services.
Some of the content that you see displayed on <%= community_name %> is not hosted by <%= community_name %>. These
“embeds” are hosted by a third-party and embedded in <%= community_name %>. For example: YouTube videos, Codepens,
Twitter tweets, or GitHub code that appear within a <%= community_name %> post. These files send data to the hosted
site just as if you were visiting that site directly (for example, when you load a <%= community_name %> post page with
a YouTube video embedded in it, YouTube receives data about your activity). <%= community_name %> does not control what
data third parties collect in cases like this, or what they will do with it. Third-party embeds on <%= community_name %>
are not covered by this privacy policy; they are covered by the privacy policy of the third-party service. Be mindful
when interacting with these services.
</p>
<p><strong>Facebook (visitor action pixel)</strong>
<br>
@ -123,7 +132,14 @@
We use browser cookies and similar technologies to recognize you when you return to our Services. Third-party vendors may also use cookies for various reasons.
<br>
<br>
<%= community_name %> uses a specific cookie in order to facilitate the use of Google Universal Analytics for users logged-in to the Applications or the Platforms (“Logged-In User). If you are a Logged-In User, <%= community_name %> may use your <%= community_name %> user ID in combination with Google Universal Analytics and Google Analytics to track and analyze the pages of the Services you visit. We do this only to better understand how you use the Website and the other Services, with a view to offering improvements for all <%= community_name %> users; and to tailor our business and marketing activities accordingly, both generally and specifically to you. Google Analytics cookies do not provide <%= community_name %> with any Personal Information.You can prevent Google Analytics from recognizing you on return visits to this site by disabling cookies on your browser.
<%= community_name %> uses a specific cookie in order to facilitate the use of Google Universal Analytics for users
logged-in to the Applications or the Platforms (“Logged-In User). If you are a Logged-In User, <%= community_name %>
may use your <%= community_name %> user ID in combination with Google Universal Analytics and Google Analytics to track
and analyze the pages of the Services you visit. We do this only to better understand how you use the Website and the
other Services, with a view to offering improvements for all <%= community_name %> users; and to tailor our business
and marketing activities accordingly, both generally and specifically to you. Google Analytics cookies do not provide
<%= community_name %> with any Personal Information.You can prevent Google Analytics from recognizing you on return
visits to this site by disabling cookies on your browser.
<br>
<br>
You may opt-out of this feature by installing the Google Analytics Opt-out Browser Add-on, by setting your web browser to refuse cookies, or by setting your browser to alert you when cookies are being sent. If you do so, note that some parts of the Site may not function properly.

View file

@ -244,6 +244,35 @@ RSpec.describe "/internal/config", type: :request do
end
end
describe "Shop" do
it "rejects update to shop_url without proper confirmation" do
expected_shop_url = "https://qshop.dev.to"
expect { post "/internal/config", params: { site_config: { shop_url: expected_shop_url }, confirmation: "Incorrect confirmation" } }.to raise_error Pundit::NotAuthorizedError
expect(SiteConfig.shop_url).not_to eq(expected_shop_url)
get "/privacy"
expect(response.body).not_to include(expected_shop_url)
expect(response.body).to include("#{ApplicationConfig['COMMUNITY_NAME']} Shop")
end
it "sets shop_url to nil" do
previous_shop_url = SiteConfig.shop_url
post "/internal/config", params: { site_config: { shop_url: "" }, confirmation: confirmation_message }
expect(SiteConfig.shop_url).to eq("")
get "/privacy"
expect(response.body).not_to include(previous_shop_url)
expect(response.body).not_to include("#{ApplicationConfig['COMMUNITY_NAME']} Shop")
end
it "updates shop url" do
expected_shop_url = "https://qshop.dev.to"
post "/internal/config", params: { site_config: { shop_url: expected_shop_url }, confirmation: confirmation_message }
expect(SiteConfig.shop_url).to eq(expected_shop_url)
get "/privacy"
expect(response.body).to include(expected_shop_url)
expect(response.body).to include("#{ApplicationConfig['COMMUNITY_NAME']} Shop")
end
end
describe "Authentication" do
it "removes space authentication_providers" do
post "/internal/config", params: { site_config: { authentication_providers: "github, twitter" }, confirmation: confirmation_message }

View file

@ -36,6 +36,8 @@ RSpec.describe "Pages", type: :request do
it "has proper headline" do
get "/privacy"
expect(response.body).to include("Privacy Policy")
expect(response.body).to include(SiteConfig.shop_url)
expect(response.body).to include("#{ApplicationConfig['COMMUNITY_NAME']} Shop")
end
end