Read about our upcoming Code of Conduct on this issue

Commit 85414834 authored by Brett Walker's avatar Brett Walker Committed by Douglas Barbosa Alexandre
Browse files

Allow disabling group/project email notifications

- Adds UI to configure in group and project settings
- Removes notification configuration for users when
disabled at group or project level
parent fca952c4595f
......@@ -2315,6 +2315,57 @@
end
end
describe '#emails_disabled?' do
let(:project) { create(:project, emails_disabled: false) }
context 'emails disabled in group' do
it 'returns true' do
allow(project.namespace).to receive(:emails_disabled?) { true }
expect(project.emails_disabled?).to be_truthy
end
end
context 'emails enabled in group' do
before do
allow(project.namespace).to receive(:emails_disabled?) { false }
end
it 'returns false' do
expect(project.emails_disabled?).to be_falsey
end
it 'returns true' do
project.update_attribute(:emails_disabled, true)
expect(project.emails_disabled?).to be_truthy
end
end
context 'when :emails_disabled feature flag is off' do
before do
stub_feature_flags(emails_disabled: false)
end
context 'emails disabled in group' do
it 'returns false' do
allow(project.namespace).to receive(:emails_disabled?) { true }
expect(project.emails_disabled?).to be_falsey
end
end
context 'emails enabled in group' do
it 'returns false' do
allow(project.namespace).to receive(:emails_disabled?) { false }
project.update_attribute(:emails_disabled, true)
expect(project.emails_disabled?).to be_falsey
end
end
end
end
describe '#lfs_enabled?' do
let(:project) { create(:project) }
......
......@@ -86,6 +86,7 @@
context "unauthorized visibility_level validation" do
let!(:service) { described_class.new(internal_group, user, visibility_level: 99) }
before do
internal_group.add_user(user, Gitlab::Access::MAINTAINER)
end
......@@ -96,6 +97,20 @@
end
end
context 'when updating #emails_disabled' do
let(:service) { described_class.new(internal_group, user, emails_disabled: true) }
it 'updates the attribute' do
internal_group.add_user(user, Gitlab::Access::OWNER)
expect { service.execute }.to change { internal_group.emails_disabled }.to(true)
end
it 'does not update when not group owner' do
expect { service.execute }.not_to change { internal_group.emails_disabled }
end
end
context 'rename group' do
let!(:service) { described_class.new(internal_group, user, path: SecureRandom.hex) }
......
This diff is collapsed.
......@@ -369,9 +369,28 @@
end
end
context 'when updating #emails_disabled' do
it 'updates the attribute for the project owner' do
expect { update_project(project, user, emails_disabled: true) }
.to change { project.emails_disabled }
.to(true)
end
it 'does not update when not project owner' do
maintainer = create(:user)
project.add_user(maintainer, :maintainer)
expect { update_project(project, maintainer, emails_disabled: true) }
.not_to change { project.emails_disabled }
end
end
context 'with external authorization enabled' do
before do
enable_external_authorization_service_check
allow(::Gitlab::ExternalAuthorization)
.to receive(:access_allowed?).with(user, 'default_label', project.full_path).and_call_original
end
it 'does not save the project with an error if the service denies access' do
......@@ -402,8 +421,7 @@
end
it 'does not check the label when it does not change' do
expect(::Gitlab::ExternalAuthorization)
.not_to receive(:access_allowed?)
expect(::Gitlab::ExternalAuthorization).to receive(:access_allowed?).once
update_project(project, user, { name: 'New name' })
end
......
......@@ -31,6 +31,10 @@ def should_not_email_anyone
expect(ActionMailer::Base.deliveries).to be_empty
end
def should_email_anyone
expect(ActionMailer::Base.deliveries).not_to be_empty
end
def email_recipients(kind: :to)
ActionMailer::Base.deliveries.flat_map(&kind)
end
......
# frozen_string_literal: true
# Note that we actually update the attribute on the target_project/group, rather than
# using `allow`. This is because there are some specs where, based on how the notification
# is done, using an `allow` doesn't change the correct object.
shared_examples 'project emails are disabled' do
let(:target_project) { notification_target.is_a?(Project) ? notification_target : notification_target.project }
before do
reset_delivered_emails!
target_project.clear_memoization(:emails_disabled)
end
it 'sends no emails with project emails disabled' do
target_project.update_attribute(:emails_disabled, true)
notification_trigger
should_not_email_anyone
end
it 'sends emails to someone' do
target_project.update_attribute(:emails_disabled, false)
notification_trigger
should_email_anyone
end
end
shared_examples 'group emails are disabled' do
let(:target_group) { notification_target.is_a?(Group) ? notification_target : notification_target.project.group }
before do
reset_delivered_emails!
target_group.clear_memoization(:emails_disabled)
end
it 'sends no emails with group emails disabled' do
target_group.update_attribute(:emails_disabled, true)
notification_trigger
should_not_email_anyone
end
it 'sends emails to someone' do
target_group.update_attribute(:emails_disabled, false)
notification_trigger
should_email_anyone
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