From d616a3704f78ca4bea1dedbaa3fdc27991a29729 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 3 Oct 2023 10:15:07 +0100 Subject: [PATCH] Add expiration time to url --- app/jobs/email_missing_addresses_csv_job.rb | 5 +++-- app/mailers/csv_download_mailer.rb | 8 ++++---- spec/jobs/email_missing_addresses_csv_job_spec.rb | 8 ++++---- spec/mailers/csv_download_mailer_spec.rb | 8 ++++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/jobs/email_missing_addresses_csv_job.rb b/app/jobs/email_missing_addresses_csv_job.rb index 23af581c4..685a77d83 100644 --- a/app/jobs/email_missing_addresses_csv_job.rb +++ b/app/jobs/email_missing_addresses_csv_job.rb @@ -2,6 +2,7 @@ class EmailMissingAddressesCsvJob < ApplicationJob queue_as :default BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 + EXPIRATION_TIME = 72.hours.to_i def perform(user_ids, organisation, log_type) csv_service = Csv::MissingAddressesCsvService.new(organisation) @@ -19,13 +20,13 @@ class EmailMissingAddressesCsvJob < ApplicationJob storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"]) storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) - url = storage_service.get_presigned_url(filename, nil) + url = storage_service.get_presigned_url(filename, EXPIRATION_TIME) user_ids.each do |id| user = User.find(id) next if user.blank? - CsvDownloadMailer.new.send(email_method, user, url) + CsvDownloadMailer.new.send(email_method, user, url, EXPIRATION_TIME) end end end diff --git a/app/mailers/csv_download_mailer.rb b/app/mailers/csv_download_mailer.rb index 11bbeef33..b26ae2359 100644 --- a/app/mailers/csv_download_mailer.rb +++ b/app/mailers/csv_download_mailer.rb @@ -11,19 +11,19 @@ class CsvDownloadMailer < NotifyMailer ) end - def send_missing_lettings_addresses_csv_download_mail(user, link) + def send_missing_lettings_addresses_csv_download_mail(user, link, duration) send_email( user.email, CSV_MISSING_LETTINGS_ADDRESSES_DOWNLOAD_TEMPLATE_ID, - { name: user.name, link: }, + { name: user.name, link:, duration: ActiveSupport::Duration.build(duration).inspect }, ) end - def send_missing_sales_addresses_csv_download_mail(user, link) + def send_missing_sales_addresses_csv_download_mail(user, link, duration) send_email( user.email, CSV_MISSING_SALES_ADDRESSES_DOWNLOAD_TEMPLATE_ID, - { name: user.name, link: }, + { name: user.name, link:, duration: ActiveSupport::Duration.build(duration).inspect }, ) end end diff --git a/spec/jobs/email_missing_addresses_csv_job_spec.rb b/spec/jobs/email_missing_addresses_csv_job_spec.rb index a6dfb235b..88c2dccf3 100644 --- a/spec/jobs/email_missing_addresses_csv_job_spec.rb +++ b/spec/jobs/email_missing_addresses_csv_job_spec.rb @@ -39,8 +39,8 @@ describe EmailMissingAddressesCsvJob do end it "sends emails to all the provided users" do - expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[0], test_url) - expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[1], test_url) + expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[0], test_url, instance_of(Integer)) + expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[1], test_url, instance_of(Integer)) job.perform(users.map(&:id), organisation, "lettings") end end @@ -58,8 +58,8 @@ describe EmailMissingAddressesCsvJob do end it "sends emails to all the provided users" do - expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[0], test_url) - expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[1], test_url) + expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[0], test_url, instance_of(Integer)) + expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[1], test_url, instance_of(Integer)) job.perform(users.map(&:id), organisation, "sales") end end diff --git a/spec/mailers/csv_download_mailer_spec.rb b/spec/mailers/csv_download_mailer_spec.rb index 1474527aa..20ea2f1a0 100644 --- a/spec/mailers/csv_download_mailer_spec.rb +++ b/spec/mailers/csv_download_mailer_spec.rb @@ -31,6 +31,7 @@ RSpec.describe CsvDownloadMailer do describe "#send_missing_lettings_addresses_csv_download_mail" do it "sends a CSV download E-mail via notify" do link = :link + duration = 20.minutes.to_i expect(notify_client).to receive(:send_email).with( email_address: user.email, @@ -38,16 +39,18 @@ RSpec.describe CsvDownloadMailer do personalisation: { name: user.name, link:, + duration: "20 minutes", }, ) - described_class.new.send_missing_lettings_addresses_csv_download_mail(user, link) + described_class.new.send_missing_lettings_addresses_csv_download_mail(user, link, duration) end end describe "#send_missing_sales_addresses_csv_download_mail" do it "sends a CSV download E-mail via notify" do link = :link + duration = 20.minutes.to_i expect(notify_client).to receive(:send_email).with( email_address: user.email, @@ -55,10 +58,11 @@ RSpec.describe CsvDownloadMailer do personalisation: { name: user.name, link:, + duration: "20 minutes", }, ) - described_class.new.send_missing_sales_addresses_csv_download_mail(user, link) + described_class.new.send_missing_sales_addresses_csv_download_mail(user, link, duration) end end end