Add ability for super users to rename and delete organizations
This commit is contained in:
parent
27d8ea3d5c
commit
3e1abba284
5 changed files with 230 additions and 1 deletions
|
@ -103,6 +103,12 @@ class SuperUserLogs(ApiResource):
|
|||
abort(403)
|
||||
|
||||
|
||||
def org_view(org):
|
||||
return {
|
||||
'name': org.username,
|
||||
'avatar': avatar.get_data_for_org(org),
|
||||
}
|
||||
|
||||
def user_view(user):
|
||||
return {
|
||||
'username': user.username,
|
||||
|
@ -132,6 +138,25 @@ class UsageInformation(ApiResource):
|
|||
|
||||
|
||||
|
||||
@resource('/v1/superuser/organizations/')
|
||||
@internal_only
|
||||
@show_if(features.SUPER_USERS)
|
||||
class SuperUserOrganizationList(ApiResource):
|
||||
""" Resource for listing organizations in the system. """
|
||||
@require_fresh_login
|
||||
@verify_not_prod
|
||||
@nickname('listAllOrganizations')
|
||||
def get(self):
|
||||
""" Returns a list of all organizations in the system. """
|
||||
if SuperUserPermission().can():
|
||||
orgs = model.get_organizations()
|
||||
return {
|
||||
'organizations': [org_view(org) for org in orgs]
|
||||
}
|
||||
|
||||
abort(403)
|
||||
|
||||
|
||||
@resource('/v1/superuser/users/')
|
||||
@internal_only
|
||||
@show_if(features.SUPER_USERS)
|
||||
|
@ -248,6 +273,10 @@ class SuperUserManagement(ApiResource):
|
|||
'email': {
|
||||
'type': 'string',
|
||||
'description': 'The new e-mail address for the user',
|
||||
},
|
||||
'enabled': {
|
||||
'type': 'boolean',
|
||||
'description': 'Whether the user is enabled'
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -309,3 +338,54 @@ class SuperUserManagement(ApiResource):
|
|||
return user_view(user)
|
||||
|
||||
abort(403)
|
||||
|
||||
|
||||
@resource('/v1/superuser/organizations/<name>')
|
||||
@path_param('name', 'The name of the organizaton being managed')
|
||||
@internal_only
|
||||
@show_if(features.SUPER_USERS)
|
||||
class SuperUserOrganizationManagement(ApiResource):
|
||||
""" Resource for managing organizations in the system. """
|
||||
schemas = {
|
||||
'UpdateOrg': {
|
||||
'id': 'UpdateOrg',
|
||||
'type': 'object',
|
||||
'description': 'Description of updates for an organization',
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'string',
|
||||
'description': 'The new name for the organization',
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@require_fresh_login
|
||||
@verify_not_prod
|
||||
@nickname('deleteOrganization')
|
||||
def delete(self, name):
|
||||
""" Deletes the specified organization. """
|
||||
if SuperUserPermission().can():
|
||||
org = model.get_organization(name)
|
||||
|
||||
model.delete_user(org)
|
||||
return 'Deleted', 204
|
||||
|
||||
abort(403)
|
||||
|
||||
@require_fresh_login
|
||||
@verify_not_prod
|
||||
@nickname('changeOrganization')
|
||||
@validate_json_request('UpdateOrg')
|
||||
def put(self, name):
|
||||
""" Updates information about the specified user. """
|
||||
if SuperUserPermission().can():
|
||||
org = model.get_organization(name)
|
||||
org_data = request.get_json()
|
||||
|
||||
if 'name' in org_data:
|
||||
org = model.change_username(org.id, org_data['name'])
|
||||
|
||||
return org_view(org)
|
||||
|
||||
abort(403)
|
||||
|
|
Reference in a new issue