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
Boxiang Sun
gitlab-ce
Commits
158581a4
Commit
158581a4
authored
Jun 02, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the DeleteUserWorker
parent
c3410760
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
27 additions
and
11 deletions
+27
-11
app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
+1
-1
app/models/abuse_report.rb
app/models/abuse_report.rb
+1
-2
app/models/spam_log.rb
app/models/spam_log.rb
+1
-2
app/models/user.rb
app/models/user.rb
+5
-0
app/services/users/destroy_service.rb
app/services/users/destroy_service.rb
+16
-1
lib/api/users.rb
lib/api/users.rb
+1
-1
spec/controllers/registrations_controller_spec.rb
spec/controllers/registrations_controller_spec.rb
+1
-1
spec/models/abuse_report_spec.rb
spec/models/abuse_report_spec.rb
+1
-3
No files found.
app/controllers/registrations_controller.rb
View file @
158581a4
...
...
@@ -25,7 +25,7 @@ class RegistrationsController < Devise::RegistrationsController
end
def
destroy
DeleteUserWorker
.
perform_async
(
current_user
.
id
,
current_user
.
id
)
current_user
.
delete_async
(
deleted_by:
current_user
)
respond_to
do
|
format
|
format
.
html
do
...
...
app/models/abuse_report.rb
View file @
158581a4
...
...
@@ -15,8 +15,7 @@ class AbuseReport < ActiveRecord::Base
alias_method
:author
,
:reporter
def
remove_user
(
deleted_by
:)
user
.
block
DeleteUserWorker
.
perform_async
(
deleted_by
.
id
,
user
.
id
,
delete_solo_owned_groups:
true
,
hard_delete:
true
)
user
.
delete_async
(
deleted_by:
deleted_by
,
params:
{
hard_delete:
true
})
end
def
notify
...
...
app/models/spam_log.rb
View file @
158581a4
...
...
@@ -4,8 +4,7 @@ class SpamLog < ActiveRecord::Base
validates
:user
,
presence:
true
def
remove_user
(
deleted_by
:)
user
.
block
DeleteUserWorker
.
perform_async
(
deleted_by
.
id
,
user
.
id
,
delete_solo_owned_groups:
true
,
hard_delete:
true
)
user
.
delete_async
(
deleted_by:
deleted_by
,
params:
{
hard_delete:
true
})
end
def
text
...
...
app/models/user.rb
View file @
158581a4
...
...
@@ -809,6 +809,11 @@ class User < ActiveRecord::Base
system_hook_service
.
execute_hooks_for
(
self
,
:destroy
)
end
def
delete_async
(
deleted_by
:,
params:
{})
block
if
params
[
:hard_delete
]
DeleteUserWorker
.
perform_async
(
deleted_by
.
id
,
id
,
params
)
end
def
notification_service
NotificationService
.
new
end
...
...
app/services/users/destroy_service.rb
View file @
158581a4
...
...
@@ -6,12 +6,27 @@ module Users
@current_user
=
current_user
end
# Synchronously destroys +user+
#
# The operation will fail if the user is the sole owner of any groups. To
# force the groups to be destroyed, pass `delete_solo_owned_groups: true` in
# +options+.
#
# The user's contributions will be migrated to a global ghost user. To
# force the contributions to be destroyed, pass `hard_delete: true` in
# +options+.
#
# `hard_delete: true` implies `delete_solo_owned_groups: true`. To perform
# a hard deletion without destroying solo-owned groups, pass
# `delete_solo_owned_groups: false, hard_delete: true` in +options+.
def
execute
(
user
,
options
=
{})
delete_solo_owned_groups
=
options
.
fetch
(
:delete_solo_owned_groups
,
options
[
:hard_delete
])
unless
Ability
.
allowed?
(
current_user
,
:destroy_user
,
user
)
raise
Gitlab
::
Access
::
AccessDeniedError
,
"
#{
current_user
}
tried to destroy user
#{
user
}
!"
end
if
!
options
[
:delete_solo_owned_groups
]
&&
user
.
solo_owned_groups
.
present?
if
!
delete_solo_owned_groups
&&
user
.
solo_owned_groups
.
present?
user
.
errors
[
:base
]
<<
'You must transfer ownership or delete groups before you can remove user'
return
user
end
...
...
lib/api/users.rb
View file @
158581a4
...
...
@@ -293,7 +293,7 @@ module API
user
=
User
.
find_by
(
id:
params
[
:id
])
not_found!
(
'User'
)
unless
user
DeleteUserWorker
.
perform_async
(
current_user
.
id
,
user
.
id
,
hard_delete:
params
[
:hard_delete
]
)
user
.
delete_async
(
deleted_by:
current_user
,
params:
params
)
end
desc
'Block a user. Available only for admins.'
...
...
spec/controllers/registrations_controller_spec.rb
View file @
158581a4
...
...
@@ -77,7 +77,7 @@ describe RegistrationsController do
end
it
'schedules the user for destruction'
do
expect
(
DeleteUserWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
,
user
.
id
)
expect
(
DeleteUserWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
,
user
.
id
,
{}
)
post
(
:destroy
)
...
...
spec/models/abuse_report_spec.rb
View file @
158581a4
...
...
@@ -28,9 +28,7 @@ RSpec.describe AbuseReport, type: :model do
end
it
'lets a worker delete the user'
do
expect
(
DeleteUserWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
,
subject
.
user
.
id
,
delete_solo_owned_groups:
true
,
hard_delete:
true
)
expect
(
DeleteUserWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
,
subject
.
user
.
id
,
hard_delete:
true
)
subject
.
remove_user
(
deleted_by:
user
)
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