Remove markerb dependency

markerb is dead and isn't compatible with rails 6 anymore. Removing it
means adding separate templates for text and html, this sadly means some
code duplication, but also luckily the templates aren't that
complicated, so the duplication is also very minimal.
This commit is contained in:
Benjamin Neff 2022-07-11 04:24:01 +02:00
parent 6cea355636
commit a9ae84f3a6
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
66 changed files with 238 additions and 211 deletions

View file

@ -130,10 +130,6 @@ gem "http_accept_language", "2.1.1"
gem "i18n-inflector-rails", "1.0.7"
gem "rails-i18n", "5.1.3"
# Mail
gem "markerb", "1.1.0"
# Map
gem "leaflet-rails", "1.7.0"

View file

@ -377,7 +377,6 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.2)
markdown-it-html5-embed (1.0.0)
markerb (1.1.0)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (1.0.0)
@ -825,7 +824,6 @@ DEPENDENCIES
listen (= 3.7.1)
logging-rails (= 0.6.0)
markdown-it-html5-embed (= 1.0.0)
markerb (= 1.1.0)
mini_magick (= 4.11.0)
minitest (= 5.15.0)
mobile-fu (= 1.4.0)

View file

@ -2,38 +2,31 @@
class ExportMailer < ApplicationMailer
def export_complete_for(user)
@user = user
mail(to: @user.email, subject: I18n.t('notifier.export_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_email' }
format.text { render 'users/export_email' }
end
send_mail(user, I18n.t("notifier.export_email.subject", name: user.name),
I18n.t("notifier.export_email.body", url: download_profile_user_url, name: user.first_name))
end
def export_failure_for(user)
@user = user
mail(to: @user.email, subject: I18n.t('notifier.export_failure_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_failure_email' }
format.text { render 'users/export_failure_email' }
end
send_mail(user, I18n.t("notifier.export_failure_email.subject", name: user.name),
I18n.t("notifier.export_failure_email.body", name: user.first_name))
end
def export_photos_complete_for(user)
@user = user
mail(to: @user.email, subject: I18n.t('notifier.export_photos_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_photos_email' }
format.text { render 'users/export_photos_email' }
end
send_mail(user, I18n.t("notifier.export_photos_email.subject", name: user.name),
I18n.t("notifier.export_photos_email.body", url: download_photos_user_url, name: user.first_name))
end
def export_photos_failure_for(user)
@user = user
send_mail(user, I18n.t("notifier.export_photos_failure_email.subject", name: user.name),
I18n.t("notifier.export_photos_failure_email.body", name: user.first_name))
end
mail(to: @user.email, subject: I18n.t('notifier.export_photos_failure_email.subject', name: @user.name)) do |format|
format.html { render 'users/export_photos_failure_email' }
format.text { render 'users/export_photos_failure_email' }
private
def send_mail(user, subject, body)
mail(to: user.email, subject: subject) do |format|
format.html { render "notifier/plain_markdown_email", locals: {body: body} }
format.text { render "notifier/plain_markdown_email", locals: {body: body} }
end
end
end

View file

@ -2,16 +2,15 @@
class Maintenance < ApplicationMailer
def account_removal_warning(user)
@user = user
@login_url = new_user_session_url
@pod_url = AppConfig.environment.url
@after_days = AppConfig.settings.maintenance.remove_old_users.after_days.to_s
@remove_after = @user.remove_after
I18n.with_locale(@user.language) do
mail(to: @user.email, subject: I18n.t("notifier.remove_old_user.subject")) do |format|
format.text
format.html
I18n.with_locale(user.language) do
body = I18n.t("notifier.remove_old_user.body",
pod_url: AppConfig.environment.url,
login_url: new_user_session_url,
after_days: AppConfig.settings.maintenance.remove_old_users.after_days.to_s,
remove_after: user.remove_after)
mail(to: user.email, subject: I18n.t("notifier.remove_old_user.subject")) do |format|
format.text { render "notifier/plain_markdown_email", locals: {body: body} }
format.html { render "notifier/plain_markdown_email", locals: {body: body} }
end
end
end

View file

@ -24,33 +24,28 @@ class Notifier < ApplicationMailer
}
end
unless subject
subject = I18n.t('notifier.single_admin.subject')
end
subject ||= I18n.t("notifier.single_admin.subject")
default_opts = {:to => @receiver.email,
:from => AppConfig.mail.sender_address,
:subject => subject, :host => AppConfig.pod_uri.host}
default_opts = {to: @receiver.email, from: AppConfig.mail.sender_address, subject: subject}
default_opts.merge!(opts)
mail(default_opts) do |format|
format.text
format.html
end
mail(default_opts)
end
def invite(email, inviter, invitation_code, locale)
@inviter = inviter
@invitation_code = invitation_code
I18n.with_locale(locale) do
mail_opts = {to: email, from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>",
subject: I18n.t("notifier.invited_you", name: @inviter.name),
host: AppConfig.pod_uri.host}
subject: I18n.t("notifier.invited_you", name: inviter.name)}
name = inviter.full_name.empty? ? inviter.diaspora_handle : "#{inviter.name} (#{inviter.diaspora_handle})"
body = I18n.t("notifier.invite.message",
invite_url: invite_code_url(invitation_code),
diasporafoundation_url: "https://diasporafoundation.org/",
user: name,
diaspora_id: inviter.diaspora_handle)
mail(mail_opts) do |format|
format.text { render :layout => nil }
format.html { render :layout => nil }
format.text { render "notifier/plain_markdown_email", layout: nil, locals: {body: body} }
format.html { render "notifier/plain_markdown_email", layout: nil, locals: {body: body} }
end
end
end

View file

@ -26,9 +26,10 @@ class ReportMailer < ApplicationMailer
private
def format(resource)
body = I18n.t("notifier.report_email.body", resource)
mail(to: resource[:email], subject: I18n.t("notifier.report_email.subject", type: resource[:type])) do |format|
format.html { render "report/report_email", locals: {resource: resource} }
format.text { render "report/report_email", locals: {resource: resource} }
format.html { render "notifier/plain_markdown_email", locals: {body: body} }
format.text { render "notifier/plain_markdown_email", locals: {body: body} }
end
end
end

View file

@ -0,0 +1,6 @@
%p
= t("devise.mailer.welcome", username: @resource.username)
%p
= t(".you_can_confirm")
%p
= link_to t(".confirm"), confirmation_url(@resource, confirmation_token: @token)

View file

@ -1,7 +0,0 @@
<%= t('devise.mailer.welcome', username: @resource.username) %>
<%= t('.you_can_confirm') %>
[<%= t('.confirm') %>][1]
[1]: <%= confirmation_url(@resource, confirmation_token: @token) %>

View file

@ -0,0 +1,4 @@
<%= t("devise.mailer.welcome", username: @resource.username) %>
<%= t(".you_can_confirm") %>
<%= confirmation_url(@resource, confirmation_token: @token) %>

View file

@ -1 +0,0 @@
<%= t('.message', :invite_url => invite_code_url(@invitation_code)) %>

View file

@ -0,0 +1,12 @@
%p
= t("devise.mailer.hello", username: @resource.username)
%p
= t(".someone_requested")
%p
= link_to t(".change"), edit_password_url(@resource, reset_password_token: @token)
%p
= t(".then_connect", username: @resource.username)
%p
= t(".wont_change")
%p
= t(".ignore")

View file

@ -1,13 +0,0 @@
<%= t('devise.mailer.hello', username: @resource.username) %>
<%= t('.someone_requested') %>
[<%= t('.change') %>][1]
[1]: <%= edit_password_url(@resource, reset_password_token: @token) %>
<%= t('.then_connect', username: @resource.username) %>
<%= t('.wont_change') %>
<%= t('.ignore') %>

View file

@ -0,0 +1,11 @@
<%= t("devise.mailer.hello", username: @resource.username) %>
<%= t(".someone_requested") %>
<%= t(".change") %>: <%= edit_password_url(@resource, reset_password_token: @token) %>
<%= t(".then_connect", username: @resource.username) %>
<%= t(".wont_change") %>
<%= t(".ignore") %>

View file

@ -0,0 +1,8 @@
%p
= t("devise.mailer.hello", username: @resource.username)
%p
= t(".account_locked")
%p
= t(".click_to_unlock")
%p
= link_to t(".unlock"), unlock_url(@resource, unlock_token: @token)

View file

@ -1,9 +0,0 @@
<%= t('devise.mailer.hello', username: @resource.username) %>
<%= t('.account_locked') %>
<%= t('.click_to_unlock') %>
[<%= t('.unlock') %>][1]
[1]: <%= unlock_url(@resource, unlock_token: @token) %>

View file

@ -0,0 +1,6 @@
<%= t("devise.mailer.hello", username: @resource.username) %>
<%= t(".account_locked") %>
<%= t(".click_to_unlock") %>
<%= unlock_url(@resource, unlock_token: @token) %>

View file

@ -1,7 +1,7 @@
%table{cellspacing: 0, cellpadding: 0, border: 0,
style: "font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px"}
%tr
- if @notification.try(:sender)
- if @notification&.sender.present?
%td{width: "60px", style: "vertical-align: top"}>
%div{style: "background-color: #eee; height: 50px; width: 50px"}
= image_tag @notification.sender.profile.image_url(:thumb_small), alt: @notification.sender.name,

View file

@ -1,4 +1,5 @@
!= yield
!= "-- "
!= t("notifier.email_sent_by_diaspora", pod_name: pod_name)
!= t("notifier.to_change_your_notification_settings")
!= edit_user_url
!= "#{t('notifier.to_change_your_notification_settings')}: #{edit_user_url}"

View file

@ -1,2 +0,0 @@
<%= t('notifier.remove_old_user.body', pod_url: @pod_url, login_url: @login_url, after_days: @after_days, remove_after: @remove_after) %>

View file

@ -1,28 +0,0 @@
:css
body{
width:600px;
font-family: 'Helvetica',sans-serif;
}
#container{
}
header{
margin-bottom: 25px;
}
p{
padding:5px;
}
p.small{
font-size:smaller;
color:#999;
font-style:italic;
}
a{
color:#107FC9;
font-weight:bold;
}
a:hover{
color: #22AAE0;
}
a:active{
color: #005D9C;
}

