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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
97cbf7c2
Commit
97cbf7c2
authored
Apr 05, 2017
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move a user's notes to the ghost user
... when the user is destroyed.
parent
72580f07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
14 deletions
+27
-14
app/services/concerns/users/migrate_to_ghost_user.rb
app/services/concerns/users/migrate_to_ghost_user.rb
+5
-0
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+8
-2
spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb
..._destroy_service_migrate_to_ghost_user_shared_examples.rb
+14
-12
No files found.
app/services/concerns/users/migrate_to_ghost_user.rb
View file @
97cbf7c2
...
...
@@ -21,6 +21,7 @@ module Users::MigrateToGhostUser
move_issues_to_ghost_user
(
user
)
move_merge_requests_to_ghost_user
(
user
)
move_notes_to_ghost_user
(
user
)
end
user
.
reload
...
...
@@ -35,4 +36,8 @@ module Users::MigrateToGhostUser
def
move_merge_requests_to_ghost_user
(
user
)
user
.
merge_requests
.
update_all
(
author_id:
ghost_user
.
id
)
end
def
move_notes_to_ghost_user
(
user
)
user
.
notes
.
update_all
(
author_id:
ghost_user
.
id
)
end
end
spec/services/users/destroy_service_spec.rb
View file @
97cbf7c2
...
...
@@ -144,18 +144,24 @@ describe Users::DestroyService, services: true do
context
'migrating associated records to the ghost user'
do
context
'issues'
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
Issue
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
Issue
,
{}
do
let
(
:created_record
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
let
(
:assigned_record
)
{
create
(
:issue
,
project:
project
,
assignee:
user
)
}
end
end
context
'merge requests'
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
MergeRequest
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
MergeRequest
,
{}
do
let
(
:created_record
)
{
create
(
:merge_request
,
source_project:
project
,
author:
user
,
target_branch:
"first"
)
}
let
(
:assigned_record
)
{
create
(
:merge_request
,
source_project:
project
,
assignee:
user
,
target_branch:
'second'
)
}
end
end
context
'notes'
do
include_examples
"migrating a deleted user's associated records to the ghost user"
,
Note
,
{
skip_assignee_specs:
true
}
do
let
(
:created_record
)
{
create
(
:note
,
project:
project
,
author:
user
)
}
end
end
end
end
end
spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb
View file @
97cbf7c2
require
"spec_helper"
shared_examples
"migrating a deleted user's associated records to the ghost user"
do
|
record_class
|
shared_examples
"migrating a deleted user's associated records to the ghost user"
do
|
record_class
,
options
|
record_class_name
=
record_class
.
to_s
.
titleize
.
downcase
let
(
:project
)
{
create
(
:project
)
}
...
...
@@ -33,21 +33,23 @@ shared_examples "migrating a deleted user's associated records to the ghost user
end
end
context
"for a
#{
record_class_name
}
the user was assigned to"
do
let!
(
:record
)
{
assigned_record
}
unless
options
[
:skip_assignee_specs
]
context
"for a
#{
record_class_name
}
the user was assigned to"
do
let!
(
:record
)
{
assigned_record
}
before
do
service
.
execute
(
user
)
end
before
do
service
.
execute
(
user
)
end
it
"does not delete
#{
record_class_name
}
s the user is assigned to"
do
expect
(
record_class
.
find_by_id
(
record
.
id
)).
to
be_present
end
it
"does not delete
#{
record_class_name
}
s the user is assigned to"
do
expect
(
record_class
.
find_by_id
(
record
.
id
)).
to
be_present
end
it
"migrates the
#{
record_class_name
}
so that it is 'Unassigned'"
do
migrated_record
=
record_class
.
find_by_id
(
record
.
id
)
it
"migrates the
#{
record_class_name
}
so that it is 'Unassigned'"
do
migrated_record
=
record_class
.
find_by_id
(
record
.
id
)
expect
(
migrated_record
.
assignee
).
to
be_nil
expect
(
migrated_record
.
assignee
).
to
be_nil
end
end
end
end
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