diff --git a/mozillians/groups/tasks.py b/mozillians/groups/tasks.py index ea6576a27..5674fecf5 100644 --- a/mozillians/groups/tasks.py +++ b/mozillians/groups/tasks.py @@ -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') @@ -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 diff --git a/mozillians/groups/tests/test_tasks.py b/mozillians/groups/tests/test_tasks.py index cbf19fd34..b79c9539c 100644 --- a/mozillians/groups/tests/test_tasks.py +++ b/mozillians/groups/tests/test_tasks.py @@ -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: