Commit b31c5052 authored by Rémy Coutable's avatar Rémy Coutable

Fallback to group's owners/masters when a project has none

A project in a group can have no explicit owners/masters,
in that case we fallbacks to the group's owners/masters.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 44b8b77e
...@@ -12,6 +12,11 @@ module Emails ...@@ -12,6 +12,11 @@ module Emails
@member_id = member_id @member_id = member_id
admins = member_source.members.owners_and_masters.includes(:user).pluck(:notification_email) admins = member_source.members.owners_and_masters.includes(:user).pluck(:notification_email)
# A project in a group can have no explicit owners/masters, in that case
# we fallbacks to the group's owners/masters.
if admins.empty? && member_source.respond_to?(:group) && member_source.group
admins = member_source.group.members.owners_and_masters.includes(:user).pluck(:notification_email)
end
mail(to: admins, mail(to: admins,
subject: subject("Request to join the #{member_source.human_name} #{member_source.model_name.singular}")) subject: subject("Request to join the #{member_source.human_name} #{member_source.model_name.singular}"))
......
...@@ -401,23 +401,56 @@ describe Notify do ...@@ -401,23 +401,56 @@ describe Notify do
end end
describe 'project access requested' do describe 'project access requested' do
let(:project) { create(:project) } context 'for a project in a user namespace' do
let(:user) { create(:user) } let(:project) { create(:project).tap { |p| p.team << [p.owner, :master, p.owner] } }
let(:project_member) do let(:user) { create(:user) }
project.request_access(user) let(:project_member) do
project.members.request.find_by(user_id: user.id) project.request_access(user)
project.members.request.find_by(user_id: user.id)
end
subject { Notify.member_access_requested_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 'contains all the useful information' do
to_emails = subject.header[:to].addrs
expect(to_emails.size).to eq(1)
expect(to_emails[0].address).to eq(project.members.owners_and_masters.first.user.notification_email)
is_expected.to have_subject "Request to join the #{project.name_with_namespace} project"
is_expected.to have_body_text /#{project.name_with_namespace}/
is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
is_expected.to have_body_text /#{project_member.human_access}/
end
end end
subject { Notify.member_access_requested_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab' context 'for a project in a group' do
it_behaves_like 'it should not have Gmail Actions links' let(:group_owner) { create(:user) }
it_behaves_like "a user cannot unsubscribe through footer link" let(:group) { create(:group).tap { |g| g.add_owner(group_owner) } }
let(:project) { create(:project, namespace: group) }
let(:user) { create(:user) }
let(:project_member) do
project.request_access(user)
project.members.request.find_by(user_id: user.id)
end
subject { Notify.member_access_requested_email('project', project_member.id) }
it 'contains all the useful information' do it_behaves_like 'an email sent from GitLab'
is_expected.to have_subject "Request to join the #{project.name_with_namespace} project" it_behaves_like 'it should not have Gmail Actions links'
is_expected.to have_body_text /#{project.name_with_namespace}/ it_behaves_like "a user cannot unsubscribe through footer link"
is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
is_expected.to have_body_text /#{project_member.human_access}/ it 'contains all the useful information' do
to_emails = subject.header[:to].addrs
expect(to_emails.size).to eq(1)
expect(to_emails[0].address).to eq(group.members.owners_and_masters.first.user.notification_email)
is_expected.to have_subject "Request to join the #{project.name_with_namespace} project"
is_expected.to have_body_text /#{project.name_with_namespace}/
is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
is_expected.to have_body_text /#{project_member.human_access}/
end
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