Manage hosting account retirement and name release in the panel
This commit is contained in:
1 parent
47a4d4e6cb
commit
103783c5d8
25 files changed
+994
-49
No files matched your search
@@ -291,7 +291,8 @@ class HostingPlan(models.Model):
|
||||
|
||||
class HostingAccount(models.Model):
|
||||
name = models.CharField(max_length=120)
|
||||
primary_domain = DomainNameField(max_length=253, unique=True)
|
||||
primary_domain = DomainNameField(max_length=253, unique=True, null=True)
|
||||
retired_at = models.DateTimeField(null=True, blank=True)
|
||||
hosting_plan = models.ForeignKey(
|
||||
HostingPlan, on_delete=models.PROTECT, null=True, blank=True
|
||||
)
|
||||
@@ -321,7 +322,12 @@ class HostingAccount(models.Model):
|
||||
scheduled_backups_to_keep__lte=MAX_RETAINED_BACKUPS,
|
||||
),
|
||||
name="hosting_account_valid_backup_retention",
|
||||
)
|
||||
),
|
||||
models.CheckConstraint(
|
||||
condition=models.Q(primary_domain__isnull=False)
|
||||
| models.Q(retired_at__isnull=False),
|
||||
name="hosting_account_active_domain_required",
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
@@ -332,6 +338,9 @@ class HostingAccount(models.Model):
|
||||
if update_fields is not None and "primary_domain" not in update_fields:
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
if self.primary_domain is None and self.retired_at is not None:
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
self.primary_domain = self._meta.get_field("primary_domain").to_python(
|
||||
self.primary_domain
|
||||
)
|
||||
@@ -606,6 +615,51 @@ class ProvisioningJob(models.Model):
|
||||
return "running" if self.started_at else "queued"
|
||||
|
||||
|
||||
class AccountRetirement(models.Model):
|
||||
class Policy(models.TextChoices):
|
||||
HOLD = "hold", "Keep names reserved"
|
||||
RELEASE = "release", "Release names and retain data"
|
||||
|
||||
account = models.OneToOneField(
|
||||
HostingAccount, on_delete=models.PROTECT, related_name="retirement"
|
||||
)
|
||||
primary_domain = DomainNameField(max_length=253)
|
||||
policy = models.CharField(max_length=8, choices=Policy)
|
||||
inventory = models.JSONField()
|
||||
history = models.JSONField(default=list)
|
||||
requested_at = models.DateTimeField(default=timezone.now)
|
||||
released_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-pk",)
|
||||
permissions = [
|
||||
("retire_hosting_account", "Can retire hosting accounts")
|
||||
]
|
||||
|
||||
|
||||
class AccountRetirementJob(ProvisioningJob):
|
||||
class Kind(models.TextChoices):
|
||||
ALIAS = "alias", "Website alias"
|
||||
WEB = "web", "Website and SFTP"
|
||||
DATABASE = "database", "Database"
|
||||
MAILBOX = "mailbox", "Mailbox"
|
||||
DNS = "dns", "DNS zone"
|
||||
|
||||
retirement = models.ForeignKey(
|
||||
AccountRetirement, on_delete=models.CASCADE, related_name="jobs"
|
||||
)
|
||||
operation_id = models.UUIDField(default=uuid.uuid4, unique=True)
|
||||
kind = models.CharField(max_length=8, choices=Kind)
|
||||
target = models.CharField(max_length=254)
|
||||
manifest = models.JSONField()
|
||||
|
||||
class Meta:
|
||||
ordering = ("kind", "target")
|
||||
indexes = [
|
||||
models.Index(fields=("kind", "finished_at", "requested_at"))
|
||||
]
|
||||
|
||||
|
||||
class AccountServiceChange(models.Model):
|
||||
account = models.ForeignKey(
|
||||
HostingAccount,
|
||||
|
||||
Reference in new issue
Block a user