Skip to content

Commit

Permalink
Add the EXTENSION_EMAILS environment flag
Browse files Browse the repository at this point in the history
as per #329
  • Loading branch information
demillir committed Mar 15, 2022
1 parent f952cfe commit 83dfbf1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/mailers/extension_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/mailers/extension_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down

0 comments on commit 83dfbf1

Please sign in to comment.