Commit 2d89cf20 authored by Mario de la Ossa's avatar Mario de la Ossa

Notifications for Clone quick_action

Adds email notifications for the new Clone quick-action
parent 2d7d9ef3
...@@ -5,7 +5,7 @@ module NotifyHelper ...@@ -5,7 +5,7 @@ module NotifyHelper
link_to(entity.to_reference, merge_request_url(entity, *args)) link_to(entity.to_reference, merge_request_url(entity, *args))
end end
def issue_reference_link(entity, *args) def issue_reference_link(entity, *args, full: false)
link_to(entity.to_reference, issue_url(entity, *args)) link_to(entity.to_reference(full: full), issue_url(entity, *args))
end end
end end
...@@ -80,6 +80,16 @@ module Emails ...@@ -80,6 +80,16 @@ module Emails
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason)) mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason))
end end
def issue_cloned_email(recipient, issue, new_issue, updated_by_user, reason = nil)
setup_issue_mail(issue.id, recipient.id)
@author = updated_by_user
@issue = issue
@new_issue = new_issue
@can_access_project = recipient.can?(:read_project, @new_issue.project)
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason))
end
def import_issues_csv_email(user_id, project_id, results) def import_issues_csv_email(user_id, project_id, results)
@user = User.find(user_id) @user = User.find(user_id)
@project = Project.find(project_id) @project = Project.find(project_id)
......
...@@ -504,6 +504,16 @@ class NotificationService ...@@ -504,6 +504,16 @@ class NotificationService
end end
end end
def issue_cloned(issue, new_issue, current_user)
recipients = NotificationRecipients::BuildService.build_recipients(issue, current_user, action: 'cloned')
recipients.map do |recipient|
email = mailer.issue_cloned_email(recipient.user, issue, new_issue, current_user, recipient.reason)
email.deliver_later
email
end
end
def project_exported(project, current_user) def project_exported(project, current_user)
return true unless notifiable?(current_user, :mention, project: project) return true unless notifiable?(current_user, :mention, project: project)
......
- author_link = link_to @author.name, user_url(@author)
- if @can_access_project
- string = _("%{author_link} cloned %{original_issue} to %{new_issue}.").html_safe
- else
- string = _("%{author_link} cloned %{original_issue}. You don't have access to the new project.").html_safe
%p
= string % { author_link: author_link, original_issue: issue_reference_link(@issue), new_issue: issue_reference_link(@new_issue, full: true) }
Issue was cloned.
<% if @can_access_project %>
New issue location:
<%= project_issue_url(@new_issue.project, @new_issue) %>
<% else %>
You don't have access to the project.
<% end %>
---
title: Added email notifications when an Issue is cloned
merge_request: 48534
author:
type: added
...@@ -359,6 +359,12 @@ msgstr "" ...@@ -359,6 +359,12 @@ msgstr ""
msgid "%{anchorOpen}Learn more%{anchorClose} about how you can customize / disable registration on your instance." msgid "%{anchorOpen}Learn more%{anchorClose} about how you can customize / disable registration on your instance."
msgstr "" msgstr ""
msgid "%{author_link} cloned %{original_issue} to %{new_issue}."
msgstr ""
msgid "%{author_link} cloned %{original_issue}. You don't have access to the new project."
msgstr ""
msgid "%{author_link} wrote:" msgid "%{author_link} wrote:"
msgstr "" msgstr ""
......
...@@ -1549,6 +1549,37 @@ RSpec.describe NotificationService, :mailer do ...@@ -1549,6 +1549,37 @@ RSpec.describe NotificationService, :mailer do
end end
end end
describe '#issue_cloned' do
let(:new_issue) { create(:issue) }
it 'sends email to issue notification recipients' do
notification.issue_cloned(issue, new_issue, @u_disabled)
should_email(issue.assignees.first)
should_email(issue.author)
should_email(@u_watcher)
should_email(@u_guest_watcher)
should_email(@u_participant_mentioned)
should_email(@subscriber)
should_email(@watcher_and_subscriber)
should_not_email(@unsubscriber)
should_not_email(@u_participating)
should_not_email(@u_disabled)
should_not_email(@u_lazy_participant)
end
it_behaves_like 'participating notifications' do
let(:participant) { create(:user, username: 'user-participant') }
let(:issuable) { issue }
let(:notification_trigger) { notification.issue_cloned(issue, new_issue, @u_disabled) }
end
it_behaves_like 'project emails are disabled' do
let(:notification_target) { issue }
let(:notification_trigger) { notification.issue_cloned(issue, new_issue, @u_disabled) }
end
end
describe '#issue_due' do describe '#issue_due' do
before do before do
issue.update!(due_date: Date.today) issue.update!(due_date: Date.today)
......
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