Skip to content

Commit

Permalink
CV2-2357: add mail worker and template
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Mar 4, 2024
1 parent 00e7074 commit 4a5ed08
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/mailers/updated_terms_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class UpdatedTermsMailer < ApplicationMailer
layout nil

def notify(recipient, name)
@recipient = recipient
@name = name
@accept_terms_url = "#{CheckConfig.get('checkdesk_client')}/check/updated-terms-url"
subject = I18n.t("mails_notifications.updated_terms.subject")
Rails.logger.info "Sending ToS e-mail to #{@recipient}"
mail(to: @recipient, email_type: 'updated_terms', subject: subject)
end
end
131 changes: 131 additions & 0 deletions app/views/updated_terms_mailer/notify.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<%= render "shared/header" %>

<style>
@media only screen and (max-width: 481px) {
.notify-title a {
display: block !important;
width: auto !important;
}
}


@media only screen and (max-width: 601px) {
.notify-title__content {
padding: 0 30px;
}
}


@media only screen and (max-width: 481px) {
.notify-title__content {
padding: 0 !important;
}
}
</style>

<!--~~// Notify-title module start \\~~-->
<!--————————————————————————————-->
<div class="notify-title" style="text-align: <%= @direction[:align] %> !important; direction: <%= @direction[:dir] %>">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 44px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>
<div class="container " width="600" style="margin: 0 auto; text-align: <%= @direction[:align] %>; width: 600px;">
<table class="container__table" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; margin: 0 auto; mso-table-lspace: 0pt; mso-table-rspace: 0pt; table-layout: fixed;">
<tr>
<th class="col-1" style="font-weight: normal; mso-line-height-rule: exactly; padding: 0;" width="600px" valign="top" align="<%= @direction[:align] %>">
<div class="notify-title__content" style="text-align:<%= @direction[:align] %>;">
<div class="h3 notify-title__proj" style="font-size: 21px; letter-spacing: -0.2px; line-height: 29px;">
<%= I18n.t(:"mails_notifications.updated_terms.hello", name: @name) %>
</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 13px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>
<div class="h1 notify-title__header" style="font-size: 40px; font-weight: bold; letter-spacing: -0.8px; line-height: 40px;">
<%= I18n.t("mails_notifications.updated_terms.title") %>
</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 12px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>
<div class="text-gray" style="color: #757575 !important;">
<div class="h3" style="font-size: 21px; letter-spacing: -0.2px; line-height: 30px;">
<%= I18n.t(:"mails_notifications.updated_terms.body") %>
</div>
</div>
</div>

<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 28px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>

<!--————————————————————————————-->
<!--~~\\ Notify-title module end //~~-->

<div class="container wide" width="600" style="margin: 0 auto; text-align: <%= @direction[:align] %>; width: 600px;">

<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td class="notify-title__button text-white" style="background: #2E77FC; border-collapse: collapse; border-radius: 4px; color: #f1f1f1 !important; display: inline-block; padding-bottom: 15px; padding-left: 25px; padding-right: 23px; padding-top: 15px;"
width="auto">
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; padding-right: 14px;">
<span class="span" style="font-size: 17px; font-weight: bold; line-height: 20px;">
<%=
link_to(I18n.t('mails_notifications.updated_terms.term_button'),
@accept_terms_url,
:style => "text-decoration: none !important;color: #fff !important;"
)
%>
</span>
</td>
<td style="border-collapse: collapse;" align="right">
<%= image_tag("https://images.ctfassets.net/g118h5yoccvd/#{@direction[:arrow]}", width: "7", alt: "arrow-icon", style: "-ms-interpolation-mode: bicubic; border: 0 none; height: auto; line-height: 100%; outline: none; text-decoration: none;") %>
</td>
</tr>
</table>
</td>
</tr>
</table>

<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 23px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>

<div class="text-gray" style="color: #757575 !important;">
<div class="h3" style="font-size: 21px; letter-spacing: -0.2px; line-height: 30px;">
<%= t("mails_notifications.updated_terms.more_info") %>
</div>
</div>

</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td style="border-collapse: collapse; font-size: 23px; line-height: 1; text-decoration: none !important;">&nbsp;</td>
</tr>
</table>
<style>
@media only screen and (max-width: 601px) {
th.footer {
padding: 0 30px !important;
}
}


@media only screen and (max-width: 481px) {
th.footer {
padding: 0 !important;
}
}
</style>

<%= render "shared/footer" %>
15 changes: 15 additions & 0 deletions app/views/updated_terms_mailer/notify.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= I18n.t(:"mails_notifications.updated_terms.hello", name: @name) %>
==========================================
<%= I18n.t("mails_notifications.updated_terms.title") %>
==========================================

<%= raw I18n.t(:"mails_notifications.updated_terms.body") %>

<%= I18n.t('mails_notifications.updated_terms.term_button') %>

<%= t("mails_notifications.updated_terms.more_info") %>

...

<%= strip_tags I18n.t("mails_notifications.copyright_html", app_name: CheckConfig.get('app_name')) %>
https://meedan.com
12 changes: 12 additions & 0 deletions app/workers/terms_of_service_update_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class TermsOfServiceUpdateWorker
include Sidekiq::Worker

sidekiq_options queue: 'terms_mailer', retry: 0

def perform
last_updated = User.terms_last_updated_at
User.where('last_received_terms_email_at < ?', last_updated).find_each do |u|
UpdatedTermsMailer.delay({ retry: 0, queue: 'terms_mailer' }).notify(u.email, u.name)
end
end
end
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ en:
hello: Hello %{email}
body: "%{name}, %{email} has invited your organization to contribute to a Check Shared Feed "
view_button: View invitation
updated_terms:
subject: Check Updated Terms of Service
hello: Hello %{name}
title: Updated Terms of Service
body: We have made updates to our Terms of Services for Check users.
We are sending this notification to everyone with a Check account. Continued use for Check following the update
constitutes acceptance of our updated Terms of Service.
term_button: Terms of Service
more_info: This is a one-time required legal notice sent to all Check users, even those who have unsubscribed by optional announcements.
mail_security:
device_subject: 'Security alert: New login to %{app_name} from %{browser} on %{platform}'
ip_subject: 'Security alert: New or unusual %{app_name} login'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddLastReceivedTermsEmailAtToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :last_received_terms_email_at, :integer
User.find_each do |u|
u.update_columns(last_received_terms_email_at: u.last_accepted_terms_at.to_i)
end
end
end
7 changes: 7 additions & 0 deletions test/mailers/updated_terms_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class UpdatedTermsMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end
9 changes: 9 additions & 0 deletions test/workers/terms_of_service_update_worker_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require_relative '../test_helper'

class TermsOfServiceUpdateWorkerTest < ActiveSupport::TestCase
def setup
super
require 'sidekiq/testing'
Sidekiq::Testing.inline!
end
end

0 comments on commit 4a5ed08

Please sign in to comment.