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
Léo-Paul Géneau
gitlab-ce
Commits
7db09c63
Commit
7db09c63
authored
Jun 01, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hard-deleting users when they have authored issues
parent
aff097e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
7 deletions
+13
-7
app/models/user.rb
app/models/user.rb
+1
-5
changelogs/unreleased/33215-fix-hard-delete-of-users.yml
changelogs/unreleased/33215-fix-hard-delete-of-users.yml
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-1
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+7
-1
No files found.
app/models/user.rb
View file @
7db09c63
...
@@ -101,6 +101,7 @@ class User < ActiveRecord::Base
...
@@ -101,6 +101,7 @@ class User < ActiveRecord::Base
has_many
:snippets
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:snippets
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:notes
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:notes
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:issues
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:events
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:events
,
dependent: :destroy
,
foreign_key: :author_id
has_many
:subscriptions
,
dependent: :destroy
has_many
:subscriptions
,
dependent: :destroy
...
@@ -120,11 +121,6 @@ class User < ActiveRecord::Base
...
@@ -120,11 +121,6 @@ class User < ActiveRecord::Base
has_many
:assigned_issues
,
class_name:
"Issue"
,
through: :issue_assignees
,
source: :issue
has_many
:assigned_issues
,
class_name:
"Issue"
,
through: :issue_assignees
,
source: :issue
has_many
:assigned_merge_requests
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"MergeRequest"
has_many
:assigned_merge_requests
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"MergeRequest"
# Issues that a user owns are expected to be moved to the "ghost" user before
# the user is destroyed. If the user owns any issues during deletion, this
# should be treated as an exceptional condition.
has_many
:issues
,
dependent: :restrict_with_exception
,
foreign_key: :author_id
#
#
# Validations
# Validations
#
#
...
...
changelogs/unreleased/33215-fix-hard-delete-of-users.yml
0 → 100644
View file @
7db09c63
---
title
:
Fix hard-deleting users when they have authored issues
merge_request
:
11855
author
:
spec/models/user_spec.rb
View file @
7db09c63
...
@@ -22,7 +22,7 @@ describe User, models: true do
...
@@ -22,7 +22,7 @@ describe User, models: true do
it
{
is_expected
.
to
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:events
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
is_expected
.
to
have_many
(
:recent_events
).
class_name
(
'Event'
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:
restrict_with_exception
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
dependent
(
:
destroy
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:merge_requests
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:identities
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:identities
).
dependent
(
:destroy
)
}
...
...
spec/services/users/destroy_service_spec.rb
View file @
7db09c63
...
@@ -147,16 +147,22 @@ describe Users::DestroyService, services: true do
...
@@ -147,16 +147,22 @@ describe Users::DestroyService, services: true do
end
end
context
"migrating associated records"
do
context
"migrating associated records"
do
let!
(
:issue
)
{
create
(
:issue
,
author:
user
)
}
it
'delegates to the `MigrateToGhostUser` service to move associated records to the ghost user'
do
it
'delegates to the `MigrateToGhostUser` service to move associated records to the ghost user'
do
expect_any_instance_of
(
Users
::
MigrateToGhostUserService
).
to
receive
(
:execute
).
once
expect_any_instance_of
(
Users
::
MigrateToGhostUserService
).
to
receive
(
:execute
).
once
.
and_call_original
service
.
execute
(
user
)
service
.
execute
(
user
)
expect
(
issue
.
reload
.
author
).
to
be_ghost
end
end
it
'does not run `MigrateToGhostUser` if hard_delete option is given'
do
it
'does not run `MigrateToGhostUser` if hard_delete option is given'
do
expect_any_instance_of
(
Users
::
MigrateToGhostUserService
).
not_to
receive
(
:execute
)
expect_any_instance_of
(
Users
::
MigrateToGhostUserService
).
not_to
receive
(
:execute
)
service
.
execute
(
user
,
hard_delete:
true
)
service
.
execute
(
user
,
hard_delete:
true
)
expect
(
Issue
.
exists?
(
issue
.
id
)).
to
be_falsy
end
end
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