Skip to content

Commit

Permalink
feat(api): disable registration under LPS via POST domains/
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Jan 12, 2024
1 parent fc61014 commit ebe2428
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/desecapi/views/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated, SAFE_METHODS
from rest_framework.response import Response
from rest_framework.serializers import ValidationError
from rest_framework.settings import api_settings
from rest_framework.views import APIView

Expand Down Expand Up @@ -83,6 +84,14 @@ def get_serializer(self, *args, **kwargs):
return super().get_serializer(*args, include_keys=include_keys, **kwargs)

def perform_create(self, serializer):
if (
not settings.REGISTER_LPS
and Domain(name=serializer.validated_data["name"]).is_locally_registrable
):
raise ValidationError(
{"name": [DomainSerializer.default_error_messages["name_unavailable"]]},
code="name_unavailable",
)
with PDNSChangeTracker():
domain = serializer.save(owner=self.request.user)

Expand Down

0 comments on commit ebe2428

Please sign in to comment.