mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-24 09:14:46 +01:00
5cfbc49cc3
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
38 lines
1017 B
Python
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()
|