mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-10 05:06:46 +10:00
Merge branch 'disable_email_option' into 'master'
Disable email option Fixes #1569 See merge request !1222
This commit is contained in:
@@ -39,6 +39,8 @@ production: &base
|
||||
# time_zone: 'UTC'
|
||||
|
||||
## Email settings
|
||||
# Uncomment and set to false if you need to disable email sending from GitLab (default: true)
|
||||
# email_enabled: true
|
||||
# Email address used in the "From" field in mails sent by GitLab
|
||||
email_from: example@example.com
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ Settings.gitlab['https'] = false if Settings.gitlab['https'].nil?
|
||||
Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
|
||||
Settings.gitlab['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] || ''
|
||||
Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http"
|
||||
Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].nil?
|
||||
Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}"
|
||||
Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url)
|
||||
Settings.gitlab['user'] ||= 'git'
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Interceptor in lib/disable_email_interceptor.rb
|
||||
ActionMailer::Base.register_interceptor(DisableEmailInterceptor) unless Gitlab.config.gitlab.email_enabled
|
||||
@@ -0,0 +1,8 @@
|
||||
# Read about interceptors in http://guides.rubyonrails.org/action_mailer_basics.html#intercepting-emails
|
||||
class DisableEmailInterceptor
|
||||
|
||||
def self.delivering_email(message)
|
||||
message.perform_deliveries = false
|
||||
Rails.logger.info "Emails disabled! Interceptor prevented sending mail #{message.subject}"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe DisableEmailInterceptor do
|
||||
before do
|
||||
ActionMailer::Base.register_interceptor(DisableEmailInterceptor)
|
||||
end
|
||||
|
||||
it 'should not send emails' do
|
||||
Gitlab.config.gitlab.stub(:email_enabled).and_return(false)
|
||||
expect {
|
||||
deliver_mail
|
||||
}.not_to change(ActionMailer::Base.deliveries, :count)
|
||||
end
|
||||
|
||||
after do
|
||||
# Removing interceptor from the list because unregister_interceptor is
|
||||
# implemented in later version of mail gem
|
||||
# See: https://github.com/mikel/mail/pull/705
|
||||
Mail.class_variable_set(:@@delivery_interceptors, [])
|
||||
end
|
||||
|
||||
def deliver_mail
|
||||
key = create :personal_key
|
||||
Notify.new_ssh_key_email(key.id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user