BigW Consortium Gitlab

issues.rb 2.43 KB
Newer Older
1 2
module Emails
  module Issues
3
    def new_issue_email(recipient_id, issue_id)
4 5 6
      setup_issue_mail(issue_id, recipient_id)

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

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

14
    def reassigned_issue_email(recipient_id, issue_id, previous_assignee_ids, updated_by_user_id)
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))
21 22
    end

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

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

30
    def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id)
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))
36 37
    end

38
    def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id)
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))
44 45
    end

46 47 48 49 50 51 52 53
    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

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)
65 66 67 68 69 70
      {
        from: sender(sender_id),
        to: recipient(recipient_id),
        subject: subject("#{@issue.title} (##{@issue.iid})")
      }
    end
71 72
  end
end