Commit 7dab4bc5 authored by Robert Speicher's avatar Robert Speicher

Add a NullNotificationService

When a group member is an LDAP user, we use this service in place of
NotificationService in order to avoid sending them notifications about
group and project memberships.
parent 46ba8b07
......@@ -3,6 +3,7 @@
module EE
module Member
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
attr_accessor :skip_notification
......@@ -19,5 +20,15 @@ module EE
}
end
end
override :notification_service
def notification_service
if ldap
# LDAP users shouldn't receive notifications about membership changes
::EE::NullNotificationService.new
else
super
end
end
end
end
# frozen_string_literal: true
# This class can be used as a drop-in for NotificationService in order to
# prevent sending notifications.
#
# It will respond to any message that NotificationService responds to with
# itself in order to support method chaining.
module EE
class NullNotificationService
def method_missing(name, *)
if respond_to_missing?(name)
self
else
super
end
end
def respond_to_missing?(name, *)
::NotificationService.method_defined?(name)
end
end
end
# frozen_string_literal: true
require 'rails_helper'
describe Member, type: :model do
describe '#notification_service' do
it 'returns a NullNotificationService instance for LDAP users' do
member = described_class.new
allow(member).to receive(:ldap).and_return(true)
expect(member.__send__(:notification_service))
.to be_instance_of(::EE::NullNotificationService)
end
end
end
# frozen_string_literal: true
require 'rails_helper'
describe ::EE::NullNotificationService do
it 'responds to methods implemented by NotificationService' do
method = NotificationService.instance_methods(false).sample
expect(subject.public_send(method)).to be_instance_of(described_class)
end
it 'raises NoMethodError for methods not implemented by NotificationService' do
expect { subject.not_a_real_method }.to raise_error(NoMethodError)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment