Commit 6d103a2f authored by Rémy Coutable's avatar Rémy Coutable

Factorize members mails into a new Emails::Members module

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent d75edf1a
module Emails
module Groups
def group_access_requested_email(group_member_id)
setup_group_member_mail(group_member_id)
@requester = @group_member.created_by
group_admins = User.where(id: @group.group_members.admins.pluck(:user_id)).pluck(:notification_email)
mail(to: group_admins,
subject: subject("Request to join #{@group.name} group"))
end
def group_access_granted_email(group_member_id)
setup_group_member_mail(group_member_id)
@current_user = @group_member.user
mail(to: @current_user.notification_email,
subject: subject("Access to #{@group.name} group was granted"))
end
def group_access_denied_email(group_id, user_id)
@group = Group.find(group_id)
@current_user = User.find(user_id)
@target_url = group_url(@group)
mail(to: @current_user.notification_email,
subject: subject("Access to #{@group.name} group was denied"))
end
def group_member_invited_email(group_member_id, token)
setup_group_member_mail(group_member_id)
@token = token
@current_user = @group_member.user
mail(to: @group_member.invite_email,
subject: "Invitation to join group #{@group.name}")
end
def group_invite_accepted_email(group_member_id)
setup_group_member_mail(group_member_id)
return if @group_member.created_by.nil?
@current_user = @group_member.created_by
mail(to: @current_user.notification_email,
subject: subject("Invitation accepted"))
end
def group_invite_declined_email(group_id, invite_email, access_level, created_by_id)
return if created_by_id.nil?
@group = Group.find(group_id)
@current_user = @created_by = User.find(created_by_id)
@access_level = access_level
@invite_email = invite_email
@target_url = group_url(@group)
mail(to: @created_by.notification_email,
subject: subject("Invitation declined"))
end
private
def setup_group_member_mail(group_member_id)
@group_member = GroupMember.find(group_member_id)
@group = @group_member.group
@target_url = group_url(@group)
end
end
end
module Emails
module Members
extend ActiveSupport::Concern
included do
attr_reader :member_target_type
helper_method :member, :access_requester, :member_target_type, :member_target_name, :member_target_url
end
def member_access_requested_email(member_target_type, member_id)
@member_target_type = member_target_type
@member_id = member_id
admins = User.where(id: target.public_send(members_association).admins.pluck(:user_id)).pluck(:notification_email)
mail(to: admins,
subject: subject("Request to join the #{member_target_name} #{member_target_type}"))
end
def member_access_granted_email(member_target_type, member_id)
@member_target_type = member_target_type
@member_id = member_id
mail(to: member.user.notification_email,
subject: subject("Access to the #{member_target_name} #{member_target_type} was granted"))
end
def member_access_denied_email(member_target_type, target_id, user_id)
@member_target_type = member_target_type
@target = target_class.find(target_id)
mail(to: User.find(user_id).notification_email,
subject: subject("Access to the #{member_target_name} #{member_target_type} was denied"))
end
def member_invited_email(member_target_type, member_id, token)
@member_target_type = member_target_type
@member_id = member_id
@token = token
mail(to: member.invite_email,
subject: "Invitation to join the #{member_target_name} #{member_target_type}")
end
def member_invite_accepted_email(member_target_type, member_id)
@member_target_type = member_target_type
@member_id = member_id
return if access_requester.nil?
mail(to: access_requester.notification_email,
subject: subject('Invitation accepted'))
end
def member_invite_declined_email(member_target_type, target_id, invite_email, created_by_id)
return if created_by_id.nil?
@member_target_type = member_target_type
@target = target_class.find(target_id)
@invite_email = invite_email
mail(to: User.find(created_by_id).notification_email,
subject: subject('Invitation declined'))
end
def member
@member ||= member_class.find(@member_id)
end
def access_requester
@access_requester ||= member.created_by
end
def member_target_name
case member_target_type
when 'project'
target.name_with_namespace
else
target.name
end
end
def member_target_url
@member_target_url ||= target.web_url
end
private
def target
@target ||= member.public_send(member_target_type)
end
def target_class
@target_class ||= member_target_type.classify.constantize
end
def member_class
@member_class ||= "#{member_target_type.classify}Member".constantize
end
def members_association
@members_association ||= member_class.to_s.tableize
end
end
end
module Emails module Emails
module Projects module Projects
def project_access_requested_email(project_member_id)
setup_project_member_mail(project_member_id)
@requester = @project_member.created_by
project_admins = User.where(id: @project.project_members.admins.pluck(:user_id)).pluck(:notification_email)
mail(to: project_admins,
subject: subject("Request to join #{@project.name_with_namespace} project"))
end
def project_access_granted_email(project_member_id)
setup_project_member_mail(project_member_id)
@current_user = @project_member.user
mail(to: @current_user.notification_email,
subject: subject("Access to #{@project.name_with_namespace} project was granted"))
end
def project_access_denied_email(project_id, user_id)
@project = Project.find(project_id)
@current_user = User.find(user_id)
@target_url = namespace_project_url(@project.namespace, @project)
mail(to: @current_user.notification_email,
subject: subject("Access to #{@project.name_with_namespace} project was denied"))
end
def project_member_invited_email(project_member_id, token)
setup_project_member_mail(project_member_id)
@token = token
@current_user = @project_member.user
mail(to: @project_member.invite_email,
subject: "Invitation to join project #{@project.name_with_namespace}")
end
def project_invite_accepted_email(project_member_id)
setup_project_member_mail(project_member_id)
return if @project_member.created_by.nil?
@current_user = @project_member.created_by
mail(to: @project_member.created_by.notification_email,
subject: subject("Invitation accepted"))
end
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)
@current_user = @created_by = User.find(created_by_id)
@access_level = access_level
@invite_email = invite_email
@target_url = namespace_project_url(@project.namespace, @project)
mail(to: @created_by.notification_email,
subject: subject("Invitation declined"))
end
def project_was_moved_email(project_id, user_id, old_path_with_namespace) def project_was_moved_email(project_id, user_id, old_path_with_namespace)
@current_user = @user = User.find user_id @current_user = @user = User.find user_id
@project = Project.find project_id @project = Project.find project_id
...@@ -88,13 +25,5 @@ module Emails ...@@ -88,13 +25,5 @@ module Emails
reply_to: @message.reply_to, reply_to: @message.reply_to,
subject: @message.subject) subject: @message.subject)
end end
private
def setup_project_member_mail(project_member_id)
@project_member = ProjectMember.find(project_member_id)
@project = @project_member.project
@target_url = namespace_project_url(@project.namespace, @project)
end
end end
end end
...@@ -6,8 +6,8 @@ class Notify < BaseMailer ...@@ -6,8 +6,8 @@ class Notify < BaseMailer
include Emails::Notes include Emails::Notes
include Emails::Projects include Emails::Projects
include Emails::Profile include Emails::Profile
include Emails::Groups
include Emails::Builds include Emails::Builds
include Emails::Members
add_template_helper MergeRequestsHelper add_template_helper MergeRequestsHelper
add_template_helper DiffHelper add_template_helper DiffHelper
......
...@@ -59,6 +59,10 @@ class Group < Namespace ...@@ -59,6 +59,10 @@ class Group < Namespace
"#{self.class.reference_prefix}#{name}" "#{self.class.reference_prefix}#{name}"
end end
def web_url
Gitlab::Routing.url_helpers.group_url(self)
end
def human_name def human_name
name name
end end
......
...@@ -175,23 +175,24 @@ class NotificationService ...@@ -175,23 +175,24 @@ class NotificationService
# Project access request # Project access request
def new_project_access_request(project_member) def new_project_access_request(project_member)
mailer.project_access_requested_email(project_member.id).deliver_later mailer.member_access_requested_email('project', project_member.id).deliver_later
end end
def decline_project_access_request(project, user) def decline_project_access_request(project, user)
mailer.project_access_denied_email(project.id, user.id).deliver_later mailer.member_access_denied_email('project', project.id, user.id).deliver_later
end end
def invite_project_member(project_member, token) def invite_project_member(project_member, token)
mailer.project_member_invited_email(project_member.id, token).deliver_later mailer.member_invited_email('project', project_member.id, token).deliver_later
end end
def accept_project_invite(project_member) def accept_project_invite(project_member)
mailer.project_invite_accepted_email(project_member.id).deliver_later mailer.member_invite_accepted_email('project', project_member.id).deliver_later
end end
def decline_project_invite(project_member) def decline_project_invite(project_member)
mailer.project_invite_declined_email( mailer.member_invite_declined_email(
'project',
project_member.project.id, project_member.project.id,
project_member.invite_email, project_member.invite_email,
project_member.access_level, project_member.access_level,
...@@ -200,32 +201,33 @@ class NotificationService ...@@ -200,32 +201,33 @@ class NotificationService
end end
def new_project_member(project_member) def new_project_member(project_member)
mailer.project_access_granted_email(project_member.id).deliver_later mailer.member_access_granted_email('project', project_member.id).deliver_later
end end
def update_project_member(project_member) def update_project_member(project_member)
mailer.project_access_granted_email(project_member.id).deliver_later mailer.member_access_granted_email('project', project_member.id).deliver_later
end end
# Group access request # Group access request
def new_group_access_request(group_member) def new_group_access_request(group_member)
mailer.group_access_requested_email(group_member.id).deliver_later mailer.member_access_requested_email('group', group_member.id).deliver_later
end end
def decline_group_access_request(group, user) def decline_group_access_request(group, user)
mailer.group_access_denied_email(group.id, user.id).deliver_later mailer.member_access_denied_email('group', group.id, user.id).deliver_later
end end
def invite_group_member(group_member, token) def invite_group_member(group_member, token)
mailer.group_member_invited_email(group_member.id, token).deliver_later mailer.member_invited_email('group', group_member.id, token).deliver_later
end end
def accept_group_invite(group_member) def accept_group_invite(group_member)
mailer.group_invite_accepted_email(group_member.id).deliver_later mailer.member_invite_accepted_email(group_member.id).deliver_later
end end
def decline_group_invite(group_member) def decline_group_invite(group_member)
mailer.group_invite_declined_email( mailer.member_invite_declined_email(
'group',
group_member.group.id, group_member.group.id,
group_member.invite_email, group_member.invite_email,
group_member.access_level, group_member.access_level,
...@@ -234,11 +236,11 @@ class NotificationService ...@@ -234,11 +236,11 @@ class NotificationService
end end
def new_group_member(group_member) def new_group_member(group_member)
mailer.group_access_granted_email(group_member.id).deliver_later mailer.member_access_granted_email('group', group_member.id).deliver_later
end end
def update_group_member(group_member) def update_group_member(group_member)
mailer.group_access_granted_email(group_member.id).deliver_later mailer.member_access_granted_email('group', group_member.id).deliver_later
end end
def project_was_moved(project, old_path_with_namespace) def project_was_moved(project, old_path_with_namespace)
......
%p
Your request to join group #{link_to @group.name, @target_url} has been denied.
Your request to join group <%= @group.name %> has been denied.
<%= @target_url %>
%p
#{link_to @requester.name, @requester} requested #{@group_member.human_access}
access to group #{link_to @group.name, @target_url}.
<%= @requester.name %> (<%= user_url(@requester) %>) requested <%= @group_member.human_access %> access to group <%= @group.name %>
<%= @target_url %>
%p
Your request to join the
#{link_to member_target_name, member_target_url} #{member_target_type}
has been denied.
Your request to join the <%= member_target_name %> <%= member_target_type %> has been denied.
<%= member_target_url %>
%p
You have been granted #{member.human_access} access to the
#{link_to member_target_name, member_target_url} #{member_target_type}.
You have been granted <%= member.human_access %> access to the <%= member_target_name %> <%= member_target_type %>.
<%= member_target_url %>
%p
#{link_to access_requester.name, access_requester} requested #{member.human_access}
access to the #{link_to member_target_name, member_target_url} #{member_target_type}.
<%= access_requester.name %> (<%= user_url(access_requester) %>) requested <%= member.human_access %> access to the <%= member_target_name %> <%= member_target_type %>.
<%= member_target_url %>
%p
#{member.invite_email}, now known as
#{link_to member.user.name, user_url(member.user)},
has accepted your invitation to join the
#{link_to member_target_name, member_target_url} #{member_target_type}.
<%= member.invite_email %>, now known as <%= member.user.name %>, has accepted your invitation to join the <%= member_target_name %> <%= member_target_type %>.
<%= member_target_url %>
%p
#{@invite_email}
has declined your invitation to join the
#{link_to member_target_name, member_target_url} #{member_target_type}.
<%= @invite_email %> has declined your invitation to join the <%= member_target_name %> <%= member_target_type %>.
<%= member_target_url %>
%p %p
You have been invited You have been invited
- if inviter = @project_member.created_by - if access_requester
by by
= link_to inviter.name, user_url(inviter) = link_to access_requester.name, user_url(access_requester)
to join project to join the
= link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project) = link_to member_target_name, member_target_url
as #{@project_member.human_access}. #{member_target_type} as #{member.human_access}.
%p %p
= link_to 'Accept invitation', invite_url(@token) = link_to 'Accept invitation', invite_url(@token)
......
You have been invited <%= "by #{@project_member.created_by.name} " if @project_member.created_by %>to join project <%= @project.name_with_namespace %> as <%= @project_member.human_access %>. You have been invited <%= "by #{access_requester.name} " if access_requester %>to join the <%= member_target_name %> <%= member_target_type %> as <%= member.human_access %>.
Accept invitation: <%= invite_url(@token) %> Accept invitation: <%= invite_url(@token) %>
Decline invitation: <%= decline_invite_url(@token) %> Decline invitation: <%= decline_invite_url(@token) %>
%p
Your request to join project #{link_to @project.name_with_namespace, @target_url}
has been denied.
Your request to join project <%= @project.name_with_namespace %> has been denied.
<%= @target_url %>
%p
You have been granted #{@project_member.human_access} access to project
#{link_to @project.name_with_namespace, @target_url}.
You have been granted <%= @project_member.human_access %> access to project <%= @project.name_with_namespace %>.
<%= @target_url %>
%p
#{link_to @requester.name, @requester} requested #{@project_member.human_access}
access to project #{link_to @project.name_with_namespace, @target_url}.
<%= @requester.name %> (<%= user_url(@requester) %>) requested <%= @project_member.human_access %> access to project <%= @project.name_with_namespace %>.
<%= @target_url %>
%p
#{@project_member.invite_email}, now known as
#{link_to @project_member.user.name, user_url(@project_member.user)},
has accepted your invitation to join project
#{link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)}.
<%= @project_member.invite_email %>, now known as <%= @project_member.user.name %>, has accepted your invitation to join project <%= @project.name_with_namespace %>.
<%= namespace_project_url(@project.namespace, @project) %>
%p
#{@invite_email}
has declined your invitation to join project
#{link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)}.
<%= @invite_email %> has declined your invitation to join project <%= @project.name_with_namespace %>.
<%= namespace_project_url(@project.namespace, @project) %>
...@@ -407,23 +407,16 @@ describe Notify do ...@@ -407,23 +407,16 @@ describe Notify do
project.request_access(user) project.request_access(user)
project.project_members.find_by(created_by_id: user.id) project.project_members.find_by(created_by_id: user.id)
end end
subject { Notify.project_access_requested_email(project_member.id) } subject { Notify.member_access_requested_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Request to join the #{project.name_with_namespace} project" }
is_expected.to have_subject /Request to join #{project.name_with_namespace} project/ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
end it { is_expected.to have_body_text /#{project.web_url}/ }
it { is_expected.to have_body_text /#{project_member.human_access}/ }
it 'contains name of project' do
is_expected.to have_body_text /#{project.name}/
end
it 'contains new user role' do
is_expected.to have_body_text /#{project_member.human_access}/
end
end end
describe 'project access denied' do describe 'project access denied' do
...@@ -433,42 +426,99 @@ describe Notify do ...@@ -433,42 +426,99 @@ describe Notify do
project.request_access(user) project.request_access(user)
project.project_members.find_by(created_by_id: user.id) project.project_members.find_by(created_by_id: user.id)
end end
subject { Notify.project_access_denied_email(project.id, user.id) } subject { Notify.member_access_denied_email('project', project.id, user.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Access to the #{project.name_with_namespace} project was denied" }
is_expected.to have_subject /Access to #{project.name_with_namespace} project was denied/ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
end it { is_expected.to have_body_text /#{project.web_url}/ }
it 'contains name of project' do
is_expected.to have_body_text /#{project.name}/
end
end end
describe 'project access changed' do describe 'project access changed' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project_member) { create(:project_member, project: project, user: user) } let(:project_member) { create(:project_member, project: project, user: user) }
subject { Notify.project_access_granted_email(project_member.id) } subject { Notify.member_access_granted_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Access to the #{project.name_with_namespace} project was granted" }
is_expected.to have_subject /Access to #{project.name_with_namespace} project was granted/ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
it { is_expected.to have_body_text /#{project.web_url}/ }
it { is_expected.to have_body_text /#{project_member.human_access}/ }
end end
it 'contains name of project' do def invite_to_project(project:, email:, inviter:)
is_expected.to have_body_text /#{project.name}/ ProjectMember.add_user(project.project_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter)
project.project_members.invite.last
end end
it 'contains new user role' do describe 'project invitation' do
is_expected.to have_body_text /#{project_member.human_access}/ let(:project) { create(:project) }
let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
let(:project_member) { invite_to_project(project: project, email: 'toto@example.com', inviter: master) }
subject { Notify.member_invited_email('project', project_member.id, project_member.invite_token) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject "Invitation to join the #{project.name_with_namespace} project" }
it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
it { is_expected.to have_body_text /#{project.web_url}/ }
it { is_expected.to have_body_text /#{project_member.human_access}/ }
it { is_expected.to have_body_text /#{project_member.invite_token}/ }
end
describe 'project invitation accepted' do
let(:project) { create(:project) }
let(:invited_user) { create(:user) }
let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
let(:project_member) do
invitee = invite_to_project(project: project, email: 'toto@example.com', inviter: master)
invitee.accept_invite!(invited_user)
invitee
end
subject { Notify.member_invite_accepted_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject 'Invitation accepted' }
it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
it { is_expected.to have_body_text /#{project.web_url}/ }
it { is_expected.to have_body_text /#{project_member.invite_email}/ }
it { is_expected.to have_body_text /#{invited_user.name}/ }
end end
describe 'project invitation declined' do
let(:project) { create(:project) }
let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
let(:project_member) do
invitee = invite_to_project(project: project, email: 'toto@example.com', inviter: master)
invitee.decline_invite!
invitee
end
subject { Notify.member_invite_declined_email('project', project.id, project_member.invite_email, master.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject 'Invitation declined' }
it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
it { is_expected.to have_body_text /#{project.web_url}/ }
it { is_expected.to have_body_text /#{project_member.invite_email}/ }
end end
context 'items that are noteable, the email for a note' do context 'items that are noteable, the email for a note' do
...@@ -583,6 +633,7 @@ describe Notify do ...@@ -583,6 +633,7 @@ describe Notify do
end end
end end
context 'for a group' do
describe 'group access requested' do describe 'group access requested' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -590,23 +641,16 @@ describe Notify do ...@@ -590,23 +641,16 @@ describe Notify do
group.request_access(user) group.request_access(user)
group.group_members.find_by(created_by_id: user.id) group.group_members.find_by(created_by_id: user.id)
end end
subject { Notify.group_access_requested_email(group_member.id) } subject { Notify.member_access_requested_email('group', group_member.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Request to join the #{group.name} group" }
is_expected.to have_subject /Request to join #{group.name} group/ it { is_expected.to have_body_text /#{group.name}/ }
end it { is_expected.to have_body_text /#{group.web_url}/ }
it { is_expected.to have_body_text /#{group_member.human_access}/ }
it 'contains name of group' do
is_expected.to have_body_text /#{group.name}/
end
it 'contains new user role' do
is_expected.to have_body_text /#{group_member.human_access}/
end
end end
describe 'group access denied' do describe 'group access denied' do
...@@ -616,42 +660,100 @@ describe Notify do ...@@ -616,42 +660,100 @@ describe Notify do
group.request_access(user) group.request_access(user)
group.group_members.find_by(created_by_id: user.id) group.group_members.find_by(created_by_id: user.id)
end end
subject { Notify.group_access_denied_email(group.id, user.id) } subject { Notify.member_access_denied_email('group', group.id, user.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Access to the #{group.name} group was denied" }
is_expected.to have_subject /Access to #{group.name} group was denied/ it { is_expected.to have_body_text /#{group.name}/ }
it { is_expected.to have_body_text /#{group.web_url}/ }
end end
it 'contains name of group' do describe 'group access changed' do
is_expected.to have_body_text /#{group.name}/ let(:group) { create(:group) }
let(:user) { create(:user) }
let(:group_member) { create(:group_member, group: group, user: user) }
subject { Notify.member_access_granted_email('group', group_member.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject "Access to the #{group.name} group was granted" }
it { is_expected.to have_body_text /#{group.name}/ }
it { is_expected.to have_body_text /#{group.web_url}/ }
it { is_expected.to have_body_text /#{group_member.human_access}/ }
end end
def invite_to_group(group:, email:, inviter:)
GroupMember.add_user(group.group_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter)
group.group_members.invite.last
end end
describe 'group access changed' do describe 'group invitation' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:user) } let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
let(:membership) { create(:group_member, group: group, user: user) } let(:group_member) { invite_to_group(group: group, email: 'toto@example.com', inviter: owner) }
subject { Notify.group_access_granted_email(membership.id) } subject { Notify.member_invited_email('group', group_member.id, group_member.invite_token) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject' do it { is_expected.to have_subject "Invitation to join the #{group.name} group" }
is_expected.to have_subject /Access to #{group.name} group was granted/ it { is_expected.to have_body_text /#{group.name}/ }
it { is_expected.to have_body_text /#{group.web_url}/ }
it { is_expected.to have_body_text /#{group_member.human_access}/ }
it { is_expected.to have_body_text /#{group_member.invite_token}/ }
end end
it 'contains name of project' do describe 'group invitation accepted' do
is_expected.to have_body_text /#{group.name}/ let(:group) { create(:group) }
let(:invited_user) { create(:user) }
let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
let(:group_member) do
invitee = invite_to_group(group: group, email: 'toto@example.com', inviter: owner)
invitee.accept_invite!(invited_user)
invitee
end end
it 'contains new user role' do subject { Notify.member_invite_accepted_email('group', group_member.id) }
is_expected.to have_body_text /#{membership.human_access}/
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject 'Invitation accepted' }
it { is_expected.to have_body_text /#{group.name}/ }
it { is_expected.to have_body_text /#{group.web_url}/ }
it { is_expected.to have_body_text /#{group_member.invite_email}/ }
it { is_expected.to have_body_text /#{invited_user.name}/ }
end
describe 'group invitation declined' do
let(:group) { create(:group) }
let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
let(:group_member) do
invitee = invite_to_group(group: group, email: 'toto@example.com', inviter: owner)
invitee.decline_invite!
invitee
end
subject { Notify.member_invite_declined_email('group', group.id, group_member.invite_email, owner.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it { is_expected.to have_subject 'Invitation declined' }
it { is_expected.to have_body_text /#{group.name}/ }
it { is_expected.to have_body_text /#{group.web_url}/ }
it { is_expected.to have_body_text /#{group_member.invite_email}/ }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment