Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f1320e4f
Commit
f1320e4f
authored
Sep 23, 2019
by
manojmj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require maintainer permission to transfer projects
parent
1425a56c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
128 additions
and
2 deletions
+128
-2
app/policies/group_policy.rb
app/policies/group_policy.rb
+2
-0
app/policies/namespace_policy.rb
app/policies/namespace_policy.rb
+2
-0
app/services/projects/transfer_service.rb
app/services/projects/transfer_service.rb
+1
-1
changelogs/unreleased/security-developer-transfer-project.yml
...gelogs/unreleased/security-developer-transfer-project.yml
+5
-0
spec/policies/group_policy_spec.rb
spec/policies/group_policy_spec.rb
+82
-0
spec/policies/namespace_policy_spec.rb
spec/policies/namespace_policy_spec.rb
+2
-1
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+16
-0
spec/services/projects/transfer_service_spec.rb
spec/services/projects/transfer_service_spec.rb
+18
-0
No files found.
app/policies/group_policy.rb
View file @
f1320e4f
...
...
@@ -131,6 +131,8 @@ class GroupPolicy < BasePolicy
rule
{
owner
|
admin
}.
enable
:read_statistics
rule
{
maintainer
&
can?
(
:create_projects
)
}.
enable
:transfer_projects
def
access_level
return
GroupMember
::
NO_ACCESS
if
@user
.
nil?
...
...
app/policies/namespace_policy.rb
View file @
f1320e4f
...
...
@@ -15,6 +15,8 @@ class NamespacePolicy < BasePolicy
end
rule
{
personal_project
&
~
can_create_personal_project
}.
prevent
:create_projects
rule
{
(
owner
|
admin
)
&
can?
(
:create_projects
)
}.
enable
:transfer_projects
end
NamespacePolicy
.
prepend_if_ee
(
'EE::NamespacePolicy'
)
app/services/projects/transfer_service.rb
View file @
f1320e4f
...
...
@@ -98,7 +98,7 @@ module Projects
@new_namespace
&&
can?
(
current_user
,
:change_namespace
,
project
)
&&
@new_namespace
.
id
!=
project
.
namespace_id
&&
current_user
.
can?
(
:
create
_projects
,
@new_namespace
)
current_user
.
can?
(
:
transfer
_projects
,
@new_namespace
)
end
def
update_namespace_and_visibility
(
to_namespace
)
...
...
changelogs/unreleased/security-developer-transfer-project.yml
0 → 100644
View file @
f1320e4f
---
title
:
Require Maintainer permission on group where project is transferred to
merge_request
:
author
:
type
:
security
spec/policies/group_policy_spec.rb
View file @
f1320e4f
...
...
@@ -354,6 +354,88 @@ describe GroupPolicy do
end
end
context
'transfer_projects'
do
shared_examples_for
'allowed to transfer projects'
do
before
do
group
.
update
(
project_creation_level:
project_creation_level
)
end
it
{
is_expected
.
to
be_allowed
(
:transfer_projects
)
}
end
shared_examples_for
'not allowed to transfer projects'
do
before
do
group
.
update
(
project_creation_level:
project_creation_level
)
end
it
{
is_expected
.
to
be_disallowed
(
:transfer_projects
)
}
end
context
'reporter'
do
let
(
:current_user
)
{
reporter
}
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
}
end
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
}
end
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
}
end
end
context
'developer'
do
let
(
:current_user
)
{
developer
}
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
}
end
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
}
end
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
}
end
end
context
'maintainer'
do
let
(
:current_user
)
{
maintainer
}
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
}
end
it_behaves_like
'allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
}
end
it_behaves_like
'allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
}
end
end
context
'owner'
do
let
(
:current_user
)
{
owner
}
it_behaves_like
'not allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
}
end
it_behaves_like
'allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
}
end
it_behaves_like
'allowed to transfer projects'
do
let
(
:project_creation_level
)
{
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
}
end
end
end
context
"create_projects"
do
context
'when group has no project creation level set'
do
before_all
do
...
...
spec/policies/namespace_policy_spec.rb
View file @
f1320e4f
...
...
@@ -6,7 +6,7 @@ describe NamespacePolicy do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:namespace
)
{
create
(
:namespace
,
owner:
owner
)
}
let
(
:owner_permissions
)
{
[
:create_projects
,
:admin_namespace
,
:read_namespace
,
:read_statistics
]
}
let
(
:owner_permissions
)
{
[
:create_projects
,
:admin_namespace
,
:read_namespace
,
:read_statistics
,
:transfer_projects
]
}
subject
{
described_class
.
new
(
current_user
,
namespace
)
}
...
...
@@ -31,6 +31,7 @@ describe NamespacePolicy do
let
(
:owner
)
{
create
(
:user
,
projects_limit:
0
)
}
it
{
is_expected
.
to
be_disallowed
(
:create_projects
)
}
it
{
is_expected
.
to
be_disallowed
(
:transfer_projects
)
}
end
end
...
...
spec/requests/api/projects_spec.rb
View file @
f1320e4f
...
...
@@ -2648,6 +2648,22 @@ describe API::Projects do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
context
'when authenticated as developer'
do
before
do
group
.
add_developer
(
user
)
end
context
'target namespace allows developers to create projects'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
)
}
it
'fails transferring the project to the target namespace'
do
put
api
(
"/projects/
#{
project
.
id
}
/transfer"
,
user
),
params:
{
namespace:
group
.
id
}
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
end
end
it_behaves_like
'custom attributes endpoints'
,
'projects'
do
...
...
spec/services/projects/transfer_service_spec.rb
View file @
f1320e4f
...
...
@@ -222,6 +222,24 @@ describe Projects::TransferService do
it
{
expect
(
project
.
errors
[
:new_namespace
]).
to
include
(
'Project with same name or path in target namespace already exists'
)
}
end
context
'target namespace allows developers to create projects'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
)
}
context
'the user is a member of the target namespace with developer permissions'
do
subject
(
:transfer_project_result
)
{
transfer_project
(
project
,
user
,
group
)
}
before
do
group
.
add_developer
(
user
)
end
it
'does not allow project transfer to the target namespace'
do
expect
(
transfer_project_result
).
to
eq
false
expect
(
project
.
namespace
).
to
eq
(
user
.
namespace
)
expect
(
project
.
errors
[
:new_namespace
]).
to
include
(
'Transfer failed, please contact an admin.'
)
end
end
end
def
transfer_project
(
project
,
user
,
new_namespace
)
service
=
Projects
::
TransferService
.
new
(
project
,
user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment