Automatically email all members of the applicable committee when a comment is left on an endorsed budget

This commit is contained in:
Yingtong Li 2023-05-01 17:37:57 +10:00
parent 4f84e8a99f
commit e098ed4f01
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 19 additions and 3 deletions

View File

@ -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):