BigW Consortium Gitlab

issues.rb 2.64 KB
Newer Older
1 2
module Emails
  module Issues
3
    def new_issue_email(recipient_id, issue_id, reason = nil)
4 5
      setup_issue_mail(issue_id, recipient_id)

6
      mail_new_thread(@issue, issue_thread_options(@issue.author_id, recipient_id, reason))
7 8
    end

9
    def new_mention_in_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
10
      setup_issue_mail(issue_id, recipient_id)
11
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
12 13
    end

14
    def reassigned_issue_email(recipient_id, issue_id, previous_assignee_ids, updated_by_user_id, reason = nil)
15 16
      setup_issue_mail(issue_id, recipient_id)

17 18 19
      @previous_assignees = []
      @previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any?

20
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
21 22
    end

23
    def closed_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil)
24 25
      setup_issue_mail(issue_id, recipient_id)

26
      @updated_by = User.find(updated_by_user_id)
27
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
28 29
    end

30
    def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id, reason = nil)
31
      setup_issue_mail(issue_id, recipient_id)
32

33
      @label_names = label_names
34
      @labels_url = project_labels_url(@project)
35
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
36 37
    end

38
    def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id, reason = nil)
39 40 41
      setup_issue_mail(issue_id, recipient_id)

      @issue_status = status
42
      @updated_by = User.find(updated_by_user_id)
43
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id, reason))
44 45
    end

46
    def issue_moved_email(recipient, issue, new_issue, updated_by_user, reason = nil)
47 48 49 50
      setup_issue_mail(issue.id, recipient.id)

      @new_issue = new_issue
      @new_project = new_issue.project
51
      mail_answer_thread(issue, issue_thread_options(updated_by_user.id, recipient.id, reason))
52 53
    end

54 55
    private

56
    def setup_issue_mail(issue_id, recipient_id)
57 58
      @issue = Issue.find(issue_id)
      @project = @issue.project
59
      @target_url = project_issue_url(@project, @issue)
60

61
      @sent_notification = SentNotification.record(@issue, recipient_id, reply_key)
62 63
    end

64
    def issue_thread_options(sender_id, recipient_id, reason)
65 66 67
      {
        from: sender(sender_id),
        to: recipient(recipient_id),
68 69
        subject: subject("#{@issue.title} (##{@issue.iid})"),
        'X-GitLab-NotificationReason' => reason
70 71
      }
    end
72 73
  end
end