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
6a2d022d
Commit
6a2d022d
authored
Mar 31, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete users asynchronously
parent
8a71d40e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
8 deletions
+24
-8
app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
+2
-2
lib/api/users.rb
lib/api/users.rb
+1
-1
spec/controllers/registrations_controller_spec.rb
spec/controllers/registrations_controller_spec.rb
+16
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+5
-5
No files found.
app/controllers/registrations_controller.rb
View file @
6a2d022d
...
...
@@ -25,12 +25,12 @@ class RegistrationsController < Devise::RegistrationsController
end
def
destroy
Users
::
DestroyService
.
new
(
current_user
).
execute
(
current_user
)
DeleteUserWorker
.
perform_async
(
current_user
.
id
,
current_user
.
id
)
respond_to
do
|
format
|
format
.
html
do
session
.
try
(
:destroy
)
redirect_to
new_user_session_path
,
notice:
"Account s
uccessfully removed
."
redirect_to
new_user_session_path
,
notice:
"Account s
cheduled for removal
."
end
end
end
...
...
lib/api/users.rb
View file @
6a2d022d
...
...
@@ -293,7 +293,7 @@ module API
user
=
User
.
find_by
(
id:
params
[
:id
])
not_found!
(
'User'
)
unless
user
::
Users
::
DestroyService
.
new
(
current_user
).
execute
(
user
)
DeleteUserWorker
.
perform_async
(
current_user
.
id
,
user
.
id
)
end
desc
'Block a user. Available only for admins.'
...
...
spec/controllers/registrations_controller_spec.rb
View file @
6a2d022d
...
...
@@ -68,4 +68,20 @@ describe RegistrationsController do
end
end
end
describe
'#destroy'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
it
'schedules the user for destruction'
do
expect
(
DeleteUserWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
,
user
.
id
)
post
(
:destroy
)
expect
(
response
.
status
).
to
eq
(
302
)
end
end
end
spec/requests/api/users_spec.rb
View file @
6a2d022d
...
...
@@ -676,7 +676,7 @@ describe API::Users, api: true do
before
{
admin
}
it
"deletes user"
do
delete
api
(
"/users/
#{
user
.
id
}
"
,
admin
)
Sidekiq
::
Testing
.
inline!
{
delete
api
(
"/users/
#{
user
.
id
}
"
,
admin
)
}
expect
(
response
).
to
have_http_status
(
204
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
...
...
@@ -684,23 +684,23 @@ describe API::Users, api: true do
end
it
"does not delete for unauthenticated user"
do
delete
api
(
"/users/
#{
user
.
id
}
"
)
Sidekiq
::
Testing
.
inline!
{
delete
api
(
"/users/
#{
user
.
id
}
"
)
}
expect
(
response
).
to
have_http_status
(
401
)
end
it
"is not available for non admin users"
do
delete
api
(
"/users/
#{
user
.
id
}
"
,
user
)
Sidekiq
::
Testing
.
inline!
{
delete
api
(
"/users/
#{
user
.
id
}
"
,
user
)
}
expect
(
response
).
to
have_http_status
(
403
)
end
it
"returns 404 for non-existing user"
do
delete
api
(
"/users/999999"
,
admin
)
Sidekiq
::
Testing
.
inline!
{
delete
api
(
"/users/999999"
,
admin
)
}
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
it
"returns a 404 for invalid ID"
do
delete
api
(
"/users/ASDF"
,
admin
)
Sidekiq
::
Testing
.
inline!
{
delete
api
(
"/users/ASDF"
,
admin
)
}
expect
(
response
).
to
have_http_status
(
404
)
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