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
0e56b243
Commit
0e56b243
authored
Mar 18, 2022
by
Manoj M J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retain membership record for a personal project’s owner after transfer
Changelog: fixed
parent
cf6d1a58
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
1 deletion
+65
-1
app/services/projects/transfer_service.rb
app/services/projects/transfer_service.rb
+14
-0
spec/services/projects/transfer_service_spec.rb
spec/services/projects/transfer_service_spec.rb
+51
-1
No files found.
app/services/projects/transfer_service.rb
View file @
0e56b243
...
...
@@ -121,6 +121,7 @@ module Projects
# Overridden in EE
def
post_update_hooks
(
project
)
move_pages
(
project
)
ensure_personal_project_owner_membership
(
project
)
end
# Overridden in EE
...
...
@@ -152,6 +153,19 @@ module Projects
project
.
track_project_repository
end
def
ensure_personal_project_owner_membership
(
project
)
# In case of personal projects, we want to make sure that
# a membership record with `OWNER` access level exists for the owner of the namespace.
return
unless
project
.
personal?
namespace_owner
=
project
.
namespace
.
owner
existing_membership_record
=
project
.
member
(
namespace_owner
)
return
if
existing_membership_record
.
present?
&&
existing_membership_record
.
access_level
==
Gitlab
::
Access
::
OWNER
project
.
add_owner
(
namespace_owner
)
end
def
refresh_permissions
# This ensures we only schedule 1 job for every user that has access to
# the namespaces.
...
...
spec/services/projects/transfer_service_spec.rb
View file @
0e56b243
...
...
@@ -11,8 +11,9 @@ RSpec.describe Projects::TransferService do
let
(
:project
)
{
create
(
:project
,
:repository
,
:legacy_storage
,
namespace:
user
.
namespace
)
}
let
(
:target
)
{
group
}
let
(
:executor
)
{
user
}
subject
(
:execute_transfer
)
{
described_class
.
new
(
project
,
use
r
).
execute
(
target
).
tap
{
project
.
reload
}
}
subject
(
:execute_transfer
)
{
described_class
.
new
(
project
,
executo
r
).
execute
(
target
).
tap
{
project
.
reload
}
}
context
'with npm packages'
do
before
do
...
...
@@ -92,6 +93,55 @@ RSpec.describe Projects::TransferService do
end
end
context
'project in a group -> a personal namespace'
,
:enable_admin_mode
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:legacy_storage
,
group:
group
)
}
let
(
:target
)
{
user
.
namespace
}
# We need to use an admin user as the executor because
# only an admin user has required permissions to transfer projects
# under _all_ the different circumstances specified below.
let
(
:executor
)
{
create
(
:user
,
:admin
)
}
it
'executes the transfer to personal namespace successfully'
do
execute_transfer
expect
(
project
.
namespace
).
to
eq
(
user
.
namespace
)
end
context
'the owner of the namespace does not have a direct membership in the project residing in the group'
do
it
'creates a project membership record for the owner of the namespace, with OWNER access level, after the transfer'
do
execute_transfer
expect
(
project
.
members
.
owners
.
find_by
(
user_id:
user
.
id
)).
to
be_present
end
end
context
'the owner of the namespace has a direct membership in the project residing in the group'
do
context
'that membership has an access level of OWNER'
do
before
do
project
.
add_owner
(
user
)
end
it
'retains the project membership record for the owner of the namespace, with OWNER access level, after the transfer'
do
execute_transfer
expect
(
project
.
members
.
owners
.
find_by
(
user_id:
user
.
id
)).
to
be_present
end
end
context
'that membership has an access level that is not OWNER'
do
before
do
project
.
add_developer
(
user
)
end
it
'updates the project membership record for the owner of the namespace, to OWNER access level, after the transfer'
do
execute_transfer
expect
(
project
.
members
.
owners
.
find_by
(
user_id:
user
.
id
)).
to
be_present
end
end
end
end
context
'when transfer succeeds'
do
before
do
group
.
add_owner
(
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