View file

@ -0,0 +1,5 @@
%p
= comment_message(@notification.comment, process_newlines: true)
%p
= link_to t("notifier.comment_on_post.reply", name: @notification.comment.post.author_first_name),
post_url(@notification.comment.post, anchor: @notification.comment.guid)

View file

@ -1,5 +0,0 @@
<%= comment_message(@notification.comment, :process_newlines => true) %>
[<%= t('notifier.comment_on_post.reply', :name => @notification.comment_post.author_first_name) %>][1]
[1]: <%= post_url(@notification.comment_post, anchor: @notification.comment.guid) %>

View file

@ -0,0 +1,4 @@
<%= comment_message(@notification.comment) %>
<%= t("notifier.comment_on_post.reply", name: @notification.comment.post.author_first_name) %>
<%= post_url(@notification.comment.post, anchor: @notification.comment.guid) %>

View file

@ -0,0 +1,5 @@
%p
= comment_message(@notification.comment, process_newlines: true)
%p
= link_to t("notifier.comment_on_post.reply", name: @notification.comment.post.author_first_name),
post_url(@notification.comment.post, anchor: @notification.comment.guid)

View file

@ -1,5 +0,0 @@
<%= comment_message(@notification.comment, :process_newlines => true) %>
[<%= t('notifier.comment_on_post.reply', :name => @notification.comment.parent_author_name) %>][1]
[1]: <%= post_url(@notification.comment.post, anchor: @notification.comment.guid) %>

