def delete(self, request, *args, **kwargs): """ 删除团队 --- parameters: - name: team_name description: 要删除的团队 required: true type: string paramType: path """ tenant_name = request.data.get("tenant_name", None) if not tenant_name: return Response(generate_result("1003", "team name is none", "参数缺失")) try: service_count = team_services.get_team_service_count_by_team_name(team_name=tenant_name) if service_count >= 1: result = generate_result("0404", "failed", "当前团队内有应用,不可以删除") return Response(result) status = team_services.delete_tenant(tenant_name=tenant_name) if not status: result = generate_result("0000", "success", "删除团队成功") else: result = generate_result("1002", "delete a tenant failed", "删除团队失败") except Tenants.DoesNotExist as e: logger.exception(e) result = generate_result("1004", "tenant not exist", "{}团队不存在".format(tenant_name)) except Exception as e: result = generate_result("9999", "sys exception", "系统异常") logger.exception(e) return Response(result)
def delete(self, request, team_name, *args, **kwargs): """ 删除当前团队 --- parameters: - name: team_name description: 要删除的团队 required: true type: string paramType: path """ code = 200 identity_list = team_services.get_user_perm_identitys_in_permtenant( user_id=request.user.user_id, tenant_name=team_name) perm_tuple = team_services.get_user_perm_in_tenant( user_id=request.user.user_id, tenant_name=team_name) team = team_services.get_tenant_by_tenant_name(team_name) if not user_services.is_user_admin_in_current_enterprise( request.user, team.enterprise_id): if "owner" not in identity_list and "drop_tenant" not in perm_tuple: code = 400 result = general_message(code, "no identity", "您不是最高管理员,不能删除团队") return Response(result, status=code) try: service_count = team_services.get_team_service_count_by_team_name( team_name=team_name) if service_count >= 1: result = general_message(400, "failed", "当前团队内有应用,不可以删除") return Response(result, status=400) status = team_services.delete_tenant(tenant_name=team_name) if not status: result = general_message(code, "delete a tenant successfully", "删除团队成功") else: code = 400 result = general_message(code, "delete a tenant failed", "删除团队失败") except Tenants.DoesNotExist as e: code = 400 logger.exception(e) result = generate_result(code, "tenant not exist", "{}团队不存在".format(team_name)) except Exception as e: code = 500 result = general_message(code, "sys exception", "系统异常") logger.exception(e) return Response(result, status=code)