diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-03-23 10:34:20 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-03-23 10:34:20 +0000 |
commit | 3b39ce325263028553c6019cc894024c207644ea (patch) | |
tree | d60ffe7af7f2fbb2a304f66aedfece3c2bc45b7f /spec/services | |
parent | 0c0f925339df3ca53c1840befd087f51d2b1f6f4 (diff) | |
parent | 8ca5b33175ae809fabc0d88bf16b0325e59f7203 (diff) | |
download | gitlab-ce-3b39ce325263028553c6019cc894024c207644ea.tar.gz |
Merge branch 'notifications-for-subscribers-confidential-issue-labels' into 'master'
Restrict notifications for confidential issues
Closes #14468
/cc @rymai
See merge request !3334
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 88 |
2 files changed, 94 insertions, 1 deletions
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 4ffe753fef5..6b214a0d96b 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -151,7 +151,12 @@ describe Issues::UpdateService, services: true do context 'when the issue is relabeled' do let!(:non_subscriber) { create(:user) } - let!(:subscriber) { create(:user).tap { |u| label.toggle_subscription(u) } } + let!(:subscriber) do + create(:user).tap do |u| + label.toggle_subscription(u) + project.team << [u, :developer] + end + end it 'sends notifications for subscribers of newly added labels' do opts = { label_ids: [label.id] } diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index b5407397c1d..0f2aa3ae73c 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -111,6 +111,33 @@ describe NotificationService, services: true do end end + context 'confidential issue note' do + let(:project) { create(:empty_project, :public) } + let(:author) { create(:user) } + let(:assignee) { create(:user) } + let(:non_member) { create(:user) } + let(:member) { create(:user) } + let(:admin) { create(:admin) } + let(:confidential_issue) { create(:issue, :confidential, project: project, author: author, assignee: assignee) } + let(:note) { create(:note_on_issue, noteable: confidential_issue, project: project, note: "#{author.to_reference} #{assignee.to_reference} #{non_member.to_reference} #{member.to_reference} #{admin.to_reference}") } + + it 'filters out users that can not read the issue' do + project.team << [member, :developer] + + expect(SentNotification).to receive(:record).with(confidential_issue, any_args).exactly(4).times + + ActionMailer::Base.deliveries.clear + + notification.new_note(note) + + should_not_email(non_member) + should_email(author) + should_email(assignee) + should_email(member) + should_email(admin) + end + end + context 'issue note mention' do let(:project) { create(:empty_project, :public) } let(:issue) { create(:issue, project: project, assignee: create(:user)) } @@ -233,6 +260,36 @@ describe NotificationService, services: true do should_email(subscriber) end + + context 'confidential issues' do + let(:author) { create(:user) } + let(:assignee) { create(:user) } + let(:non_member) { create(:user) } + let(:member) { create(:user) } + let(:admin) { create(:admin) } + let(:confidential_issue) { create(:issue, :confidential, project: project, title: 'Confidential issue', author: author, assignee: assignee) } + + it "emails subscribers of the issue's labels that can read the issue" do + project.team << [member, :developer] + + label = create(:label, issues: [confidential_issue]) + label.toggle_subscription(non_member) + label.toggle_subscription(author) + label.toggle_subscription(assignee) + label.toggle_subscription(member) + label.toggle_subscription(admin) + + ActionMailer::Base.deliveries.clear + + notification.new_issue(confidential_issue, @u_disabled) + + should_not_email(non_member) + should_not_email(author) + should_email(assignee) + should_email(member) + should_email(admin) + end + end end describe :reassigned_issue do @@ -332,6 +389,37 @@ describe NotificationService, services: true do should_not_email(subscriber_to_label) should_email(subscriber_to_label2) end + + context 'confidential issues' do + let(:author) { create(:user) } + let(:assignee) { create(:user) } + let(:non_member) { create(:user) } + let(:member) { create(:user) } + let(:admin) { create(:admin) } + let(:confidential_issue) { create(:issue, :confidential, project: project, title: 'Confidential issue', author: author, assignee: assignee) } + let!(:label_1) { create(:label, issues: [confidential_issue]) } + let!(:label_2) { create(:label) } + + it "emails subscribers of the issue's labels that can read the issue" do + project.team << [member, :developer] + + label_2.toggle_subscription(non_member) + label_2.toggle_subscription(author) + label_2.toggle_subscription(assignee) + label_2.toggle_subscription(member) + label_2.toggle_subscription(admin) + + ActionMailer::Base.deliveries.clear + + notification.relabeled_issue(confidential_issue, [label_2], @u_disabled) + + should_not_email(non_member) + should_email(author) + should_email(assignee) + should_email(member) + should_email(admin) + end + end end describe :close_issue do |