def post(self, request, enterprise_id, *args, **kwargs): user_id = request.data.get("user_id") try: user = user_services.get_user_by_user_id(user_id) ent = enterprise_services.get_enterprise_by_enterprise_id( enterprise_id) if ent is None: result = general_message(404, "no found", "未找到该企业") else: user_services.create_admin_user(user, ent) result = general_message(201, "success", None) except UserNotExistError: result = general_message(404, "no found", "未找到该用户") return Response(result, status=201)
def post(self, req, *args, **kwargs): serializer = CreateAdminUserReqSerializer(data=req.data) serializer.is_valid(raise_exception=True) try: user = user_services.get_user_by_user_id(req.data["user_id"]) except UserNotExistError: raise exceptions.NotFound("用户'{}'不存在".format(req.data["user_id"])) ent = enterprise_services.get_enterprise_by_enterprise_id(req.data["eid"]) if ent is None: raise serializers.ValidationError("企业'{}'不存在".format(req.data["eid"]), status.HTTP_404_NOT_FOUND) user_services.create_admin_user(user, ent) return Response(None, status.HTTP_201_CREATED)
def post(self, request, enterprise_id, *args, **kwargs): roles = parse_item(request, "roles", required=True, error="at least one role needs to be specified") if not set(roles).issubset(EnterpriseRolesEnum.names()): raise AbortRequest("invalid roles", msg_show="角色不正确") user_id = request.data.get("user_id") if user_id == self.user.user_id: raise AbortRequest("cannot edit your own role", msg_show="不可操作自己的角色") try: user = user_services.get_user_by_user_id(user_id) except UserNotExistError: raise ErrUserNotFound ent = enterprise_services.get_enterprise_by_enterprise_id(enterprise_id) if ent is None: raise ErrEnterpriseNotFound user_services.create_admin_user(user, ent, roles) return Response(general_message(201, "success", None), status=201)