0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-30 19:41:46 +01:00
posthog/ee/api/license.py
Tim Glaser 5cfbc49cc3
Add clickhouse and max users to license (#3918)
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-04-14 08:45:39 -07:00

38 lines
1017 B
Python

from typing import Any
from django.conf import settings
from django.db.models import QuerySet
from rest_framework import mixins, serializers, viewsets
from ee.models.license import License
class LicenseSerializer(serializers.ModelSerializer):
class Meta:
model = License
fields = [
"id",
"key",
"plan",
"valid_until",
"max_users",
"created_at",
]
read_only_fields = ["plan", "valid_until", "max_users"]
def create(self, validated_data: Any) -> Any:
return super().create({"key": validated_data.get("key")})
class LicenseViewSet(
mixins.ListModelMixin, mixins.RetrieveModelMixin, mixins.CreateModelMixin, viewsets.GenericViewSet,
):
queryset = License.objects.all()
serializer_class = LicenseSerializer
def get_queryset(self) -> QuerySet:
if getattr(settings, "MULTI_TENANCY", False):
return License.objects.none()
return super().get_queryset()