From f763d8394e62bbc6d86ed1da9d966fc792d15fe3 Mon Sep 17 00:00:00 2001 From: Leonardo Crauss Daronco Date: Thu, 8 Dec 2016 18:55:41 -0200 Subject: [PATCH] Add flag to enable/disable mail notifications --- app/controllers/bbb_controller.rb | 6 ++- config/application.rb | 61 ++++++++++++++++--------------- sample.env | 5 ++- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/app/controllers/bbb_controller.rb b/app/controllers/bbb_controller.rb index c70ada69..e3766468 100644 --- a/app/controllers/bbb_controller.rb +++ b/app/controllers/bbb_controller.rb @@ -171,8 +171,10 @@ class BbbController < ApplicationController RecordingCreatedJob.perform_later(token, parse_recording_for_view(rec_info)) # send an email to the owner of this recording, if defined - owner = User.find_by(encrypted_id: token) - RecordingReadyEmailJob.perform_later(owner) if owner.present? + if Rails.configuration.mail_notifications + owner = User.find_by(encrypted_id: token) + RecordingReadyEmailJob.perform_later(owner) if owner.present? + end # TODO: remove the webhook now that the meeting and recording are done # remove only if the meeting is not running, otherwise the hook is needed diff --git a/config/application.rb b/config/application.rb index ae422bc7..faba7374 100644 --- a/config/application.rb +++ b/config/application.rb @@ -38,35 +38,38 @@ module Greenlight config.bigbluebutton_endpoint = ENV['BIGBLUEBUTTON_ENDPOINT'] config.bigbluebutton_secret = ENV['BIGBLUEBUTTON_SECRET'] - # GreenLight - config.use_webhooks = ENV['GREENLIGHT_USE_WEBHOOKS'] - config.smtp_from = ENV['SMTP_FROM'] - config.smtp_server = ENV['SMTP_SERVER'] - config.smtp_domain = ENV['SMTP_DOMAIN'] - config.smtp_port = ENV['SMTP_PORT'] || 587 - config.smtp_username = ENV['SMTP_USERNAME'] - config.smtp_password = ENV['SMTP_PASSWORD'] - config.smtp_auth = ENV['SMTP_AUTH'] || "login" - config.smtp_starttls_auto = ENV['SMTP_STARTTLS_AUTO'].nil? ? true : ENV['SMTP_STARTTLS_AUTO'] - config.smtp_tls = ENV['SMTP_TLS'].nil? ? false : ENV['SMTP_TLS'] + config.use_webhooks = ENV['GREENLIGHT_USE_WEBHOOKS'] == "true" + config.mail_notifications = ENV['GREENLIGHT_MAIL_NOTIFICATIONS'] == "true" - # SMTP - config.action_mailer.default_url_options = { host: ENV['GREENLIGHT_DOMAIN'] } - config.action_mailer.delivery_method = :smtp - config.action_mailer.perform_deliveries = true - config.action_mailer.raise_delivery_errors = true - config.action_mailer.smtp_settings = { - :address => config.smtp_server, - :domain => config.smtp_domain, - :port => config.smtp_port, - :user_name => config.smtp_username, - :password => config.smtp_password, - :authentication => config.smtp_auth, - :enable_starttls_auto => config.smtp_starttls_auto, - :tls => config.smtp_tls - } - config.action_mailer.default_options = { - from: config.smtp_from - } + # SMTP and action mailer + if config.mail_notifications + config.smtp_from = ENV['SMTP_FROM'] + config.smtp_server = ENV['SMTP_SERVER'] + config.smtp_domain = ENV['SMTP_DOMAIN'] + config.smtp_port = ENV['SMTP_PORT'] || 587 + config.smtp_username = ENV['SMTP_USERNAME'] + config.smtp_password = ENV['SMTP_PASSWORD'] + config.smtp_auth = ENV['SMTP_AUTH'] || "login" + config.smtp_starttls_auto = ENV['SMTP_STARTTLS_AUTO'].nil? ? true : ENV['SMTP_STARTTLS_AUTO'] + config.smtp_tls = ENV['SMTP_TLS'].nil? ? false : ENV['SMTP_TLS'] + + config.action_mailer.default_url_options = { host: ENV['GREENLIGHT_DOMAIN'] } + config.action_mailer.delivery_method = :smtp + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + config.action_mailer.smtp_settings = { + address: config.smtp_server, + domain: config.smtp_domain, + port: config.smtp_port, + user_name: config.smtp_username, + password: config.smtp_password, + authentication: config.smtp_auth, + enable_starttls_auto: config.smtp_starttls_auto, + tls: config.smtp_tls + } + config.action_mailer.default_options = { + from: config.smtp_from + } + end end end diff --git a/sample.env b/sample.env index 54626cb4..24c8ff8f 100644 --- a/sample.env +++ b/sample.env @@ -20,7 +20,10 @@ GREENLIGHT_USE_WEBHOOKS=false # The web site domain, needed for emails mostly GREENLIGHT_DOMAIN=localhost -# SMTP configurations +# Enable email notifications +GREENLIGHT_MAIL_NOTIFICATIONS=true + +# Email configurations SMTP_FROM=email@gmail.com SMTP_SERVER=smtp.gmail.com SMTP_DOMAIN=gmail.com