diff --git a/apps/zadmin/forms.py b/apps/zadmin/forms.py index 6ecd618356..290835df5b 100644 --- a/apps/zadmin/forms.py +++ b/apps/zadmin/forms.py @@ -35,9 +35,9 @@ class DevMailerForm(happyforms.Form): ('sdk', 'Developers of active SDK add-ons'), ('apps', 'Developers of active apps (not add-ons)'), ('payments', - 'Developers of active apps (not add-ons) with payments'), + 'Developers of non-deleted apps (not add-ons) with payments'), ('desktop_apps', - 'Developers of active apps supported on desktop')] + 'Developers of non-deleted apps supported on desktop')] recipients = forms.ChoiceField(choices=_choices, required=True) subject = forms.CharField(widget=forms.TextInput(attrs=dict(size='100')), required=True) diff --git a/apps/zadmin/tests/test_views.py b/apps/zadmin/tests/test_views.py index 727186576c..cd3c2cc6b3 100644 --- a/apps/zadmin/tests/test_views.py +++ b/apps/zadmin/tests/test_views.py @@ -33,6 +33,7 @@ from users.models import UserProfile from users.utils import get_task_user from versions.models import ApplicationsVersions, Version from zadmin import forms, tasks +from zadmin.forms import DevMailerForm from zadmin.models import EmailPreviewTopic, ValidationJob, ValidationResult from zadmin.views import completed_versions_dirty, find_files @@ -1930,6 +1931,18 @@ class TestEmailDevs(amo.tests.TestCase): self.assertNoFormErrors(res) eq_(len(mail.outbox), 1) + mail.outbox = [] + self.addon.update(status=amo.STATUS_PENDING) + res = self.post(recipients='payments') + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 1) + + mail.outbox = [] + self.addon.update(status=amo.STATUS_DELETED) + res = self.post(recipients='payments') + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 0) + def test_only_desktop_apps(self): from addons.models import AddonDeviceType self.addon.update(type=amo.ADDON_WEBAPP) @@ -1939,23 +1952,46 @@ class TestEmailDevs(amo.tests.TestCase): self.assertNoFormErrors(res) eq_(len(mail.outbox), 0) + mail.outbox = [] AddonDeviceType.objects.create(addon=self.addon, device_type=amo.DEVICE_DESKTOP.id) res = self.post(recipients='desktop_apps') self.assertNoFormErrors(res) eq_(len(mail.outbox), 1) + mail.outbox = [] + self.addon.update(status=amo.STATUS_PENDING) + res = self.post(recipients='desktop_apps') + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 1) + + mail.outbox = [] + self.addon.update(status=amo.STATUS_DELETED) + res = self.post(recipients='desktop_apps') + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 0) + def test_only_apps(self): self.addon.update(type=amo.ADDON_WEBAPP) res = self.post(recipients='apps') self.assertNoFormErrors(res) eq_(len(mail.outbox), 1) - def test_ignore_deleted(self): + def test_ignore_deleted_always(self): self.addon.update(status=amo.STATUS_DELETED) - res = self.post() - self.assertNoFormErrors(res) - eq_(len(mail.outbox), 0) + for name, label in DevMailerForm._choices: + res = self.post(recipients=name) + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 0) + + def test_exclude_pending_for_addons(self): + self.addon.update(status=amo.STATUS_PENDING) + for name, label in DevMailerForm._choices: + if name in ('payments', 'desktop_apps'): + continue + res = self.post(recipients=name) + self.assertNoFormErrors(res) + eq_(len(mail.outbox), 0) class TestPerms(amo.tests.TestCase): diff --git a/apps/zadmin/views.py b/apps/zadmin/views.py index f80d69327a..a3c68c3ad4 100644 --- a/apps/zadmin/views.py +++ b/apps/zadmin/views.py @@ -620,11 +620,15 @@ def email_devs(request): preview_csv = None if request.method == 'POST' and form.is_valid(): data = form.cleaned_data - listed = amo.LISTED_STATUSES qs = (AddonUser.objects.filter(role__in=(amo.AUTHOR_ROLE_DEV, - amo.AUTHOR_ROLE_OWNER), - addon__status__in=listed) + amo.AUTHOR_ROLE_OWNER)) .exclude(user__email=None)) + + if data['recipients'] in ('payments', 'desktop_apps'): + qs = qs.exclude(addon__status=amo.STATUS_DELETED) + else: + qs = qs.filter(addon__status__in=amo.LISTED_STATUSES) + if data['recipients'] == 'eula': qs = qs.exclude(addon__eula=None) elif data['recipients'] == 'payments':