Commit 65535077 authored by charlie ablett's avatar charlie ablett

Merge branch 'mmj-project-member-policy-refactor' into 'master'

ProjectMemberPolicy refactor for holder of personal project

See merge request gitlab-org/gitlab!83835
parents 44ee7b08 eb9b599e
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
class ProjectMemberPolicy < BasePolicy class ProjectMemberPolicy < BasePolicy
delegate { @subject.project } delegate { @subject.project }
condition(:target_is_owner, scope: :subject) { @subject.user == @subject.project.owner } condition(:target_is_holder_of_the_personal_namespace, scope: :subject) do
@subject.project.personal_namespace_holder?(@subject.user)
end
condition(:target_is_self) { @user && @subject.user == @user } condition(:target_is_self) { @user && @subject.user == @user }
condition(:project_bot) { @subject.user&.project_bot? } condition(:project_bot) { @subject.user&.project_bot? }
rule { anonymous }.prevent_all rule { anonymous }.prevent_all
rule { target_is_owner }.policy do rule { target_is_holder_of_the_personal_namespace }.policy do
prevent :update_project_member prevent :update_project_member
prevent :destroy_project_member prevent :destroy_project_member
end end
......
...@@ -23,9 +23,9 @@ RSpec.describe ProjectMemberPolicy do ...@@ -23,9 +23,9 @@ RSpec.describe ProjectMemberPolicy do
it { is_expected.not_to be_allowed(:destroy_project_bot_member) } it { is_expected.not_to be_allowed(:destroy_project_bot_member) }
end end
context 'when user is project owner' do context 'when user is the holder of personal namespace in which the project resides' do
let(:member_user) { project.first_owner } let(:namespace_holder) { project.namespace.owner }
let(:member) { project.members.find_by!(user: member_user) } let(:member) { project.members.find_by!(user: namespace_holder) }
it { is_expected.to be_allowed(:read_project) } it { is_expected.to be_allowed(:read_project) }
it { is_expected.to be_disallowed(:update_project_member) } it { is_expected.to be_disallowed(:update_project_member) }
......
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