diff --git a/app/jobs/notify_delivery_job.rb b/app/jobs/notify_delivery_job.rb index 71c9c5830..15a0cfe27 100644 --- a/app/jobs/notify_delivery_job.rb +++ b/app/jobs/notify_delivery_job.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true +require "notifications/client" + class NotifyDeliveryJob < ApplicationJob - queue_as { Rails.configuration.action_mailer.deliver_later_queue_name } + queue_as :mailer def self.client @client ||= Notifications::Client.new( - Rails.configuration.action_mailer.notify_settings[:api_key] + Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"] ) end @@ -15,11 +17,11 @@ def self.deliveries end def self.send_via_notify? - Rails.configuration.action_mailer.delivery_method == :notify + Settings.govuk_notify&.enabled end def self.send_via_test? - Rails.configuration.action_mailer.delivery_method == :test + Rails.env.test? end class UnknownTemplate < StandardError diff --git a/config/application.rb b/config/application.rb index 458f0c4d3..2b0809eaf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -64,8 +64,6 @@ class Application < Rails::Application config.active_job.queue_adapter = :good_job config.good_job.execution_mode = :async - config.action_mailer.deliver_later_queue_name = :mailer - config.view_component.default_preview_layout = "component_preview" config.view_component.preview_controller = "ComponentPreviewsController" config.view_component.preview_paths << Rails.root.join( diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f2d744f4..d22f42f94 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -36,25 +36,6 @@ # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local - # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false - - # Make template changes take effect immediately. - config.action_mailer.perform_caching = false - - # Set localhost to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "localhost", port: 4000 } - - if Settings.govuk_notify&.enabled - config.action_mailer.delivery_method = :notify - config.action_mailer.notify_settings = { - api_key: Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"] - } - else - config.action_mailer.default_options = { from: "no-reply@nhs.net" } - config.action_mailer.delivery_method = :file - end - # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index f8ebde4f6..b1f15257a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -77,27 +77,6 @@ # Replace the default in-process and non-durable queuing backend for Active Job. # config.active_job.queue_adapter = :resque - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { - host: - if Settings.is_review - "#{ENV["HEROKU_APP_NAME"]}.herokuapp.com" - else - Settings.host - end, - protocol: "https" - } - - # Configure GOV.UK Notify. - config.action_mailer.delivery_method = :notify - config.action_mailer.notify_settings = { - api_key: Settings.govuk_notify.live_key - } - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 8fc7962f0..8d0e2a5dd 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -20,8 +20,4 @@ description: "Track the status of DPS exports" } ) - - config.action_mailer.notify_settings = { - api_key: Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"] - } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 9f77a34d9..d91a781d5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -35,15 +35,6 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - - # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "localhost:4000" } - config.action_mailer.default_options = { from: "no-reply@nhs.net" } - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/settings/test.yml b/config/settings/test.yml index aa41f3d54..78f5734a4 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -7,6 +7,10 @@ cis2: issuer: "http://localhost:4000/test/oidc" client_id: "31337.apps.national" +govuk_notify: + enabled: false + mode: test + mesh: base_url: https://localhost:8700 disable_ssl_verification: true diff --git a/spec/jobs/email_delivery_job_spec.rb b/spec/jobs/email_delivery_job_spec.rb index 24fc1a5a9..b941fc558 100644 --- a/spec/jobs/email_delivery_job_spec.rb +++ b/spec/jobs/email_delivery_job_spec.rb @@ -2,11 +2,11 @@ describe EmailDeliveryJob do before(:all) do - Rails.configuration.action_mailer.delivery_method = :notify - Rails.configuration.action_mailer.notify_settings = { api_key: "abc" } + Settings.govuk_notify.enabled = true + Settings.govuk_notify.test_key = "abc" end - after(:all) { Rails.configuration.action_mailer.delivery_method = :test } + after(:all) { Settings.govuk_notify.enabled = false } let(:response) do instance_double( diff --git a/spec/jobs/sms_delivery_job_spec.rb b/spec/jobs/sms_delivery_job_spec.rb index 14f188295..570a096d9 100644 --- a/spec/jobs/sms_delivery_job_spec.rb +++ b/spec/jobs/sms_delivery_job_spec.rb @@ -2,11 +2,11 @@ describe SMSDeliveryJob do before(:all) do - Rails.configuration.action_mailer.delivery_method = :notify - Rails.configuration.action_mailer.notify_settings = { api_key: "abc" } + Settings.govuk_notify.enabled = true + Settings.govuk_notify.test_key = "abc" end - after(:all) { Rails.configuration.action_mailer.delivery_method = :test } + after(:all) { Settings.govuk_notify.enabled = false } let(:response) do instance_double(