View file

@ -0,0 +1,4 @@
<%= comment_message(@notification.comment) %>
<%= t("notifier.comment_on_post.reply", name: @notification.comment.post.author_first_name) %>
<%= post_url(@notification.comment.post, anchor: @notification.comment.guid) %>

View file

@ -0,0 +1,6 @@
%p
= t("notifier.hello", name: @notification.recipient_first_name)
%p
= t("notifier.confirm_email.click_link", unconfirmed_email: @notification.recipient_unconfirmed_email)
%p
= link_to nil, confirm_email_url(token: @notification.recipient_confirm_email_token)

View file

@ -1,5 +0,0 @@
<%= t('notifier.hello', :name => @notification.recipient_first_name) %>
<%= t('notifier.confirm_email.click_link', :unconfirmed_email => @notification.recipient_unconfirmed_email) %>
<<%= confirm_email_url(:token => @notification.recipient_confirm_email_token) %>>

View file

@ -0,0 +1,5 @@
<%= t("notifier.hello", name: @notification.recipient_first_name) %>
<%= t("notifier.confirm_email.click_link", unconfirmed_email: @notification.recipient_unconfirmed_email) %>
<%= confirm_email_url(token: @notification.recipient_confirm_email_token) %>

View file

@ -0,0 +1,5 @@
%p
= t(".birthday", name: @notification.person.name)
%p
= link_to t(".view_profile", name: @notification.person.first_name),
local_or_remote_person_path(@notification.person, absolute: true)

View file

@ -1,6 +0,0 @@
<%= t(".birthday", name: @notification.person.name) %>
[<%= t(".view_profile", name: @notification.person.name) %>][1]
[1]: <%= local_or_remote_person_path(@notification.person, absolute: true) %>

View file

@ -0,0 +1,4 @@
<%= t(".birthday", name: @notification.person.name) %>
<%= t(".view_profile", name: @notification.person.first_name) %>
<%= local_or_remote_person_path(@notification.person, absolute: true) %>

