Add support for deleting namespaces (users, organizations)
Fixes #102 Fixes #105
This commit is contained in:
parent
a74e94fb67
commit
73eb66eac5
23 changed files with 407 additions and 33 deletions
|
@ -10,7 +10,7 @@ from peewee import IntegrityError
|
|||
|
||||
import features
|
||||
|
||||
from app import app, billing as stripe, authentication, avatar, user_analytics
|
||||
from app import app, billing as stripe, authentication, avatar, user_analytics, all_queues
|
||||
from auth import scopes
|
||||
from auth.auth_context import get_authenticated_user
|
||||
from auth.permissions import (AdministerOrganizationPermission, CreateRepositoryPermission,
|
||||
|
@ -346,9 +346,11 @@ class User(ApiResource):
|
|||
@validate_json_request('NewUser')
|
||||
def post(self):
|
||||
""" Create a new user. """
|
||||
if app.config['AUTHENTICATION_TYPE'] != 'Database':
|
||||
abort(404)
|
||||
|
||||
user_data = request.get_json()
|
||||
invite_code = user_data.get('invite_code', '')
|
||||
|
||||
existing_user = model.user.get_nonrobot_user(user_data['username'])
|
||||
if existing_user:
|
||||
raise request_error(message='The username already exists')
|
||||
|
@ -373,6 +375,19 @@ class User(ApiResource):
|
|||
except model.user.DataModelException as ex:
|
||||
raise request_error(exception=ex)
|
||||
|
||||
@require_user_admin
|
||||
@require_fresh_login
|
||||
@nickname('deleteCurrentUser')
|
||||
@internal_only
|
||||
def delete(self):
|
||||
""" Deletes the current user. """
|
||||
if app.config['AUTHENTICATION_TYPE'] != 'Database':
|
||||
abort(404)
|
||||
|
||||
model.user.delete_user(get_authenticated_user(), all_queues)
|
||||
return 'Deleted', 204
|
||||
|
||||
|
||||
@resource('/v1/user/private')
|
||||
@internal_only
|
||||
@show_if(features.BILLING)
|
||||
|
|
Reference in a new issue