Commit dd1aedef authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'issue_11391' into 'master'

Update moved service desk issues notifications

See merge request gitlab-org/gitlab!25640
parents 1cbc7c17 668cdfcd
......@@ -44,6 +44,8 @@ class Issue < ApplicationRecord
has_many :assignees, class_name: "User", through: :issue_assignees
has_many :zoom_meetings
has_many :user_mentions, class_name: "IssueUserMention", dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :sent_notifications, as: :noteable
has_one :sentry_issue
accepts_nested_attributes_for :sentry_issue
......
---
title: Update moved service desk issues notifications
merge_request: 25640
author:
type: added
......@@ -161,6 +161,10 @@ module EE
IssueLink.inverse_link_type(type)
end
def from_service_desk?
author.id == ::User.support_bot.id
end
class_methods do
extend ::Gitlab::Utils::Override
......
......@@ -5,6 +5,17 @@ module EE
module MoveService
extend ::Gitlab::Utils::Override
override :execute
def execute(issue, target_project)
super
# Updates old issue sent notifications allowing
# to receive service desk emails on the new moved issue.
update_service_desk_sent_notifications
new_entity
end
override :update_old_entity
def update_old_entity
rewrite_epic_issue
......@@ -14,6 +25,13 @@ module EE
private
def update_service_desk_sent_notifications
return unless original_entity.from_service_desk?
original_entity
.sent_notifications.update_all(project_id: new_entity.project_id, noteable_id: new_entity.id)
end
def rewrite_epic_issue
return unless epic_issue = original_entity.epic_issue
return unless can?(current_user, :update_epic, epic_issue.epic.group)
......
......@@ -615,4 +615,20 @@ describe Issue do
end
it_behaves_like 'having health status'
describe '#service_desk?' do
subject { issue.from_service_desk? }
context 'when issue author is support bot' do
let(:issue) { create(:issue, author: ::User.support_bot) }
it { is_expected.to be_truthy }
end
context 'when issue author is not support bot' do
let(:issue) { create(:issue) }
it { is_expected.to be_falsey }
end
end
end
......@@ -107,4 +107,47 @@ describe Issues::MoveService do
end
end
end
context 'updating sent notifications' do
let!(:old_issue_notification_1) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
let!(:old_issue_notification_2) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
let!(:other_issue_notification) { create(:sent_notification, project: old_issue.project) }
context 'when issue is from service desk' do
before do
allow(old_issue).to receive(:from_service_desk?).and_return(true)
end
it 'updates moved issue sent notifications' do
new_issue = move_service.execute(old_issue, new_project)
old_issue_notification_1.reload
old_issue_notification_2.reload
expect(old_issue_notification_1.project_id).to eq(new_issue.project_id)
expect(old_issue_notification_1.noteable_id).to eq(new_issue.id)
expect(old_issue_notification_2.project_id).to eq(new_issue.project_id)
expect(old_issue_notification_2.noteable_id).to eq(new_issue.id)
end
it 'does not update other issues sent notifications' do
expect do
move_service.execute(old_issue, new_project)
other_issue_notification.reload
end.not_to change { other_issue_notification.noteable_id }
end
end
context 'when issue is not from service desk' do
it 'does not update sent notifications' do
move_service.execute(old_issue, new_project)
old_issue_notification_1.reload
old_issue_notification_2.reload
expect(old_issue_notification_1.project_id).to eq(old_issue.project_id)
expect(old_issue_notification_1.noteable_id).to eq(old_issue.id)
expect(old_issue_notification_2.project_id).to eq(old_issue.project_id)
expect(old_issue_notification_2.noteable_id).to eq(old_issue.id)
end
end
end
end
......@@ -188,6 +188,7 @@ excluded_attributes:
issues:
- :milestone_id
- :moved_to_id
- :sent_notifications
- :state_id
- :duplicated_to_id
- :promoted_to_epic_id
......
......@@ -10,6 +10,7 @@ issues:
- resource_label_events
- resource_weight_events
- resource_milestone_events
- sent_notifications
- sentry_issue
- label_links
- labels
......
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