View file

@ -0,0 +1,4 @@
- message = t("notifier.csrf_token_fail.body",
name: @notification.recipient_first_name,
link: "https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)")
!= Redcarpet::Markdown.new(Diaspora::Markdownify::Email).render(message)

View file

@ -1 +0,0 @@
<%= t("notifier.csrf_token_fail.body", name: @notification.recipient_first_name, link: "https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)") %>

View file

@ -0,0 +1,3 @@
<%= t("notifier.csrf_token_fail.body",
name: @notification.recipient_first_name,
link: "https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)") %>

View file

@ -1,6 +0,0 @@
<%= t('.message',
invite_url: invite_code_url(@invitation_code),
diasporafoundation_url: 'https://diasporafoundation.org/',
user: @inviter.try(:full_name).empty? ? @inviter.try(:diaspora_handle) : "#{@inviter.name} (#{@inviter.diaspora_handle})",
diaspora_id: @inviter.try(:diaspora_handle))
%>

View file

@ -0,0 +1,11 @@
- if @notification.like_target.public?
%p
#{t('.liked', name: @notification.sender_name)}:
%p
= post_message(@notification.like_target, process_newlines: true)
- else
%p
#{t('notifier.liked.limited_post', name: @notification.sender_name)}.
%p
= link_to t(".view_post"), post_url(@notification.like_target)

View file

@ -1,11 +0,0 @@
<% if @notification.like_target.public? %>
<%= "#{t('.liked', :name => "#{@notification.sender_name}")}:" %>
<%= post_message(@notification.like_target, :process_newlines => true) %>
<% else %>
<%= "#{t('notifier.liked.limited_post', :name => "#{@notification.sender_name}")}." %>
<% end %>
[<%= t('.view_post') %>][1]
[1]: <%= post_url(@notification.like_target) %>

View file

@ -0,0 +1,10 @@
<% if @notification.like_target.public? %>
<%= "#{t(".liked", name: @notification.sender_name)}:" %>
<%= post_message(@notification.like_target) %>
<% else %>
<%= "#{t("notifier.liked.limited_post", name: @notification.sender_name)}." %>
<% end %>
<%= t(".view_post") %>
<%= post_url(@notification.like_target) %>

View file

@ -0,0 +1,10 @@
- if @notification.post.public?
%p
= post_message(@notification.post, process_newlines: true)
- else
%p
= t("notifier.mentioned.limited_post")
%p
= link_to t("notifier.comment_on_post.reply", name: @notification.post.author_first_name),
post_url(@notification.post)

View file

@ -1,9 +0,0 @@
<% if @notification.post.public? %>
<%= post_message(@notification.post, :process_newlines => true) %>
<% else %>
<%= t('notifier.mentioned.limited_post') %>
<% end %>
[<%= t("notifier.comment_on_post.reply", name: @notification.post_author_name) %>][1]
[1]: <%= post_url(@notification.post) %>

View file

@ -0,0 +1,8 @@
<% if @notification.post.public? %>
<%= post_message(@notification.post) %>
<% else %>
<%= t("notifier.mentioned.limited_post") %>
<% end %>
<%= t("notifier.comment_on_post.reply", name: @notification.post.author_first_name) %>
<%= post_url(@notification.post) %>

View file

@ -0,0 +1,10 @@
- if @notification.comment.public?
%p
= @notification.comment.message.plain_text_without_markdown
- else
%p
= t("notifier.mentioned_in_comment.limited_post")
%p
= link_to t("notifier.mentioned_in_comment.reply"),
post_url(@notification.comment.post, anchor: @notification.comment.guid)

View file

@ -4,6 +4,5 @@
<%= t("notifier.mentioned_in_comment.limited_post") %>
<% end %>
[<%= t("notifier.mentioned_in_comment.reply") %>][1]
[1]: <%= post_url(@notification.comment.parent, anchor: @notification.comment.guid) %>
<%= t("notifier.mentioned_in_comment.reply") %>
<%= post_url(@notification.comment.parent, anchor: @notification.comment.guid) %>

View file

@ -0,0 +1,2 @@
%div{style: "font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px"}
!= Redcarpet::Markdown.new(Diaspora::Markdownify::Email).render(body)

View file

@ -0,0 +1 @@
!= body

View file

@ -0,0 +1,4 @@
%p
= t("notifier.a_private_message")
%p
= link_to t(".reply_to_or_view"), conversations_url(conversation_id: @notification.conversation)

View file

@ -1,5 +0,0 @@
<%= t('notifier.a_private_message') %>
[<%= t('.reply_to_or_view') %>][1]
[1]: <%= conversations_url(:conversation_id => @notification.conversation) %>

