Skip to content

Commit

Permalink
feat(api): improve registration suspended error message, closes #905
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Apr 25, 2024
1 parent 5a317cc commit 5ec3aa3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/desecapi/tests/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def test_create_local_public_suffixes_lps_disabled(self):
domain = "foo." + next(iter(self.AUTO_DELEGATION_DOMAINS))
response = self.client.post(self.reverse("v1:domain-list"), {"name": domain})
self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["name"][0].code, "name_unavailable")
self.assertEqual(response.data["name"][0].code, "registration_suspended")

def test_create_domain_under_public_suffix_with_private_parent(self):
name = "amazonaws.com"
Expand Down
14 changes: 8 additions & 6 deletions api/desecapi/views/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ 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
):
domain = Domain(name=serializer.validated_data["name"])
if not settings.REGISTER_LPS and domain.is_locally_registrable:
raise ValidationError(
{"name": [DomainSerializer.default_error_messages["name_unavailable"]]},
code="name_unavailable",
{
"name": [
f"Domain registration under {domain.parent_domain_name} is currently suspended."
]
},
code="registration_suspended",
)
with PDNSChangeTracker():
domain = serializer.save(owner=self.request.user)
Expand Down

0 comments on commit 5ec3aa3

Please sign in to comment.