Commit e5c79248 authored by charlie ablett's avatar charlie ablett

Merge branch 'if-personal_project_owner_in_specs' into 'master'

Owners of personal projects to have OWNER access level in specs

See merge request gitlab-org/gitlab!80290
parents 4838bc49 c14c5a27
......@@ -2523,7 +2523,18 @@ class Project < ApplicationRecord
end
def access_request_approvers_to_be_notified
members.maintainers.connected_to_user.order_recent_sign_in.limit(Member::ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT)
# For a personal project:
# The creator is added as a member with `Owner` access level, starting from GitLab 14.8
# The creator was added as a member with `Maintainer` access level, before GitLab 14.8
# So, to make sure access requests for all personal projects work as expected,
# we need to filter members with the scope `owners_and_maintainers`.
access_request_approvers = if personal?
members.owners_and_maintainers
else
members.maintainers
end
access_request_approvers.connected_to_user.order_recent_sign_in.limit(Member::ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT)
end
def pages_lookup_path(trim_prefix: nil, domain: nil)
......
......@@ -84,7 +84,7 @@ FactoryBot.define do
# user have access to the project. Our specs don't use said service class,
# thus we must manually refresh things here.
unless project.group || project.pending_delete
project.add_maintainer(project.first_owner)
project.add_owner(project.first_owner)
end
project.group&.refresh_members_authorized_projects
......
......@@ -4,12 +4,14 @@ require 'spec_helper'
RSpec.describe 'Projects > Members > User requests access', :js do
let_it_be(:user) { create(:user) }
let_it_be(:maintainer) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let(:maintainer) { project.first_owner }
let(:owner) { project.first_owner }
before do
sign_in(user)
project.add_maintainer(maintainer)
visit project_path(project)
stub_feature_flags(bootstrap_confirmation_modals: false)
end
......@@ -24,7 +26,7 @@ RSpec.describe 'Projects > Members > User requests access', :js do
it 'user can request access to a project' do
perform_enqueued_jobs { click_link 'Request Access' }
expect(ActionMailer::Base.deliveries.last.to).to eq [maintainer.notification_email_or_default]
expect(ActionMailer::Base.deliveries.map(&:to)).to match_array([[owner.notification_email_or_default], [maintainer.notification_email_or_default]])
expect(ActionMailer::Base.deliveries.last.subject).to eq "Request to join the #{project.full_name} project"
expect(project.requesters.exists?(user_id: user)).to be_truthy
......
......@@ -6725,6 +6725,24 @@ RSpec.describe Project, factory_default: :keep do
end
describe '#access_request_approvers_to_be_notified' do
context 'for a personal project' do
let_it_be(:project) { create(:project) }
let_it_be(:maintainer) { create(:user) }
let(:owner_membership) { project.members.owners.find_by(user_id: project.namespace.owner_id) }
it 'includes only the owner of the personal project' do
expect(project.access_request_approvers_to_be_notified.to_a).to eq([owner_membership])
end
it 'includes the maintainers of the personal project, if any' do
project.add_maintainer(maintainer)
maintainer_membership = project.members.maintainers.find_by(user_id: maintainer.id)
expect(project.access_request_approvers_to_be_notified.to_a).to match_array([owner_membership, maintainer_membership])
end
end
let_it_be(:project) { create(:project, group: create(:group, :public)) }
it 'returns a maximum of ten maintainers of the project in recent_sign_in descending order' do
......
......@@ -2546,9 +2546,11 @@ RSpec.describe API::Projects do
get api("/projects", user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.first['permissions']['project_access']['access_level'])
detail_of_project = json_response.find { |detail| detail['id'] == project.id }
expect(detail_of_project.dig('permissions', 'project_access', 'access_level'))
.to eq(Gitlab::Access::MAINTAINER)
expect(json_response.first['permissions']['group_access']).to be_nil
expect(detail_of_project.dig('permissions', 'group_access')).to be_nil
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