Exemplo n.º 1
0
class DomainRenewOrderViewSet(mixins.RetrieveModelMixin,
                              mixins.UpdateModelMixin, mixins.ListModelMixin,
                              viewsets.GenericViewSet):
    serializer_class = serializers.DomainRenewOrderSerializer
    queryset = models.DomainRenewOrder.objects.all()
    permission_classes = [permissions.keycloak(models.DomainRenewOrder)]

    def filter_queryset(self, queryset):
        if not isinstance(self.request.auth, auth.OAuthToken):
            raise PermissionDenied

        return models.DomainRenewOrder.get_object_list(self.request.auth.token)
Exemplo n.º 2
0
class ContactAddressViewSet(viewsets.ModelViewSet):
    serializer_class = serializers.ContactAddressSerializer
    queryset = models.ContactAddress.objects.all()
    permission_classes = [permissions.keycloak(models.ContactAddress)]

    def filter_queryset(self, queryset):
        if not isinstance(self.request.auth, auth.OAuthToken):
            raise PermissionDenied

        return models.ContactAddress.get_object_list(self.request.auth.token)

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)

    def perform_destroy(self, instance):
        if instance.can_delete():
            instance.delete()
        else:
            raise exceptions.PermissionDenied(
                "Object status prohibits deletion")