From 83dfbf1b2f4ed370c3ca0e4fa994493e77d34609 Mon Sep 17 00:00:00 2001 From: Dan Milliron Date: Tue, 7 Dec 2021 21:16:19 +0000 Subject: [PATCH] Add the EXTENSION_EMAILS environment flag as per https://github.com/sensu/bonsai/issues/329 --- .env.example | 2 ++ app/mailers/extension_mailer.rb | 14 ++++++++++++++ config/application.rb | 2 ++ spec/mailers/extension_mailer_spec.rb | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index db6aa4bc..94282591 100755 --- a/.env.example +++ b/.env.example @@ -69,6 +69,8 @@ PUBSUBHUBBUB_CALLBACK_URL=http://example.com FEATURES=tools,hosted_extensions,private_repos,no_webhook +EXTENSION_EMAILS=false + # optional Fieri variables FIERI_URL=http://example.com FIERI_KEY=YOUR_FIERI_KEY diff --git a/app/mailers/extension_mailer.rb b/app/mailers/extension_mailer.rb index 3d70f7b7..98fd750c 100755 --- a/app/mailers/extension_mailer.rb +++ b/app/mailers/extension_mailer.rb @@ -10,6 +10,8 @@ class ExtensionMailer < ApplicationMailer # @param user [User] the user to notify # def follower_notification_email(extension_version, user) + return unless Rails.configuration.x.extension_emails + @extension_version = extension_version @email_preference = user.email_preference_for('New extension version') @to = user.email @@ -25,6 +27,8 @@ def follower_notification_email(extension_version, user) # @param user [User] the user to notify # def extension_deleted_email(extension, user) + return unless Rails.configuration.x.extension_emails + @extension = extension @email_preference = user.email_preference_for('Extension deleted') @to = user.email @@ -40,6 +44,8 @@ def extension_deleted_email(extension, user) # @param user [User] the user to notify # def extension_disabled_email(extension, user) + return unless Rails.configuration.x.extension_emails + @extension = extension @email_preference = user.email_preference_for('Extension disabled') @to = user.email @@ -57,6 +63,8 @@ def extension_disabled_email(extension, user) # @param user [User] the user to notify # def extension_deprecated_email(extension, replacement_extension, user) + return unless Rails.configuration.x.extension_emails + @extension = extension @replacement_extension = replacement_extension @email_preference = user.email_preference_for('Extension deprecated') @@ -79,6 +87,8 @@ def extension_deprecated_email(extension, replacement_extension, user) # @param transfer_request [OwnershipTransferRequest] # def transfer_ownership_email(transfer_request) + return unless Rails.configuration.x.extension_emails + @transfer_request = transfer_request @sender = transfer_request.sender.name @extension = transfer_request.extension @@ -99,6 +109,8 @@ def transfer_ownership_email(transfer_request) # @param user_id (Fixnum) # def notify_moderator_of_new(extension_id, user_id) + return unless Rails.configuration.x.extension_emails + @extension = Extension.find(extension_id) @moderator = User.find(user_id) @@ -115,6 +127,8 @@ def notify_moderator_of_new(extension_id, user_id) # @param user_id (Fixnum) # def notify_moderator_of_reported(extension_id, user_id, report_description, reported_by_id) + return unless Rails.configuration.x.extension_emails + @extension = Extension.find(extension_id) @moderator = User.find(user_id) @description = report_description diff --git a/config/application.rb b/config/application.rb index b3fb63ea..5880b352 100755 --- a/config/application.rb +++ b/config/application.rb @@ -80,5 +80,7 @@ class Application < Rails::Application require Rails.root.join('lib', 'active_storage_cache_store').to_s config.active_storage_cache = ActiveStorageCacheStore.new + + config.x.extension_emails = ActiveRecord::Type::Boolean.new.cast(ENV.fetch('EXTENSION_EMAILS', true)) end end diff --git a/spec/mailers/extension_mailer_spec.rb b/spec/mailers/extension_mailer_spec.rb index f88f163c..72263a92 100755 --- a/spec/mailers/extension_mailer_spec.rb +++ b/spec/mailers/extension_mailer_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ExtensionMailer do +describe ExtensionMailer, if: Rails.configuration.x.extension_emails do let(:extension) { create :extension } let(:user) { create :user } let(:reporter) { create :user }