feat: add email notifications for suffix approval process

Introduced email notifications for the suffix approval process:
- Notify prefix owners when a new suffix requires approval
- Notify users when their suffix has been approved

This helps keep stakeholders informed about the status of their suffix requests, improving transparency and workflow efficiency.
This commit is contained in:
Kumi 2024-06-24 13:15:42 +02:00
parent 26d46853c4
commit 2a9d093ec6
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -10,6 +10,7 @@ from django.views.generic import (
)
from django.shortcuts import get_object_or_404, redirect
from django.http import HttpResponseBadRequest, Http404
from django.core.mail import send_mail
from rest_framework import generics, permissions
from rest_framework.exceptions import PermissionDenied
from .serializers import SuffixSerializer, IdentifierSerializer
@ -179,6 +180,13 @@ class SuffixCreateView(LoginRequiredMixin, CreateView):
or form.instance.prefix.owner == self.request.user
):
form.instance.approved = True
else:
send_mail(
"New Suffix Pending Approval",
f"A new suffix has been created by {self.request.user.email} and is pending approval.",
None,
[form.instance.prefix.owner.email],
)
return super().form_valid(form)
@ -216,6 +224,14 @@ class SuffixApprovalView(LoginRequiredMixin, UpdateView):
def form_valid(self, form):
form.instance.approved = True
send_mail(
"Suffix Approved",
f"Your suffix { form.instance.prefix.prefix }.{form.instance.suffix} has been approved.",
None,
[form.instance.owner.email],
)
return super().form_valid(form)