Add UserDomainRole table and helpers

This commit is contained in:
Neil Martinsen-Burrell 2023-03-06 12:03:29 -06:00
parent 22eb49c004
commit 49b4f078e8
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
9 changed files with 211 additions and 7 deletions

View file

@ -502,6 +502,25 @@ class DomainApplication(TimeStampedModel):
# This is a side-effect of the state transition
self._send_confirmation_email()
@transition(field="status", source=[SUBMITTED, INVESTIGATING], target=APPROVED)
def approve(self):
"""Approve an application that has been submitted.
This has substantial side-effects because it creates another database
object for the approved Domain and makes the user who created the
application into an admin on that domain.
"""
# create the domain if it doesn't exist
Domain = apps.get_model("registrar.Domain")
created_domain, _ = Domain.objects.get_or_create(name=self.requested_domain)
# create the permission for the user
UserDomainRole = apps.get_model("registrar.UserDomainRole")
UserDomainRole.objects.get_or_create(
user=self.creator, domain=created_domain, role=UserDomainRole.Roles.ADMIN
)
# ## Form policies ###
#
# These methods control what questions need to be answered by applicants