From e098ed4f013e80f651dc1668060da0742bb6e4b5 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Mon, 1 May 2023 17:37:57 +1000 Subject: [PATCH] Automatically email all members of the applicable committee when a comment is left on an endorsed budget --- sstreasury/views.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sstreasury/views.py b/sstreasury/views.py index 23e6697..fbef3fb 100644 --- a/sstreasury/views.py +++ b/sstreasury/views.py @@ -380,13 +380,29 @@ def budget_action(request, budget, revision): comment.content = request.POST['comment'] comment.save() - emailer = Emailer() + # Get users to email about the comment + users_to_email = set() + + # Email Treasury for user in User.objects.filter(groups__name='Treasury'): if user != request.user: - emailer.send_mail([user.email], 'New comment on budget: {} (BU-{})'.format(revision.name, budget.id), 'sstreasury/email/budget_commented.md', {'revision': revision, 'comment': comment}) + users_to_email.add(user.email) + + # Email contributors for user in revision.contributors.all(): if user != request.user: - emailer.send_mail([user.email], 'New comment on budget: {} (BU-{})'.format(revision.name, budget.id), 'sstreasury/email/budget_commented.md', {'revision': revision, 'comment': comment}) + users_to_email.add(user.email) + + # If endorsed budget, email committee + if revision.state == models.BudgetState.ENDORSED.value: + for user in User.objects.filter(groups__name=revision.approver): + if user != request.user: + users_to_email.add(user.email) + + # Send emails + emailer = Emailer() + for email in users_to_email: + emailer.send_mail([email], 'New comment on budget: {} (BU-{})'.format(revision.name, budget.id), 'sstreasury/email/budget_commented.md', {'revision': revision, 'comment': comment}) if 'Submit' in actions: if not revision.can_submit(request.user):