Add email notification for staff
This commit is contained in:
@@ -295,11 +295,14 @@ class Submission(models.Model):
|
||||
depend on the caller remembering to set it.
|
||||
|
||||
Additionally: when an UPDATE flips `status` to a state with a
|
||||
dedicated email (`rejected`, `printing`, `completed`), this method
|
||||
queues the matching `send_*_email()` via `transaction.on_commit`.
|
||||
Centralising the dispatch here means **every** save path -- admin,
|
||||
the validation worker, ad-hoc shell, any future view -- fires the
|
||||
email through a single hook. Plan.md §7.3.
|
||||
dedicated email (`rejected`, `printing`, `completed`, `verifying`),
|
||||
this method queues the matching `send_*_email()` via
|
||||
`transaction.on_commit`. Centralising the dispatch here means
|
||||
**every** save path -- admin, the validation worker, ad-hoc shell,
|
||||
any future view -- fires the email through a single hook. The
|
||||
`verifying` branch is a staff broadcast (the user-facing
|
||||
`send_verifying_email` is still emitted explicitly by the worker
|
||||
on its success branch). Plan.md §7.3.
|
||||
"""
|
||||
if not self.slug:
|
||||
self.slug = self._generate_unique_slug()
|
||||
@@ -323,9 +326,9 @@ class Submission(models.Model):
|
||||
# Fire on TRANSITIONS only: an UPDATE that flips status into one of
|
||||
# the email-bearing target states. Don't fire on inserts that start
|
||||
# out in those states -- by plan.md §7.3 no submit-time edge lands
|
||||
# in rejected/printing/completed, and even if some weird path did,
|
||||
# we'd rather stay silent than send "your print is ready" to a fresh
|
||||
# victim of a fixture/data-migration import.
|
||||
# in rejected/printing/completed/verifying, and even if some weird
|
||||
# path did, we'd rather stay silent than send "your print is ready"
|
||||
# to a fresh victim of a fixture/data-migration import.
|
||||
if not is_new and old_status != new_status:
|
||||
# Local imports keep this module out of the apps/submissions
|
||||
# import-cycle (emails.py imports from here).
|
||||
@@ -334,6 +337,7 @@ class Submission(models.Model):
|
||||
send_completed_email,
|
||||
send_printing_email,
|
||||
send_rejection_email,
|
||||
send_staff_verify_email,
|
||||
)
|
||||
|
||||
if new_status == self.Status.REJECTED:
|
||||
@@ -350,6 +354,10 @@ class Submission(models.Model):
|
||||
transaction.on_commit(
|
||||
lambda sub=self: send_completed_email(sub)
|
||||
)
|
||||
elif new_status == self.Status.VERIFYING:
|
||||
transaction.on_commit(
|
||||
lambda sub=self: send_staff_verify_email(sub)
|
||||
)
|
||||
|
||||
# Refresh the snapshot so a follow-up save on the same instance
|
||||
# compares against the just-persisted state, not the original load.
|
||||
|
||||
Reference in New Issue
Block a user