diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-04-10 16:23:38 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-04-14 13:08:10 +0300 |
commit | 717fa136a5146d45660d3d97f5671352a47a0601 (patch) | |
tree | fe5bd4660f8d68b7518df21647e05b9e2ab1ed19 | |
parent | 39f389ae0fff5706b73b03c8fb5fc4e3dd7da638 (diff) |
Add emails around invitation.
-rw-r--r-- | app/mailers/emails/groups.rb | 21 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 25 | ||||
-rw-r--r-- | app/models/members/group_member.rb | 12 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 12 | ||||
-rw-r--r-- | app/services/notification_service.rb | 16 |
5 files changed, 82 insertions, 4 deletions
diff --git a/app/mailers/emails/groups.rb b/app/mailers/emails/groups.rb index 626eb593d51..9db609006e0 100644 --- a/app/mailers/emails/groups.rb +++ b/app/mailers/emails/groups.rb @@ -5,8 +5,27 @@ module Emails @group = @group_member.group @target_url = group_url(@group) @current_user = @group_member.user - mail(to: @group_member.user.email, + mail(to: @group_member.user.notification_email, subject: subject("Access to group was granted")) end + + def group_member_invited_email(group_member_id, token) + @group_member = GroupMember.find group_member_id + @group = @group_member.group + @token = token + @target_url = group_url(@group) + mail(to: @group_member.invite_email, + subject: "Invite to join group #{@group.name}") + end + + def group_invite_accepted_email(group_member_id) + @group_member = GroupMember.find group_member_id + return if @group_member.created_by.nil? + + @group = @group_member.group + @target_url = group_url(@group) + mail(to: @group_member.created_by.notification_email, + subject: subject("Invite accepted")) + end end end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 20a863c3742..64c35618a52 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -1,14 +1,33 @@ module Emails module Projects - def project_access_granted_email(user_project_id) - @project_member = ProjectMember.find user_project_id + def project_access_granted_email(project_member_id) + @project_member = ProjectMember.find project_member_id @project = @project_member.project @target_url = namespace_project_url(@project.namespace, @project) @current_user = @project_member.user - mail(to: @project_member.user.email, + mail(to: @project_member.user.notification_email, subject: subject("Access to project was granted")) end + def project_member_invited_email(project_member_id, token) + @project_member = ProjectMember.find project_member_id + @project = @project_member.project + @token = token + @target_url = namespace_project_url(@project.namespace, @project) + mail(to: @project_member.invite_email, + subject: "Invite to join project #{@project.name_with_namespace}") + 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 + @target_url = namespace_project_url(@project.namespace, @project) + mail(to: @project_member.created_by.notification_email, + subject: subject("Invite accepted")) + end + def project_was_moved_email(project_id, user_id) @current_user = @user = User.find user_id @project = Project.find project_id diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index ccbbab6afc5..68b7c169f72 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -41,6 +41,12 @@ class GroupMember < Member private + def send_invite + notification_service.invite_group_member(self, @raw_invite_token) + + super + end + def post_create_hook notification_service.new_group_member(self) @@ -54,4 +60,10 @@ class GroupMember < Member super end + + def after_accept_invite + notification_service.accept_group_invite(self) + + super + end end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 6c5d161940d..a63d5af1219 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -116,6 +116,12 @@ class ProjectMember < Member private + def send_invite + notification_service.invite_project_member(self, @raw_invite_token) + + super + end + def post_create_hook unless owner? event_service.join_project(self.project, self.user) @@ -139,6 +145,12 @@ class ProjectMember < Member super end + def after_accept_invite + notification_service.accept_project_invite(self) + + super + end + def event_service EventCreateService.new end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 42547f6f481..a97abe289f5 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -165,6 +165,14 @@ class NotificationService end end + def invite_project_member(project_member, token) + mailer.project_member_invited_email(project_member.id, token) + end + + def accept_project_invite(project_member) + mailer.project_invite_accepted_email(project_member.id) + end + def new_project_member(project_member) mailer.project_access_granted_email(project_member.id) end @@ -173,6 +181,14 @@ class NotificationService mailer.project_access_granted_email(project_member.id) end + def invite_group_member(group_member, token) + mailer.group_member_invited_email(group_member.id, token) + end + + def accept_group_invite(group_member) + mailer.group_invite_accepted_email(group_member.id) + end + def new_group_member(group_member) mailer.group_access_granted_email(group_member.id) end |