send notification on nameserver changes

This commit is contained in:
matthewswspence 2024-09-10 15:37:04 -05:00
parent ffaf3b5a37
commit 9c090ae5fe
No known key found for this signature in database
GPG key ID: FB458202A7852BA4
2 changed files with 29 additions and 0 deletions

View file

@ -39,6 +39,7 @@ class UserFixture:
"username": "be17c826-e200-4999-9389-2ded48c43691",
"first_name": "Matthew",
"last_name": "Spence",
"email": "mspence1845@gmail.com"
},
{
"username": "5f283494-31bd-49b5-b024-a7e7cae00848",
@ -155,6 +156,7 @@ class UserFixture:
"username": "d6bf296b-fac5-47ff-9c12-f88ccc5c1b99",
"first_name": "Matthew-Analyst",
"last_name": "Spence-Analyst",
"email": "mspence1845+1@gmail.com"
},
{
"username": "319c490d-453b-43d9-bc4d-7d6cd8ff6844",

View file

@ -441,6 +441,9 @@ class DomainNameserversView(DomainFormBaseView):
# no server information in this field, skip it
pass
old_nameservers = self.object.nameservers
should_notify = old_nameservers and old_nameservers != nameservers
try:
self.object.nameservers = nameservers
except NameserverError as Err:
@ -467,6 +470,30 @@ class DomainNameserversView(DomainFormBaseView):
"48 hours to propagate across the internet.",
)
# if the nameservers where changed, send notification to domain managers.
if should_notify:
managers = UserDomainRole.objects.filter(domain=self.object.name, role=UserDomainRole.Roles.MANAGER)
emails = list(managers.values_list("user", flat=True).values_list("email", flat=True))
to_addresses=', '.join(emails)
try:
send_templated_email(
"templateName",
"Subject Template Name",
to_address=to_addresses,
context={
"nameservers": nameservers,
"domain": self.object,
},
)
except EmailSendingError as exc:
logger.warn(
"Could not sent notification email to %s for domain %s",
to_addresses,
self.object,
exc_info=True,
)
# superclass has the redirect
return super().form_valid(formset)