BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3619c221
Commit
3619c221
authored
Feb 21, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sh-delete-user-permission-check' into 'master'
Add user deletion permission check in `Users::DestroyService` See merge request !8974
parents
5a381e58
e23c8037
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
5 deletions
+36
-5
destroy_service.rb
app/services/users/destroy_service.rb
+4
-0
delete_user_worker.rb
app/workers/delete_user_worker.rb
+2
-0
sh-delete-user-permission-check.yml
changelogs/unreleased/sh-delete-user-permission-check.yml
+4
-0
destroy_spec.rb
spec/services/users/destroy_spec.rb
+26
-5
No files found.
app/services/users/destroy_service.rb
View file @
3619c221
...
...
@@ -7,6 +7,10 @@ module Users
end
def
execute
(
user
,
options
=
{})
unless
current_user
.
admin?
||
current_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?
user
.
errors
[
:base
]
<<
'You must transfer ownership or delete groups before you can remove user'
return
user
...
...
app/workers/delete_user_worker.rb
View file @
3619c221
...
...
@@ -7,5 +7,7 @@ class DeleteUserWorker
current_user
=
User
.
find
(
current_user_id
)
Users
::
DestroyService
.
new
(
current_user
).
execute
(
delete_user
,
options
.
symbolize_keys
)
rescue
Gitlab
::
Access
::
AccessDeniedError
=>
e
Rails
.
logger
.
warn
(
"User could not be destroyed:
#{
e
}
"
)
end
end
changelogs/unreleased/sh-delete-user-permission-check.yml
0 → 100644
View file @
3619c221
---
title
:
Add user deletion permission check in `Users::DestroyService`
merge_request
:
author
:
spec/services/users/destroy_spec.rb
View file @
3619c221
...
...
@@ -2,11 +2,11 @@ require 'spec_helper'
describe
Users
::
DestroyService
,
services:
true
do
describe
"Deletes a user and all their personal projects"
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:
current_user
)
{
create
(
:user
)
}
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:service
)
{
described_class
.
new
(
current_user
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:
admin
)
{
create
(
:admin
)
}
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:service
)
{
described_class
.
new
(
admin
)
}
context
'no options are given'
do
it
'deletes the user'
do
...
...
@@ -57,5 +57,26 @@ describe Users::DestroyService, services: true do
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
context
"deletion permission checks"
do
it
'does not delete the user when user is not an admin'
do
other_user
=
create
(
:user
)
expect
{
described_class
.
new
(
other_user
).
execute
(
user
)
}.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
expect
(
User
.
exists?
(
user
.
id
)).
to
be
(
true
)
end
it
'allows admins to delete anyone'
do
described_class
.
new
(
admin
).
execute
(
user
)
expect
(
User
.
exists?
(
user
.
id
)).
to
be
(
false
)
end
it
'allows users to delete their own account'
do
described_class
.
new
(
user
).
execute
(
user
)
expect
(
User
.
exists?
(
user
.
id
)).
to
be
(
false
)
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