Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Do not send pending notification to CLOSED groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas committed Apr 7, 2017
1 parent be47e9c commit de8876f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions mozillians/groups/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ def send_pending_membership_emails():
from mozillians.groups.models import Group, GroupMembership

# Curated groups that have pending membership requests
groups = Group.objects.exclude(curators__isnull=True)
groups = Group.objects.exclude(curators__isnull=True, accepting_new_members=Group.CLOSED)
groups = groups.filter(groupmembership__status=GroupMembership.PENDING).distinct()

for group in groups:
# what's the max pk of pending memberships?
pending_memberships = group.groupmembership_set.filter(status=GroupMembership.PENDING)
max_pk = pending_memberships.aggregate(max_pk=Max('pk'))['max_pk']
curators = group.curators.all()
# Only send reminder if there are newer requests than we'd previously reminded about
if max_pk > group.max_reminder:
if max_pk > group.max_reminder and curators:
# TODO: Switch locale to curator's preferred language so translation will occur
# Using English for now
activate('en-us')
Expand All @@ -69,7 +70,7 @@ def send_pending_membership_emails():
})

send_mail(subject, body, settings.FROM_NOREPLY,
[profile.user.email for profile in group.curators.all()],
[profile.user.email for profile in curators],
fail_silently=False)

group.max_reminder = max_pk
Expand Down
2 changes: 1 addition & 1 deletion mozillians/groups/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_sending_pending_email_already_sent(self):

def test_sending_pending_email_non_curated(self):
# If a non-curated group has a pending membership, do not send anyone an email
group = GroupFactory.create()
group = GroupFactory.create(accepting_new_members=Group.REVIEWED)
user = UserFactory.create()
group.add_member(user.userprofile, GroupMembership.PENDING)
with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
Expand Down

0 comments on commit de8876f

Please sign in to comment.