BigW Consortium Gitlab

projects.rb 2.74 KB
Newer Older
1 2
module Emails
  module Projects
3 4
    def project_access_granted_email(project_member_id)
      @project_member = ProjectMember.find project_member_id
5
      @project = @project_member.project
6

Vinnie Okada committed
7
      @target_url = namespace_project_url(@project.namespace, @project)
Douwe Maan committed
8
      @current_user = @project_member.user
9

10
      mail(to: @project_member.user.notification_email,
11
           subject: subject("Access to project was granted"))
12 13
    end

14 15 16 17
    def project_member_invited_email(project_member_id, token)
      @project_member = ProjectMember.find project_member_id
      @project = @project_member.project
      @token = token
18

19
      @target_url = namespace_project_url(@project.namespace, @project)
20
      @current_user = @project_member.user
21

22
      mail(to: @project_member.invite_email,
23
           subject: "Invitation to join project #{@project.name_with_namespace}")
24 25 26 27 28 29 30
    end

    def project_invite_accepted_email(project_member_id)
      @project_member = ProjectMember.find project_member_id
      return if @project_member.created_by.nil?

      @project = @project_member.project
31

32
      @target_url = namespace_project_url(@project.namespace, @project)
33 34
      @current_user = @project_member.created_by

35
      mail(to: @project_member.created_by.notification_email,
36
           subject: subject("Invitation accepted"))
37 38
    end

Douwe Maan committed
39 40 41 42
    def project_invite_declined_email(project_id, invite_email, access_level, created_by_id)
      return if created_by_id.nil?

      @project = Project.find(project_id)
43
      @current_user = @created_by = User.find(created_by_id)
Douwe Maan committed
44 45
      @access_level = access_level
      @invite_email = invite_email
46

Douwe Maan committed
47 48 49
      @target_url = namespace_project_url(@project.namespace, @project)

      mail(to: @created_by.notification_email,
50
           subject: subject("Invitation declined"))
Douwe Maan committed
51 52
    end

53
    def project_was_moved_email(project_id, user_id, old_path_with_namespace)
Douwe Maan committed
54
      @current_user = @user = User.find user_id
55
      @project = Project.find project_id
Vinnie Okada committed
56
      @target_url = namespace_project_url(@project.namespace, @project)
57
      @old_path_with_namespace = old_path_with_namespace
58
      mail(to: @user.notification_email,
59
           subject: subject("Project was moved"))
60
    end
61

62
    def repository_push_email(project_id, recipient, opts = {})
63
      @message =
64 65
        Gitlab::Email::Message::RepositoryPush.new(self, project_id, recipient, opts)

66 67
      # used in notify layout
      @target_url = @message.target_url
68 69 70 71
      @project = Project.find project_id

      add_project_headers
      headers['X-GitLab-Author'] = @message.author_username
72

73 74 75 76
      mail(from:      sender(@message.author_id, @message.send_from_committer_email?),
           reply_to:  @message.reply_to,
           to:        @message.recipient,
           subject:   @message.subject)
77
    end
78 79
  end
end