BigW Consortium Gitlab

issues.rb 2.46 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_id, updated_by_user_id)
15 16 17 18
      setup_issue_mail(issue_id, recipient_id)

      @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id))
19 20
    end

21
    def closed_issue_email(recipient_id, issue_id, updated_by_user_id)
22 23
      setup_issue_mail(issue_id, recipient_id)

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

28
    def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id)
29
      setup_issue_mail(issue_id, recipient_id)
30

31
      @label_names = label_names
32
      @labels_url = namespace_project_labels_url(@project.namespace, @project)
33
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id))
34 35
    end

36
    def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id)
37 38 39
      setup_issue_mail(issue_id, recipient_id)

      @issue_status = status
40
      @updated_by = User.find(updated_by_user_id)
41
      mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, recipient_id))
42 43
    end

44 45 46 47 48 49 50 51
    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

52 53
    private

54
    def setup_issue_mail(issue_id, recipient_id)
55 56 57 58
      @issue = Issue.find(issue_id)
      @project = @issue.project
      @target_url = namespace_project_issue_url(@project.namespace, @project, @issue)

59
      @sent_notification = SentNotification.record(@issue, recipient_id, reply_key)
60 61
    end

62
    def issue_thread_options(sender_id, recipient_id)
63 64 65 66 67 68
      {
        from: sender(sender_id),
        to: recipient(recipient_id),
        subject: subject("#{@issue.title} (##{@issue.iid})")
      }
    end
69 70
  end
end