Skip to content

Commit

Permalink
✨(domains) store last check domain results
Browse files Browse the repository at this point in the history
  • Loading branch information
sdemagny committed Feb 7, 2025
1 parent 3de495a commit 1047423
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.5 on 2025-02-07 17:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mailbox_manager', '0017_alter_maildomain_status'),
]

operations = [
migrations.AddField(
model_name='maildomain',
name='last_check_details',
field=models.JSONField(blank=True, null=True, verbose_name='last check details'),
),
]
3 changes: 3 additions & 0 deletions src/backend/mailbox_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class MailDomain(BaseModel):
default=MailDomainStatusChoices.PENDING,
choices=MailDomainStatusChoices.choices,
)
last_check_details = models.JSONField(
null=True, blank=True, verbose_name=_("last check details")
)

class Meta:
db_table = "people_mail_domain"
Expand Down
4 changes: 4 additions & 0 deletions src/backend/mailbox_manager/utils/dimail.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def fetch_domain_status(self, domain):
):
self.enable_pending_mailboxes(domain)
domain.status = enums.MailDomainStatusChoices.ENABLED
domain.last_check_details = dimail_response
domain.save()
# if dimail returns broken status, we need to extract external and internal checks
# and manage the case where the domain has to be fixed by support
Expand All @@ -465,6 +466,7 @@ def fetch_domain_status(self, domain):
# manage the case where the domain has to be fixed by support
if not all(external_checks.values()):
domain.status = enums.MailDomainStatusChoices.ACTION_REQUIRED
domain.last_check_details = dimail_response
domain.save()
# if all external checks are ok but not internal checks, we need to fix internal checks
elif all(external_checks.values()) and not all(internal_checks.values()):
Expand All @@ -479,11 +481,13 @@ def fetch_domain_status(self, domain):
)
if all(external_checks.values()) and all(internal_checks.values()):
domain.status = enums.MailDomainStatusChoices.ENABLED
domain.last_check_details = dimail_response
domain.save()
elif all(external_checks.values()) and not all(
internal_checks.values()
):
domain.status = enums.MailDomainStatusChoices.FAILED
domain.last_check_details = dimail_response
domain.save()
return dimail_response

Expand Down

0 comments on commit 1047423

Please sign in to comment.