View file

@ -0,0 +1,4 @@
<%= t("notifier.a_private_message") %>
<%= t(".reply_to_or_view") %>
<%= conversations_url(conversation_id: @notification.conversation) %>

View file

@ -0,0 +1,6 @@
%p
#{t('.reshared', name: @notification.sender_name)}:
%p
= post_message(@notification.reshare_root, process_newlines: true)
%p
= link_to t(".view_post"), post_url(@notification.reshare)

View file

@ -1,7 +0,0 @@
<%= "#{t('.reshared', :name => "#{@notification.sender_name}")}:" %>
<%= post_message(@notification.reshare_root, :process_newlines => true) %>
[<%= t('.view_post') %>][1]
[1]: <%= post_url(@notification.reshare) %>

View file

@ -0,0 +1,6 @@
<%= "#{t(".reshared", name: @notification.sender_name)}:" %>
<%= post_message(@notification.reshare_root) %>
<%= t(".view_post") %>
<%= post_url(@notification.reshare) %>

View file

@ -0,0 +1,8 @@
%p
= t("notifier.hello", name: @receiver.username)
%p
= @string
%p
= t("notifier.thanks")
%br/
= t("notifier.single_admin.admin")

View file

@ -1,7 +0,0 @@
<%= t('notifier.hello', :name => @receiver.username) %>
<%= @string %>
<%= t('notifier.thanks') %>
<%= t('notifier.single_admin.admin') %>

View file

@ -0,0 +1,6 @@
<%= t("notifier.hello", name: @receiver.username) %>
<%= @string %>
<%= t("notifier.thanks") %>
<%= t("notifier.single_admin.admin") %>

View file

@ -0,0 +1,7 @@
%p
= @notification.sender_name
= t(".sharing")
%p
= link_to t(".view_profile", name: @notification.sender_first_name),
local_or_remote_person_path(@notification.sender, absolute: true)

View file

@ -1,5 +0,0 @@
<%= @notification.sender_name %> <%= t('.sharing') %>
[<%= t('.view_profile', :name => @notification.sender_first_name) %>][1]
[1]: <%= local_or_remote_person_path(@notification.sender, :absolute => true) %>

View file

@ -0,0 +1,4 @@
<%= @notification.sender_name %> <%= t(".sharing") %>
<%= t(".view_profile", name: @notification.sender_first_name) %>
<%= local_or_remote_person_path(@notification.sender, absolute: true) %>

View file

@ -1,5 +0,0 @@
<%= t("notifier.report_email.body",
url: resource[:url],
type: resource[:type],
id: resource[:id],
reason: resource[:reason]) %>

View file

@ -1 +0,0 @@
<%= t('notifier.export_email.body', url: download_profile_user_url, name: @user.first_name) %>

View file

@ -1 +0,0 @@
<%= t('notifier.export_failure_email.body', name: @user.first_name) %>

View file

@ -1 +0,0 @@
<%= t('notifier.export_photos_email.body', url: download_photos_user_url, name: @user.first_name) %>

View file

@ -1 +0,0 @@
<%= t('notifier.export_photos_failure_email.body', name: @user.first_name) %>

View file

@ -1,3 +0,0 @@
# frozen_string_literal: true
Rails.application.config.markerb.renderer = Diaspora::Markdownify::Email

View file

@ -724,7 +724,7 @@ en:
started_sharing:
subject: "%{name} started sharing with you on diaspora*"
sharing: "has started sharing with you!"
view_profile: "View %{name}s profile"
view_profile: "View %{name}s profile >"
comment_on_post:
limited_subject: "There's a new comment on one of your posts"
reply: "Reply or view %{name}s post >"
@ -749,7 +749,7 @@ en:
contacts_birthday:
subject: "%{name} has their birthday today"
birthday: "%{name} has their birthday today. Wish them 'Happy Birthday'!"
view_profile: "View %{name}s profile"
view_profile: "View %{name}s profile >"
confirm_email:
subject: "Please activate your new email address %{unconfirmed_email}"
click_link: "To activate your new email address %{unconfirmed_email}, please follow this link:"

View file

@ -12,8 +12,8 @@ describe Workers::ResetPassword do
Workers::ResetPassword.new.perform(alice.id)
mail = Devise.mailer.deliveries.last
expect(mail.to).to eq([alice.email])
expect(mail.body).to include("change your password")
expect(mail.body).to include(alice.username)
expect(mail.body.encoded).to include("change your password")
expect(mail.body.encoded).to include(alice.username)
end
end
end