Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
003698e1
Commit
003698e1
authored
8 years ago
by
Megan Henning
Browse files
Options
Downloads
Plain Diff
Merge pull request #262 from scitran/cleanup-user
Delete user and cleanup permissions
parents
4fe94c97
951decfa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/handlers/userhandler.py
+19
-1
19 additions, 1 deletion
api/handlers/userhandler.py
with
19 additions
and
1 deletion
api/handlers/userhandler.py
+
19
−
1
View file @
003698e1
...
...
@@ -7,6 +7,7 @@ from .. import config
from
..
import
validators
from
..auth
import
userauth
,
always_ok
,
ROLES
from
..dao
import
containerstorage
from
..dao
import
noop
log
=
config
.
log
...
...
@@ -52,7 +53,11 @@ class UserHandler(base.RequestHandler):
self
.
_init_storage
()
user
=
self
.
_get_user
(
_id
)
permchecker
=
userauth
.
default
(
self
,
user
)
result
=
permchecker
(
self
.
storage
.
exec_op
)(
'
DELETE
'
,
_id
)
# Check for authZ before cleaning up user permissions
permchecker
(
noop
)(
'
DELETE
'
,
_id
)
self
.
_cleanup_user_permissions
(
user
.
get
(
'
_id
'
))
log
.
debug
(
'
2
'
)
result
=
self
.
storage
.
exec_op
(
'
DELETE
'
,
_id
)
if
result
.
deleted_count
==
1
:
return
{
'
deleted
'
:
result
.
deleted_count
}
else
:
...
...
@@ -98,6 +103,19 @@ class UserHandler(base.RequestHandler):
def
_init_storage
(
self
):
self
.
storage
=
containerstorage
.
ContainerStorage
(
'
users
'
,
use_object_id
=
False
)
def
_cleanup_user_permissions
(
self
,
uid
):
try
:
config
.
db
.
collections
.
delete_many
({
'
curator
'
:
uid
})
config
.
db
.
groups
.
update_many
({
'
roles._id
'
:
uid
},
{
'
$pull
'
:
{
'
roles
'
:
{
'
_id
'
:
uid
}}})
query
=
{
'
permissions._id
'
:
uid
}
update
=
{
'
$pull
'
:
{
'
permissions
'
:
{
'
_id
'
:
uid
}}}
config
.
db
.
projects
.
update_many
(
query
,
update
)
config
.
db
.
sessions
.
update_many
(
query
,
update
)
config
.
db
.
acquisitions
.
update_many
(
query
,
update
)
except
:
self
.
abort
(
500
,
'
Site-wide user permissions for {} were unabled to be removed
'
.
format
(
uid
))
def
avatar
(
self
,
uid
):
self
.
_init_storage
()
self
.
resolve_avatar
(
uid
,
default
=
self
.
request
.
GET
.
get
(
'
default
'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment