Commit 15d32b6a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add new notifications for issue move action

[ci skip]
parent a23f0e8c
...@@ -36,6 +36,14 @@ module Emails ...@@ -36,6 +36,14 @@ module Emails
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id)) mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id))
end end
def issue_moved_email(recipient, issue, new_issue, updated_by_user)
setup_issue_mail(issue.id, recipient.id)
@new_issue = new_issue
@new_project = new_issue.project
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id))
end
private private
def setup_issue_mail(issue_id, recipient_id) def setup_issue_mail(issue_id, recipient_id)
......
...@@ -10,13 +10,17 @@ module Issues ...@@ -10,13 +10,17 @@ module Issues
if new_project_id if new_project_id
@project_new = Project.find(new_project_id) @project_new = Project.find(new_project_id)
end end
if @project_new == @project_old
raise StandardError, 'Cannot move issue to project it originates from!'
end
end end
def execute def execute
return unless move? return unless move?
# Using trasaction because of a high footprint on # Using trasaction because of a high resources footprint
# rewriting notes (unfolding references) # on rewriting notes (unfolding references)
# #
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
# New issue tasks # New issue tasks
...@@ -99,6 +103,7 @@ module Issues ...@@ -99,6 +103,7 @@ module Issues
end end
def notify_participants def notify_participants
notification_service.issue_moved(@issue_old, @issue_new, @current_user)
end end
end end
end end
...@@ -236,6 +236,16 @@ class NotificationService ...@@ -236,6 +236,16 @@ class NotificationService
end end
end end
def issue_moved(issue, new_issue, current_user)
recipients = build_recipients(issue, issue.project, current_user)
recipients.map do |recipient|
email = mailer.issue_moved_email(recipient, issue, new_issue, current_user)
email.deliver_later
email
end
end
protected protected
# Get project users with WATCH notification level # Get project users with WATCH notification level
......
%p
Issue was moved to another project.
%p
New issue:
= link_to namespace_project_issue_url(@new_project.namespace, @new_project, @new_issue) do
= @new_issue.title
Issue was moved to another project.
New issue location:
<%= namespace_project_issue_url(@new_project.namespace, @new_project, @new_issue) %>
...@@ -158,6 +158,33 @@ describe Notify do ...@@ -158,6 +158,33 @@ describe Notify do
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/ is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
end end
end end
describe 'moved to another project' do
let(:new_issue) { create(:issue) }
subject { Notify.issue_moved_email(recipient, issue, new_issue, current_user) }
it_behaves_like 'an answer to an existing thread', 'issue'
it_behaves_like 'it should show Gmail Actions View Issue link'
it_behaves_like 'an unsubscribeable thread'
it 'contains description about action taken' do
is_expected.to have_body_text 'Issue was moved to another project'
end
it 'has the correct subject' do
is_expected.to have_subject /#{issue.title} \(##{issue.iid}\)/i
end
it 'contains link to new issue' do
new_issue_url = namespace_project_issue_path(new_issue.project.namespace,
new_issue.project, new_issue)
is_expected.to have_body_text new_issue_url
end
it 'contains a link to the original issue' do
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
end
end
end end
context 'for merge requests' do context 'for merge requests' do
......
...@@ -55,7 +55,7 @@ describe Issues::MoveService, services: true do ...@@ -55,7 +55,7 @@ describe Issues::MoveService, services: true do
end end
it 'rewrites issue description' do it 'rewrites issue description' do
expect(new_issue.description).to include description expect(new_issue.description).to eq description
end end
it 'adds system note to old issue at the end' do it 'adds system note to old issue at the end' do
......
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