[deploy] Refactor to create a helper for the mailer links (#7502)

* refactor: set the email_from to use in teh defaults

* chore: remove some new lines

* feat: add a mail link helper that can be used in the views

* feat: returns the default if it doesn't understand the parameter

* feat: Quick replacement of links

* feat: allow subject to be passed through

* chore: update all hrefs

* chore: remove rel attribute

* chore: mail link

* update spec

* chore: space

* chore: update some whitespaces and emails

* style

* chore: PR mail_link to email_link and the comment

* feat: PR suggestions for encoding

* feat: use mail_to
This commit is contained in:
Ridhwana 2020-04-27 15:18:16 +02:00 committed by GitHub
parent 9d1ad76a21
commit b9a8d87e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 88 additions and 45 deletions

View file

@ -309,16 +309,10 @@ class UsersController < ApplicationController
def handle_account_tab
community_name = ApplicationConfig["COMMUNITY_NAME"]
@email_body = <<~HEREDOC
Hello #{community_name} Team,
%0A
%0A
I would like to delete my account.
%0A%0A
You can keep any comments and discussion posts under the Ghost account.
%0A
%0A
Hello #{community_name} Team,\n
I would like to delete my account.\n
You can keep any comments and discussion posts under the Ghost account.\n
Regards,
%0A
YOUR-#{community_name}-USERNAME-HERE
HEREDOC
end

View file

@ -170,6 +170,13 @@ module ApplicationHelper
"#{start_year} - #{current_year}"
end
def email_link(type = :default, text: nil, additional_info: nil)
# The allowed types for type is :default, :business, :privacy, and members.
# These options can be found in field :email_addresses of models/site_config.rb
email = SiteConfig.email_addresses[type] || SiteConfig.email_addresses[:default]
mail_to email, text || email, additional_info
end
# Creates an app internal URL
#
# @note Uses protocol and domain specified in the environment, ensure they are set.

View file

@ -2,7 +2,7 @@ import { h, render } from 'preact';
import { getUserDataAndCsrfToken } from '../chat/util';
import ArticleForm from '../article-form/articleForm';
HTMLDocument.prototype.ready = new Promise(resolve => {
HTMLDocument.prototype.ready = new Promise((resolve) => {
if (document.readyState !== 'loading') {
return resolve();
}
@ -38,5 +38,3 @@ document.ready.then(() => {
}
});
});

View file

@ -7,10 +7,14 @@ class ApplicationMailer < ActionMailer::Base
helper ApplicationHelper
default(
from: -> { "#{ApplicationConfig['COMMUNITY_NAME']} Community <#{SiteConfig.email_addresses[:default]}>" },
from: -> { email_from("Community") },
template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" },
)
def email_from(topic)
"#{ApplicationConfig['COMMUNITY_NAME']} #{topic} <#{SiteConfig.email_addresses[:default]}>"
end
def generate_unsubscribe_token(id, email_type)
Rails.application.message_verifier(:unsubscribe).generate(
user_id: id,

View file

@ -1,5 +1,5 @@
class DigestMailer < ApplicationMailer
default from: -> { "#{ApplicationConfig['COMMUNITY_NAME']} Digest <#{SiteConfig.email_addresses[:default]}>" }
default from: -> { email_from("Digest") }
def digest_email(user, articles)
@user = user

View file

@ -1,5 +1,5 @@
class ProMembershipMailer < ApplicationMailer
default from: -> { "#{ApplicationConfig['COMMUNITY_NAME']} Pro Memberships <#{SiteConfig.email_addresses[:default]}>" }
default from: -> { email_from("Pro Memberships") }
def expiring_membership(pro_membership, expiration_date)
@pro_membership = pro_membership

View file

@ -98,7 +98,7 @@
<div class="crayons-card grid gap-2 p-4">
<% if @membership.role == "mod" %>
<p>Questions about Connect Channel moderation? Contact <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a></p>
<p>Questions about Connect Channel moderation? Contact <%= email_link %></p>
<% else %>
<h3>Danger Zone</h3>
<%= form_for(@membership, html: { method: :delete, onsubmit: "return confirm('Are you absolutely sure you want to leave this channel? This action is permanent.');" }) do |f| %>

View file

@ -37,7 +37,7 @@
</div>
<br />
</div>
<p class="bulk-description"><em>Contact <a href="mailto:<%= SiteConfig.email_addresses[:business] %>?subject=Custom Bulk Pricing/Partnerships"><%= SiteConfig.email_addresses[:business] %></a> for custom bulk pricing and partnerships.</em></p>
<p class="bulk-description"><em>Contact <%= email_link(:business, additional_info: { subject: "Custom Bulk Pricing/Partnerships" }) %> for custom bulk pricing and partnerships.</em></p>
<details>
<summary>
How many credits does one listing cost?

View file

@ -25,6 +25,6 @@
<%= flash[:alert] %>
<br>
<% end %>
Please try again below, or contact <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if this persists.
Please try again below, or contact <%= email_link %> if this persists.
</div>
<% end %>

View file

@ -30,7 +30,7 @@
<p><%= community_name %> Events is a series of ongoing talks and workshops designed to cover important topics to help community members level up. Because we have a global community we will be hosting events at varying times so nobody is restricted by time zone. Additionally,
<strong>some workshops are repeated multiple times</strong> to further account for this.</p>
<p>We have many more planned if you do not see a topic that interests you. Email
<a href="mailto:<%= SiteConfig.email_addresses[:members] %>"><%= SiteConfig.email_addresses[:members] %></a> to request a topic. And if you're interested in speaking, please
<%= email_link(:members) %> to request a topic. And if you're interested in speaking, please
<a href="https://dev.to/jess/would-you-like-to-give-a-dev-talkworkshop--31c6">apply to our CFP</a>.</p>
<% @events.each do |event| %>

View file

@ -9,7 +9,7 @@
<h2>Thank you for your report.</h2>
<h3><a href="/">Return to home page</a></h3>
<p>
Questions? Send an email to <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a>
Questions? Send an email to <%= email_link %>
</p>
</div>
</div>

View file

@ -7,7 +7,7 @@
</p>
<p>
Contact us at <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if there is anything more we can help with. 😊
Contact us at <%= email_link %> if there is anything more we can help with. 😊
</p>
<p>

View file

@ -8,7 +8,7 @@
</p>
<p>
Contact us at <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if there is anything more we can help with. 😊
Contact us at <%= email_link %> if there is anything more we can help with. 😊
</p>
<p>

View file

@ -85,7 +85,7 @@
<h1 style="text-align: center"><%= community_name %> Mods</h1>
<div class="body">
<p>We periodically award some <%= community_name %> members with heightened privileges to help moderate the community.</p>
<p>Email <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if you'd like to be considered right away.</p>
<p>Email <%= email_link %> if you'd like to be considered right away.</p>
<% unless user_signed_in? %>
<p><em>P.S. You are not currently signed in.</em></p>
<% end %>

View file

@ -14,7 +14,7 @@
<div class="content notification-content comment-content">
An error occurred! This has been logged and we're tracking it.
<br>
If you see too many of these, please report it to <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a>!
If you see too many of these, please report it to <%= email_link %>!
</div>
<% end %>

View file

@ -23,6 +23,6 @@
<% end %>
<br><br />
Thanks for being part of <%= community_name %>! If you feel like this mod action was a mistake, feel free to contact
<a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a>. 🤗
<%= email_link %>. 🤗
<br /><br />
</div>

View file

@ -31,7 +31,7 @@
</ul>
<h2>Enforcement</h2>
<p>Violations of the Code of Conduct may be reported by contacting the team via the
<a href="<%= app_url("/report-abuse") %>">abuse report form</a> or by sending an email to <a href="mailto:<%= SiteConfig.email_addresses[:default] %>" rel="noopener noreferrer"><%= SiteConfig.email_addresses[:default] %></a>. All reports will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Further details of specific enforcement policies may be posted separately.
<a href="<%= app_url("/report-abuse") %>">abuse report form</a> or by sending an email to <%= email_link %>. All reports will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Further details of specific enforcement policies may be posted separately.
</p>
<p>Moderators have the right and responsibility to remove comments or other contributions that are not aligned to this Code of Conduct, or to suspend temporarily or permanently any members for other behaviors that they deem inappropriate, threatening, offensive, or harmful.</p>
<h2>Attribution</h2>

View file

@ -76,7 +76,7 @@
<p>
Users agree and certify that they have rights to share all content that they post on dev.to — including, but not limited to, information posted in articles, discussions, and comments. This rule applies to prose, code snippets, collections of links, etc. Regardless of citation, users may not post copy and pasted content that does not belong to them. Users assume all risk for the content they post, including someone else's reliance on its accuracy, claims relating to intellectual property, or other legal rights. If you believe that a user has plagiarized content, misrepresented their identity, misappropriated work, or otherwise run afoul of DMCA regulations, please email
<a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a>. <%= community_name %> may remove any content users post for any reason.
<%= email_link %>. <%= community_name %> may remove any content users post for any reason.
</p>
<h3 id="site-terms-of-use-modifications">
@ -92,7 +92,7 @@
</h3>
<p>
All uses of the <%= community_name %> logo, <%= community_name %> badges, brand slogans, iconography, and the like, may only be used with express permission from <%= community_name %>. <%= community_name %> reserves all rights, even if certain assets are included in <%= community_name %> open source projects. Please contact <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> with any questions or to request permission.
All uses of the <%= community_name %> logo, <%= community_name %> badges, brand slogans, iconography, and the like, may only be used with express permission from <%= community_name %>. <%= community_name %> reserves all rights, even if certain assets are included in <%= community_name %> open source projects. Please contact <%= email_link %> with any questions or to request permission.
</p>
<h3 id="reserved-names">

View file

@ -30,7 +30,7 @@
<%= community_qualified_name %> would love to hear from you!
</p>
<p>
Email: <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> 😁
Email: <%= email_link %> 😁
</p>
<p>
Twitter: <a href="http://twitter.com/<%= SiteConfig.social_media_handles["twitter"] %>">@<%= SiteConfig.social_media_handles["twitter"] %></a> 👻

View file

@ -164,14 +164,14 @@
</p>
<p><strong>Deleting Your Personal Information</strong>
<br>
You may request deletion of your personal information and account by emailing <a href="mailto:<%= SiteConfig.email_addresses[:privacy] %>"><%= SiteConfig.email_addresses[:privacy] %></a>.
You may request deletion of your personal information and account by emailing <%= email_link(:privacy) %>.
<br>
<br>
To protect information from accidental or malicious destruction, we may maintain residual copies for a brief time period. But, if you delete your account, your information and content will be unrecoverable after that time.
</p>
<p><strong>Data Portability</strong>
<br>
If you would like to request a copy of your user data, please email <a href="mailto:<%= SiteConfig.email_addresses[:privacy] %>"><%= SiteConfig.email_addresses[:privacy] %></a>.</p>
If you would like to request a copy of your user data, please email <%= email_link(:privacy) %>.</p>
<p><strong>Business Transfers</strong>
<br>
If we are involved in a merger, acquisition, bankruptcy, reorganization or sale of assets such that your information would be transferred or become subject to a different privacy policy, well notify you in advance of any such change.
@ -182,6 +182,6 @@
</p>
<p><strong>Questions</strong>
<br>
We welcome feedback about this policy at <a href="mailto:<%= SiteConfig.email_addresses[:privacy] %>"><%= SiteConfig.email_addresses[:privacy] %></a>.</p>
We welcome feedback about this policy at <%= email_link(:privacy) %>.</p>
</div>
</div>

View file

@ -11,5 +11,5 @@ The <%= community_name %> team sees over 1000 new posts published every week to
You will be invited to a shared Slack channel to aid communication and provide a line of communication for deep collaboration. It is an open line to our devrel experts available during extended US East business hours.
</p>
<% unless user_signed_in? %>
<h2>Email <a href="mailto:<%= SiteConfig.email_addresses[:business] %>"><%= SiteConfig.email_addresses[:business] %></a> for pricing information</h2>
<h2>Email <%= email_link(:business) %> for pricing information</h2>
<% end %>

View file

@ -50,7 +50,7 @@
<div class="partner-explainer-notice">
<%# this should never happen but better safe than sorry %>
<% sponsorships.each do |sponsorship| %>
🛑 You are already subscribed as a <%= sponsorship.level %> sponsor. Contact <%= SiteConfig.email_addresses[:business] %> to change plans.
🛑 You are already subscribed as a <%= sponsorship.level %> sponsor. Contact <%= email_link(:business) %>to change plans.
<% end %>
</div>
<% else %>
@ -120,5 +120,5 @@
<% end %>
<% end %>
<% else %>
<h2>Contact <a href="mailto:<%= SiteConfig.email_addresses[:business] %>"><%= SiteConfig.email_addresses[:business] %></a> to sign up</h1>
<h2>Contact <%= email_link(:business) %> to sign up</h1>
<% end %>

View file

@ -40,5 +40,5 @@ It will also include a call-to-action to follow your organization directly in th
As a Gold sponsor, you will receive special flair that lives on your organization page. This visual cue will show the <%= community_name %> Community and broader ecosystem that you are an important community supporter, providing a natural draw for increased engagement on the platform. And, of course, youll have bragging rights and company pride knowing that youre supporting a wonderful community.
</p>
<% unless user_signed_in? %>
<h2>Email <a href="mailto:<%= SiteConfig.email_addresses[:business] %>"><%= SiteConfig.email_addresses[:business] %></a> for pricing information</h2>
<h2>Email <%= email_link(:business) %> for pricing information</h2>
<% end %>

View file

@ -22,5 +22,5 @@ Sponsorship video insertion
As a media sponsor, your company will be included in all relevant sections around the content. For instance, in the <%= community_name %> post, in social media postings, email announcements, etc.
</p>
<% unless user_signed_in? %>
<h2>Email <a href="mailto:<%= SiteConfig.email_addresses[:business] %>"><%= SiteConfig.email_addresses[:business] %></a> for pricing information</h2>
<h2>Email <%= email_link(:business) %> for pricing information</h2>
<% end %>

View file

@ -111,6 +111,6 @@
</div>
</div>
<div style="text-align: center;">
<h2>Questions about anything?<br /><br />Email <a href="mailto:<%= SiteConfig.email_addresses[:business] %>"><%= SiteConfig.email_addresses[:business] %></a></h2>
<h2>Questions about anything?<br /><br />Email <%= email_link(:business) %></h2>
</div>
</div>

View file

@ -103,10 +103,10 @@
<% if current_user.articles_count.positive? || current_user.comments_count.positive? %>
<p>
If you would like to keep your content under the <%= link_to "@ghost", "/ghost" %> account,
please <a href="mailto:<%= SiteConfig.email_addresses[:default] %>?subject=Request Account Deletion&body=<%= @email_body %>">click here.</a>
please <%= email_link(text: "click here", additional_info: { subject: "Request Account Deletion", body: @email_body }) %>.
</p>
<% end %>
<p>Feel free to contact <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> with any questions.</p>
<p>Feel free to contact <%= email_link %> with any questions.</p>
</div>
</div>

View file

@ -22,7 +22,7 @@
</p>
<p>
Your feed will be fetched every time you submit this form and updates will be automatically fetched periodically thereafter. Contact
<a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if you encounter issues.
<%= email_link %> if you encounter issues.
</p>
<p>FYI: Medium RSS feed URLs are <em>https://medium.com/feed/@your_username</em></p>
<p><em>By submitting your RSS Feed URL, you agree that you own and/or have permission to syndicate the associated content.</em></p>

View file

@ -45,11 +45,11 @@
</script>
<p>
If you would like to keep your content under the <%= link_to "@ghost", "/ghost" %> account,
please <a href="mailto:<%= SiteConfig.email_addresses[:default] %>?subject=Request Account Deletion&body=<%= @email_body %>">click here.</a>
please <%= email_link(text: "click here", additional_info: { subject: "Request Account Deletion", body: @email_body }) %>
</p>
<p>
Feel free to contact <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> with any questions.
Feel free to contact <%= email_link %> with any questions.
</p>
</div>
</div>

View file

@ -15,7 +15,7 @@
<% if params[:state] == "previous-registration" %>
<div class="crayons-banner crayons-banner--error">
There is an existing account authorized with that social account. Contact
<a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if this is a mistake.
<%= email_link %> if this is a mistake.
</div>
<% end %>

View file

@ -33,7 +33,7 @@
<% end %>
<div style="margin:50px auto;max-width:80%;font-size:0.86em;">
<p>
<strong>Video is beta:</strong> Email <a href="mailto:<%= SiteConfig.email_addresses[:default] %>"><%= SiteConfig.email_addresses[:default] %></a> if you have any problems.
<strong>Video is beta:</strong> Email <%= email_link %> if you have any problems.
</p>
</div>
</center>

View file

@ -107,4 +107,44 @@ RSpec.describe ApplicationHelper, type: :helper do
expect(sanitized_referer("")).to be nil
end
end
describe "#email_link" do
before do
allow(SiteConfig).to receive(:email_addresses).and_return(
{
default: "hi@dev.to",
business: "business@dev.to",
privacy: "privacy@dev.to",
members: "members@dev.to"
},
)
end
it "returns an 'a' tag" do
expect(helper.email_link).to have_selector("a")
end
it "sets the correct href" do
expect(helper.email_link).to have_link(href: "mailto:hi@dev.to")
expect(helper.email_link(:business)).to have_link(href: "mailto:business@dev.to")
end
it "has the correct text in the a tag" do
expect(helper.email_link(text: "Link Name")).to have_text("Link Name")
expect(helper.email_link).to have_text("hi@dev.to")
end
it "returns the default email if it doesn't understand the type parameter" do
expect(helper.email_link(:nonsense)).to have_link(href: "mailto:hi@dev.to")
end
it "returns an href with additional_info parameters" do
additional_info = {
subject: "This is a long subject",
body: "This is a longer body with a question mark ? \n and a newline"
}
expect(email_link(text: "text", additional_info: additional_info)).to eq("<a href=\"mailto:hi@dev.to?body=This%20is%20a%20longer%20body%20with%20a%20question%20mark%20%3F%20%0A%20and%20a%20newline&amp;subject=This%20is%20a%20long%20subject\">text</a>")
end
end
end