Add new notifications for issue move action
[ci skip]
This commit is contained in:
parent
a23f0e8c9e
commit
15d32b6a11
7 changed files with 63 additions and 3 deletions
|
@ -36,6 +36,14 @@ module Emails
|
|||
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id))
|
||||
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
|
||||
|
||||
def setup_issue_mail(issue_id, recipient_id)
|
||||
|
|
|
@ -10,13 +10,17 @@ module Issues
|
|||
if new_project_id
|
||||
@project_new = Project.find(new_project_id)
|
||||
end
|
||||
|
||||
if @project_new == @project_old
|
||||
raise StandardError, 'Cannot move issue to project it originates from!'
|
||||
end
|
||||
end
|
||||
|
||||
def execute
|
||||
return unless move?
|
||||
|
||||
# Using trasaction because of a high footprint on
|
||||
# rewriting notes (unfolding references)
|
||||
# Using trasaction because of a high resources footprint
|
||||
# on rewriting notes (unfolding references)
|
||||
#
|
||||
ActiveRecord::Base.transaction do
|
||||
# New issue tasks
|
||||
|
@ -99,6 +103,7 @@ module Issues
|
|||
end
|
||||
|
||||
def notify_participants
|
||||
notification_service.issue_moved(@issue_old, @issue_new, @current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -236,6 +236,16 @@ class NotificationService
|
|||
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
|
||||
|
||||
# Get project users with WATCH notification level
|
||||
|
|
6
app/views/notify/issue_moved_email.html.haml
Normal file
6
app/views/notify/issue_moved_email.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%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
|
4
app/views/notify/issue_moved_email.text.erb
Normal file
4
app/views/notify/issue_moved_email.text.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
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
|
|||
is_expected.to have_body_text /#{namespace_project_issue_path project.namespace, project, issue}/
|
||||
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
|
||||
|
||||
context 'for merge requests' do
|
||||
|
|
|
@ -55,7 +55,7 @@ describe Issues::MoveService, services: true do
|
|||
end
|
||||
|
||||
it 'rewrites issue description' do
|
||||
expect(new_issue.description).to include description
|
||||
expect(new_issue.description).to eq description
|
||||
end
|
||||
|
||||
it 'adds system note to old issue at the end' do
|
||||
|
|
Loading…
Reference in a new issue