Implement all statuses in application admin class, implement approved email, consolidate email methods in application model class, unit test emails sends as side-effects of admin save

This commit is contained in:
rachidatecs 2023-06-20 19:10:58 -04:00
parent 14f6a92f9f
commit 94d5682b24
No known key found for this signature in database
GPG key ID: 3CEBBFA7325E5525
5 changed files with 228 additions and 60 deletions

View file

@ -90,16 +90,36 @@ class DomainApplicationAdmin(AuditedAdmin):
# Get the original application from the database
original_obj = models.DomainApplication.objects.get(pk=obj.pk)
if (
obj.status != original_obj.status
and obj.status == models.DomainApplication.INVESTIGATING
):
# This is a transition annotated method in model which will throw an
# error if the condition is violated. To make this work, we need to
# call it on the original object which has the right status value,
# but pass the current object which contains the up-to-date data
# for the email.
original_obj.in_review(obj)
if obj.status != original_obj.status:
if obj.status == models.DomainApplication.STARTED:
# No conditions
pass
if obj.status == models.DomainApplication.SUBMITTED:
# This is an fsm in model which will throw an error if the
# transition condition is violated, so we call it on the
# original object which has the right status value, and pass
# the updated object which contains the up-to-date data
# for the side effects (like an email send).
original_obj.submit(updated_domain_application=obj)
if obj.status == models.DomainApplication.INVESTIGATING:
# This is an fsm in model which will throw an error if the
# transition condition is violated, so we call it on the
# original object which has the right status value, and pass
# the updated object which contains the up-to-date data
# for the side effects (like an email send).
original_obj.in_review(updated_domain_application=obj)
if obj.status == models.DomainApplication.APPROVED:
# This is an fsm in model which will throw an error if the
# transition condition is violated, so we call it on the
# original object which has the right status value, and pass
# the updated object which contains the up-to-date data
# for the side effects (like an email send).
original_obj.approve(updated_domain_application=obj)
if obj.status == models.DomainApplication.WITHDRAWN:
# This is a transition annotated method in model which will throw an
# error if the condition is violated. To make this work, we need to
# call it on the original object which has the right status value.
original_obj.withdraw()
super().save_model(request, obj, form, change)