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,7 +401,8 @@ describe Notify do ...@@ -401,7 +401,8 @@ 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(:project) { create(:project).tap { |p| p.team << [p.owner, :master, p.owner] } }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project_member) do let(:project_member) do
project.request_access(user) project.request_access(user)
...@@ -414,6 +415,10 @@ describe Notify do ...@@ -414,6 +415,10 @@ describe Notify do
it_behaves_like "a user cannot unsubscribe through footer link" it_behaves_like "a user cannot unsubscribe through footer link"
it 'contains all the useful information' do 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_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 /#{project.name_with_namespace}/
is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/ is_expected.to have_body_text /#{namespace_project_project_members_url(project.namespace, project)}/
...@@ -421,6 +426,34 @@ describe Notify do ...@@ -421,6 +426,34 @@ describe Notify do
end end
end end
context 'for a project in a group' do
let(:group_owner) { create(:user) }
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_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(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
describe 'project access denied' do describe 'project access denied' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
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