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
1bf799e2
Commit
1bf799e2
authored
Apr 27, 2020
by
George Thomas
Committed by
Jarka Košanová
Apr 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate project snippets to the ghost user when the user is deleted
Closes #205772
parent
b7509c46
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
5 deletions
+30
-5
app/models/snippet.rb
app/models/snippet.rb
+4
-0
app/services/users/migrate_to_ghost_user_service.rb
app/services/users/migrate_to_ghost_user_service.rb
+6
-0
ee/changelogs/unreleased/205772-migrate-project-snippets-ghost-user.yml
...unreleased/205772-migrate-project-snippets-ghost-user.yml
+5
-0
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+9
-5
spec/services/users/migrate_to_ghost_user_service_spec.rb
spec/services/users/migrate_to_ghost_user_service_spec.rb
+6
-0
No files found.
app/models/snippet.rb
View file @
1bf799e2
...
@@ -102,6 +102,10 @@ class Snippet < ApplicationRecord
...
@@ -102,6 +102,10 @@ class Snippet < ApplicationRecord
where
(
project_id:
nil
)
where
(
project_id:
nil
)
end
end
def
self
.
only_project_snippets
where
.
not
(
project_id:
nil
)
end
def
self
.
only_include_projects_visible_to
(
current_user
=
nil
)
def
self
.
only_include_projects_visible_to
(
current_user
=
nil
)
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
current_user
)
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
current_user
)
...
...
app/services/users/migrate_to_ghost_user_service.rb
View file @
1bf799e2
...
@@ -52,6 +52,7 @@ module Users
...
@@ -52,6 +52,7 @@ module Users
migrate_notes
migrate_notes
migrate_abuse_reports
migrate_abuse_reports
migrate_award_emoji
migrate_award_emoji
migrate_snippets
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
...
@@ -79,6 +80,11 @@ module Users
...
@@ -79,6 +80,11 @@ module Users
def
migrate_award_emoji
def
migrate_award_emoji
user
.
award_emoji
.
update_all
(
user_id:
ghost_user
.
id
)
user
.
award_emoji
.
update_all
(
user_id:
ghost_user
.
id
)
end
end
def
migrate_snippets
snippets
=
user
.
snippets
.
only_project_snippets
snippets
.
update_all
(
author_id:
ghost_user
.
id
)
end
end
end
end
end
...
...
ee/changelogs/unreleased/205772-migrate-project-snippets-ghost-user.yml
0 → 100644
View file @
1bf799e2
---
title
:
Migrate project snippets to the ghost user when the user is deleted
merge_request
:
28870
author
:
George Thomas @thegeorgeous
type
:
added
spec/services/users/destroy_service_spec.rb
View file @
1bf799e2
...
@@ -42,13 +42,11 @@ describe Users::DestroyService do
...
@@ -42,13 +42,11 @@ describe Users::DestroyService do
it
'calls the bulk snippet destroy service for the user personal snippets'
do
it
'calls the bulk snippet destroy service for the user personal snippets'
do
repo1
=
create
(
:personal_snippet
,
:repository
,
author:
user
).
snippet_repository
repo1
=
create
(
:personal_snippet
,
:repository
,
author:
user
).
snippet_repository
repo2
=
create
(
:project_snippet
,
:repository
,
author:
user
).
snippet_repository
repo2
=
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
).
snippet_repository
repo3
=
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
).
snippet_repository
aggregate_failures
do
aggregate_failures
do
expect
(
gitlab_shell
.
repository_exists?
(
repo1
.
shard_name
,
repo1
.
disk_path
+
'.git'
)).
to
be_truthy
expect
(
gitlab_shell
.
repository_exists?
(
repo1
.
shard_name
,
repo1
.
disk_path
+
'.git'
)).
to
be_truthy
expect
(
gitlab_shell
.
repository_exists?
(
repo2
.
shard_name
,
repo2
.
disk_path
+
'.git'
)).
to
be_truthy
expect
(
gitlab_shell
.
repository_exists?
(
repo2
.
shard_name
,
repo2
.
disk_path
+
'.git'
)).
to
be_truthy
expect
(
gitlab_shell
.
repository_exists?
(
repo3
.
shard_name
,
repo3
.
disk_path
+
'.git'
)).
to
be_truthy
end
end
# Call made when destroying user personal projects
# Call made when destroying user personal projects
...
@@ -59,17 +57,23 @@ describe Users::DestroyService do
...
@@ -59,17 +57,23 @@ describe Users::DestroyService do
# project snippets where projects are not user personal
# project snippets where projects are not user personal
# ones
# ones
expect
(
Snippets
::
BulkDestroyService
).
to
receive
(
:new
)
expect
(
Snippets
::
BulkDestroyService
).
to
receive
(
:new
)
.
with
(
admin
,
user
.
snippets
).
and_call_original
.
with
(
admin
,
user
.
snippets
.
only_personal_snippets
).
and_call_original
service
.
execute
(
user
)
service
.
execute
(
user
)
aggregate_failures
do
aggregate_failures
do
expect
(
gitlab_shell
.
repository_exists?
(
repo1
.
shard_name
,
repo1
.
disk_path
+
'.git'
)).
to
be_falsey
expect
(
gitlab_shell
.
repository_exists?
(
repo1
.
shard_name
,
repo1
.
disk_path
+
'.git'
)).
to
be_falsey
expect
(
gitlab_shell
.
repository_exists?
(
repo2
.
shard_name
,
repo2
.
disk_path
+
'.git'
)).
to
be_falsey
expect
(
gitlab_shell
.
repository_exists?
(
repo2
.
shard_name
,
repo2
.
disk_path
+
'.git'
)).
to
be_falsey
expect
(
gitlab_shell
.
repository_exists?
(
repo3
.
shard_name
,
repo3
.
disk_path
+
'.git'
)).
to
be_falsey
end
end
end
end
it
'does not delete project snippets that the user is the author of'
do
repo
=
create
(
:project_snippet
,
:repository
,
author:
user
).
snippet_repository
service
.
execute
(
user
)
expect
(
gitlab_shell
.
repository_exists?
(
repo
.
shard_name
,
repo
.
disk_path
+
'.git'
)).
to
be_truthy
expect
(
User
.
ghost
.
snippets
).
to
include
(
repo
.
snippet
)
end
context
'when an error is raised deleting snippets'
do
context
'when an error is raised deleting snippets'
do
it
'does not delete user'
do
it
'does not delete user'
do
snippet
=
create
(
:personal_snippet
,
:repository
,
author:
user
)
snippet
=
create
(
:personal_snippet
,
:repository
,
author:
user
)
...
...
spec/services/users/migrate_to_ghost_user_service_spec.rb
View file @
1bf799e2
...
@@ -78,6 +78,12 @@ describe Users::MigrateToGhostUserService do
...
@@ -78,6 +78,12 @@ describe Users::MigrateToGhostUserService do
end
end
end
end
context
'snippets'
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
Snippet
do
let
(
:created_record
)
{
create
(
:snippet
,
project:
project
,
author:
user
)
}
end
end
context
"when record migration fails with a rollback exception"
do
context
"when record migration fails with a rollback exception"
do
before
do
before
do
expect_any_instance_of
(
ActiveRecord
::
Associations
::
CollectionProxy
)
expect_any_instance_of
(
ActiveRecord
::
Associations
::
CollectionProxy
)
...
...
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