Create a DraftDomain model for requested domains

This commit is contained in:
Seamus Johnston 2023-05-25 13:53:02 -05:00
parent 93427ad072
commit 7a3e1bcb2c
No known key found for this signature in database
GPG key ID: 2F21225985069105
15 changed files with 272 additions and 124 deletions

View file

@ -400,10 +400,19 @@ class DomainApplication(TimeStampedModel):
related_name="current+",
)
requested_domain = models.OneToOneField(
approved_domain = models.OneToOneField(
"Domain",
null=True,
blank=True,
help_text="The approved domain",
related_name="domain_application",
on_delete=models.PROTECT,
)
requested_domain = models.OneToOneField(
"DraftDomain",
null=True,
blank=True,
help_text="The requested domain",
related_name="domain_application",
on_delete=models.PROTECT,
@ -499,8 +508,8 @@ class DomainApplication(TimeStampedModel):
if self.requested_domain is None:
raise ValueError("Requested domain is missing.")
Domain = apps.get_model("registrar.Domain")
if not Domain.string_could_be_domain(self.requested_domain.name):
DraftDomain = apps.get_model("registrar.DraftDomain")
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
raise ValueError("Requested domain is not a valid domain name.")
# When an application is submitted, we need to send a confirmation email
@ -516,13 +525,16 @@ class DomainApplication(TimeStampedModel):
application into an admin on that domain.
"""
# create the domain if it doesn't exist
# create the domain
Domain = apps.get_model("registrar.Domain")
created_domain, _ = Domain.objects.get_or_create(name=self.requested_domain)
if Domain.objects.filter(name=self.requested_domain.name).exists():
raise ValueError("Cannot approve. Requested domain is already in use.")
created_domain = Domain.objects.create(name=self.requested_domain.name)
self.approved_domain = created_domain
# copy the information from domainapplication into domaininformation
DomainInformation = apps.get_model("registrar.DomainInformation")
DomainInformation.create_from_da(self)
DomainInformation.create_from_da(self, domain=created_domain)
# create the permission for the user
UserDomainRole = apps.get_model("registrar.UserDomainRole")