def delete_team(request):
"""
Delete a team entry in the db.
Only available to organization owners.
---
org_id:
description: The team's org id
type: string
required: true
team_id:
description: The team's id
type: string
required: true
"""
auth_context = auth_context_from_request(request)
org_id = request.matchdict['org_id']
team_id = request.matchdict['team_id']
# SEC check if owner
if not (auth_context.org and auth_context.is_owner() and
auth_context.org.id == org_id):
raise OrganizationAuthorizationFailure()
if auth_context.org.get_team('Owners').id == team_id:
raise ForbiddenError()
try:
team = auth_context.org.get_team_by_id(team_id)
except me.DoesNotExist:
raise NotFoundError()
if team.members:
raise BadRequestError(
'Team not empty. Remove all members and try again')
try:
team.drop_mappings()
auth_context.org.update(pull__teams__id=team_id)
except me.ValidationError as e:
raise BadRequestError({"msg": e.message, "errors": e.to_dict()})
except me.OperationError:
raise TeamOperationError()
trigger_session_update(auth_context.owner, ['org'])
return OK
# SEC
评论列表
文章目录