Merge branch '18757-fix' into 'master'
Fallback to group's owners/masters when a project has none for the "access requested email"
## What does this MR do?
From b31c5052f9
:
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.
## Are there points in the code the reviewer needs to double check?
No.
## Why was this MR needed?
Because of #18757.
## What are the relevant issue numbers?
Fixes #18757.
## Does this MR meet the acceptance criteria?
- [x] No need for CHANGELOG.
- [x] No need for documentation.
- [x] No API support added.
- [x] Tests
- [x] Added for this feature/bug
- [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
See merge request !4791
This commit is contained in:
commit
0e987ee7a2
2 changed files with 52 additions and 14 deletions
|
@ -12,6 +12,11 @@ module Emails
|
|||
@member_id = member_id
|
||||
|
||||
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,
|
||||
subject: subject("Request to join the #{member_source.human_name} #{member_source.model_name.singular}"))
|
||||
|
|
|
@ -401,23 +401,56 @@ describe Notify do
|
|||
end
|
||||
|
||||
describe 'project access requested' do
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { create(:user) }
|
||||
let(:project_member) do
|
||||
project.request_access(user)
|
||||
project.members.request.find_by(user_id: user.id)
|
||||
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(: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(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
|
||||
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"
|
||||
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 'contains all the useful information' do
|
||||
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}/
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue