From 69f584edb4738d4de82f0301bb2ac8f6b3998814 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 25 Apr 2017 14:44:40 +0200 Subject: Make namespace owner master of project upon creation When an admin creates a project in the namespace of a user, that user automatically gains master access to that project. --- app/services/projects/create_service.rb | 3 ++- .../unreleased/tc-make-user-master-project-by-admin.yml | 4 ++++ spec/services/projects/create_service_spec.rb | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/tc-make-user-master-project-by-admin.yml diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 7828c5806b0..535d93385e6 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -97,7 +97,8 @@ module Projects system_hook_service.execute_hooks_for(@project, :create) unless @project.group || @project.gitlab_project_import? - @project.team << [current_user, :master, current_user] + owners = [current_user, @project.namespace.owner].compact.uniq + @project.add_master(owners, current_user: current_user) end @project.group&.refresh_members_authorized_projects diff --git a/changelogs/unreleased/tc-make-user-master-project-by-admin.yml b/changelogs/unreleased/tc-make-user-master-project-by-admin.yml new file mode 100644 index 00000000000..459d6178bdd --- /dev/null +++ b/changelogs/unreleased/tc-make-user-master-project-by-admin.yml @@ -0,0 +1,4 @@ +--- +title: Ensure namespace owner is Master of project upon creation +merge_request: 10910 +author: diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index 7a07ea618c0..033e6ecd18c 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -27,6 +27,22 @@ describe Projects::CreateService, '#execute', services: true do end end + context "admin creates project with other user's namespace_id" do + it 'sets the correct permissions' do + admin = create(:admin) + opts = { + name: 'GitLab', + namespace_id: user.namespace.id + } + project = create_project(admin, opts) + + expect(project).to be_persisted + expect(project.owner).to eq(user) + expect(project.team.masters).to include(user, admin) + expect(project.namespace).to eq(user.namespace) + end + end + context 'group namespace' do let(:group) do create(:group).tap do |group| -- cgit v1.2.1