示例#1
0
 def post(self, request, team_id, *args, **kwargs):
     serializer = TeamCertificatesCSerializer(data=request.data)
     serializer.is_valid()
     data = serializer.data
     data.update({"tenant": self.team, "certificate_id": make_uuid()})
     new_c = domain_service.add_certificate(**data)
     rst = new_c.to_dict()
     rst["id"] = rst["ID"]
     rst_serializer = TeamCertificatesRSerializer(data=rst)
     rst_serializer.is_valid(raise_exception=True)
     return Response(rst_serializer.data, status=status.HTTP_200_OK)
示例#2
0
    def put(self, request, team_id, certificate_id, *args, **kwargs):
        serializer = TeamCertificatesCSerializer(data=request.data)

        serializer.is_valid()
        data = serializer.data
        data.update({"tenant": self.team, "certificate_id": certificate_id})
        new_c = domain_service.update_certificate(**data)
        rst = new_c.to_dict()
        rst["id"] = rst["ID"]
        if isinstance(rst["certificate"], bytes):
            rst["certificate"] = rst["certificate"].decode()
        rst_serializer = TeamCertificatesRSerializer(data=rst)
        rst_serializer.is_valid(raise_exception=True)
        return Response(rst_serializer.data, status=status.HTTP_200_OK)
示例#3
0
class TeamCertificatesRUDView(TeamAPIView):
    @swagger_auto_schema(
        operation_description="获取团队下证书列表",
        responses={200: TeamCertificatesRSerializer()},
        tags=['openapi-team'],
    )
    def get(self, request, team_id, certificate_id, *args, **kwargs):
        code, msg, certificate = domain_service.get_certificate_by_pk(
            certificate_id)
        if code != 200:
            raise ServiceHandleException(msg=None,
                                         status_code=code,
                                         msg_show=msg)
        serializer = TeamCertificatesRSerializer(data=certificate)
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data, status.HTTP_200_OK)

    @swagger_auto_schema(
        operation_description="更新证书",
        request_body=TeamCertificatesCSerializer(),
        responses={
            status.HTTP_200_OK: TeamCertificatesRSerializer(),
            status.HTTP_500_INTERNAL_SERVER_ERROR: None,
            status.HTTP_400_BAD_REQUEST: None,
        },
        tags=['openapi-team'],
    )
    def put(self, request, team_id, certificate_id, *args, **kwargs):
        serializer = TeamCertificatesCSerializer(data=request.data)

        serializer.is_valid()
        data = serializer.data
        data.update({"tenant": self.team, "certificate_id": certificate_id})
        new_c = domain_service.update_certificate(**data)
        rst = new_c.to_dict()
        rst["id"] = rst["ID"]
        rst_serializer = TeamCertificatesRSerializer(data=rst)
        rst_serializer.is_valid(raise_exception=True)
        return Response(rst_serializer.data, status=status.HTTP_200_OK)

    @swagger_auto_schema(
        operation_description="删除证书",
        responses={
            status.HTTP_201_CREATED: None,
            status.HTTP_500_INTERNAL_SERVER_ERROR: None,
            status.HTTP_400_BAD_REQUEST: None,
        },
        tags=['openapi-team'],
    )
    def delete(self, request, team_id, certificate_id, *args, **kwargs):
        domain_service.delete_certificate_by_pk(certificate_id)
        return Response(data=None, status=status.HTTP_200_OK)
示例#4
0
class TeamCertificatesLCView(TeamNoRegionAPIView):
    @swagger_auto_schema(
        operation_description="获取团队下证书列表",
        manual_parameters=[
            openapi.Parameter("page",
                              openapi.IN_QUERY,
                              description="页码",
                              type=openapi.TYPE_NUMBER),
            openapi.Parameter("page_size",
                              openapi.IN_QUERY,
                              description="每页数量",
                              type=openapi.TYPE_NUMBER),
        ],
        responses={200: TeamCertificatesLSerializer()},
        tags=['openapi-team'],
    )
    def get(self, request, team_id, *args, **kwargs):
        page = int(request.GET.get("page", 1))
        page_size = int(request.GET.get("page_size", 10))
        certificates, nums = domain_service.get_certificate(
            self.team, page, page_size)
        data = pagination(certificates, nums, page, page_size)
        serializer = TeamCertificatesLSerializer(data=data)
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data, status.HTTP_200_OK)

    @swagger_auto_schema(
        operation_description="添加证书",
        request_body=TeamCertificatesCSerializer(),
        responses={
            status.HTTP_200_OK: TeamCertificatesRSerializer(),
        },
        tags=['openapi-team'],
    )
    def post(self, request, team_id, *args, **kwargs):
        serializer = TeamCertificatesCSerializer(data=request.data)
        serializer.is_valid()
        data = serializer.data
        data.update({"tenant": self.team, "certificate_id": make_uuid()})
        new_c = domain_service.add_certificate(**data)
        rst = new_c.to_dict()
        rst["id"] = rst["ID"]
        if isinstance(rst["certificate"], bytes):
            rst["certificate"] = rst["certificate"].decode()
        rst_serializer = TeamCertificatesRSerializer(data=rst)
        rst_serializer.is_valid(raise_exception=True)
        return Response(rst_serializer.data, status=status.HTTP_200_OK)