2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module Emails
|
|
|
|
module Issues
|
2018-03-17 18:26:18 +05:30
|
|
|
def new_issue_email(recipient_id, issue_id, reason = nil)
|
2016-01-19 16:12:03 +05:30
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_new_thread(@issue, issue_thread_options(@issue.author_id, recipient_id, reason))
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def issue_due_email(recipient_id, issue_id, reason = nil)
|
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(@issue.author_id, recipient_id, reason))
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def new_mention_in_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
|
2016-09-13 17:45:13 +05:30
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
def reassigned_issue_email(recipient_id, issue_id, previous_assignee_ids, updated_by_user_id, reason = nil)
|
2016-01-19 16:12:03 +05:30
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@previous_assignees = []
|
|
|
|
@previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def closed_issue_email(recipient_id, issue_id, updated_by_user_id, reason: nil, closed_via: nil)
|
|
|
|
setup_issue_mail(issue_id, recipient_id, closed_via: closed_via)
|
2016-01-19 16:12:03 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@updated_by = User.find(updated_by_user_id)
|
2019-09-04 21:01:54 +05:30
|
|
|
@recipient = User.find(recipient_id)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id, reason = nil)
|
2016-06-02 11:05:42 +05:30
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
|
|
|
@label_names = label_names
|
2017-09-10 17:25:29 +05:30
|
|
|
@labels_url = project_labels_url(@project)
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def removed_milestone_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
|
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
|
|
|
end
|
|
|
|
|
|
|
|
def changed_milestone_issue_email(recipient_id, issue_id, milestone, updated_by_user_id, reason = nil)
|
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
|
|
|
@milestone = milestone
|
|
|
|
@milestone_url = milestone_url(@milestone)
|
2019-02-15 15:39:39 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason).merge({
|
|
|
|
template_name: 'changed_milestone_email'
|
|
|
|
}))
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id, reason = nil)
|
2016-01-19 16:12:03 +05:30
|
|
|
setup_issue_mail(issue_id, recipient_id)
|
|
|
|
|
|
|
|
@issue_status = status
|
2016-06-02 11:05:42 +05:30
|
|
|
@updated_by = User.find(updated_by_user_id)
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def issue_moved_email(recipient, issue, new_issue, updated_by_user, reason = nil)
|
2016-06-02 11:05:42 +05:30
|
|
|
setup_issue_mail(issue.id, recipient.id)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@new_issue = new_issue
|
|
|
|
@new_project = new_issue.project
|
2019-03-13 22:55:13 +05:30
|
|
|
@can_access_project = recipient.can?(:read_project, @new_project)
|
2018-03-17 18:26:18 +05:30
|
|
|
mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason))
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def import_issues_csv_email(user_id, project_id, results)
|
|
|
|
@user = User.find(user_id)
|
|
|
|
@project = Project.find(project_id)
|
|
|
|
@results = results
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
mail(to: @user.notification_email_for(@project.group), subject: subject('Imported issues')) do |format|
|
2019-02-15 15:39:39 +05:30
|
|
|
format.html { render layout: 'mailer' }
|
|
|
|
format.text { render layout: 'mailer' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def issues_csv_email(user, project, csv_data, export_status)
|
|
|
|
@project = project
|
|
|
|
@issues_count = export_status.fetch(:rows_expected)
|
|
|
|
@written_count = export_status.fetch(:rows_written)
|
|
|
|
@truncated = export_status.fetch(:truncated)
|
|
|
|
|
|
|
|
filename = "#{project.full_path.parameterize}_issues_#{Date.today.iso8601}.csv"
|
|
|
|
attachments[filename] = { content: csv_data, mime_type: 'text/csv' }
|
|
|
|
mail(to: user.notification_email_for(@project.group), subject: subject("Exported issues")) do |format|
|
|
|
|
format.html { render layout: 'mailer' }
|
|
|
|
format.text { render layout: 'mailer' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
private
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def setup_issue_mail(issue_id, recipient_id, closed_via: nil)
|
2015-12-23 02:04:40 +05:30
|
|
|
@issue = Issue.find(issue_id)
|
2014-09-02 18:07:02 +05:30
|
|
|
@project = @issue.project
|
2017-09-10 17:25:29 +05:30
|
|
|
@target_url = project_issue_url(@project, @issue)
|
2019-09-04 21:01:54 +05:30
|
|
|
@closed_via = closed_via
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
@sent_notification = SentNotification.record(@issue, recipient_id, reply_key)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def issue_thread_options(sender_id, recipient_id, reason)
|
2016-06-02 11:05:42 +05:30
|
|
|
{
|
|
|
|
from: sender(sender_id),
|
2019-12-21 20:55:43 +05:30
|
|
|
to: User.find(recipient_id).notification_email_for(@project.group),
|
2018-03-17 18:26:18 +05:30
|
|
|
subject: subject("#{@issue.title} (##{@issue.iid})"),
|
|
|
|
'X-GitLab-NotificationReason' => reason
|
2016-06-02 11:05:42 +05:30
|
|
|
}
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
Emails::Issues.prepend_if_ee('EE::Emails::Issues')
|