diff --git a/app/mailers/updated_terms_mailer.rb b/app/mailers/updated_terms_mailer.rb new file mode 100644 index 0000000000..2833158eec --- /dev/null +++ b/app/mailers/updated_terms_mailer.rb @@ -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 diff --git a/app/views/updated_terms_mailer/notify.html.erb b/app/views/updated_terms_mailer/notify.html.erb new file mode 100644 index 0000000000..5fe547cbe6 --- /dev/null +++ b/app/views/updated_terms_mailer/notify.html.erb @@ -0,0 +1,131 @@ +<%= render "shared/header" %> + + + + + +
+ + + + +
 
+
+ + +
+
+
+ <%= I18n.t(:"mails_notifications.updated_terms.hello", name: @name) %> +
+ + + + +
 
+
+ <%= I18n.t("mails_notifications.updated_terms.title") %> +
+ + + + +
 
+
+
+ <%= I18n.t(:"mails_notifications.updated_terms.body") %> +
+
+
+ + + + + +
 
+ + + + +
+ + + + + +
+ + + + + +
+ + <%= + link_to(I18n.t('mails_notifications.updated_terms.term_button'), + @accept_terms_url, + :style => "text-decoration: none !important;color: #fff !important;" + ) + %> + + + <%= 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;") %> +
+
+ + + + + +
 
+ +
+
+ <%= t("mails_notifications.updated_terms.more_info") %> +
+
+ +
+ + + + +
 
+ + +<%= render "shared/footer" %> diff --git a/app/views/updated_terms_mailer/notify.text.erb b/app/views/updated_terms_mailer/notify.text.erb new file mode 100644 index 0000000000..a1a22f6eec --- /dev/null +++ b/app/views/updated_terms_mailer/notify.text.erb @@ -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 diff --git a/app/workers/terms_of_service_update_worker.rb b/app/workers/terms_of_service_update_worker.rb new file mode 100644 index 0000000000..d720c08a2b --- /dev/null +++ b/app/workers/terms_of_service_update_worker.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ed46bd9f0..a00f184b91 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/db/migrate/20240304160338_add_last_received_terms_email_at_to_users.rb b/db/migrate/20240304160338_add_last_received_terms_email_at_to_users.rb new file mode 100644 index 0000000000..9740702180 --- /dev/null +++ b/db/migrate/20240304160338_add_last_received_terms_email_at_to_users.rb @@ -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 diff --git a/test/mailers/updated_terms_mailer_test.rb b/test/mailers/updated_terms_mailer_test.rb new file mode 100644 index 0000000000..0ab0435546 --- /dev/null +++ b/test/mailers/updated_terms_mailer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class UpdatedTermsMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/workers/terms_of_service_update_worker_test.rb b/test/workers/terms_of_service_update_worker_test.rb new file mode 100644 index 0000000000..6b94e431ae --- /dev/null +++ b/test/workers/terms_of_service_update_worker_test.rb @@ -0,0 +1,9 @@ +require_relative '../test_helper' + +class TermsOfServiceUpdateWorkerTest < ActiveSupport::TestCase + def setup + super + require 'sidekiq/testing' + Sidekiq::Testing.inline! + end +end