Don't let users unsubscribe from mandatory things (bug 698160)

This commit is contained in:
Gregory Koberger 2011-11-04 12:12:13 -07:00
Родитель 8342607eca
Коммит b7171080ca
3 изменённых файлов: 32 добавлений и 4 удалений

Просмотреть файл

@ -4,4 +4,10 @@
You received this email because you're subscribed to:
* email me when {{ perm_setting }}
Unsubscribe: {{ unsubscribe }}
{% if mandatory %}
You can't unsubscribe from this type of emails.
Manage email notifications: {{ manage_url }}
{% else %}
Unsubscribe: {{ unsubscribe_url }}
{% endif %}

Просмотреть файл

@ -78,6 +78,24 @@ class SendMailTest(test.TestCase):
assert success, "Email wasn't sent"
eq_(len(mail.outbox), 1)
def test_user_mandatory(self):
""" Make sure there's no unsubscribe link in mandatory emails. """
user = UserProfile.objects.all()[0]
to = user.email
n = users.notifications.NOTIFICATIONS_BY_SHORT['individual_contact']
UserNotification.objects.get_or_create(notification_id=n.id,
user=user, enabled=True)
assert n.mandatory, "Notification isn't mandatory"
success = send_mail('test subject', 'test body', perm_setting=n,
recipient_list=[to], fail_silently=False)
body = mail.outbox[0].body
assert "Unsubscribe:" not in body
assert "You can't unsubscribe from" in body
def test_user_setting_unchecked(self):
user = UserProfile.objects.all()[0]
to = user.email

Просмотреть файл

@ -172,11 +172,15 @@ def send_mail(subject, message, from_email=None, recipient_list=None,
# Add unsubscribe link to footer
token, hash = UnsubscribeCode.create(recipient)
from amo.helpers import absolutify
url = absolutify(reverse('users.unsubscribe',
unsubscribe_url = absolutify(reverse('users.unsubscribe',
args=[token, hash, perm_setting.short]))
context = {'message': message, 'unsubscribe': url,
manage_url = ('%s#acct-notify' %
absolutify(reverse('users.edit')))
context = {'message': message, 'manage_url': manage_url,
'unsubscribe_url': unsubscribe_url,
'perm_setting': perm_setting.label,
'SITE_URL': settings.SITE_URL}
'SITE_URL': settings.SITE_URL,
'mandatory': perm_setting.mandatory }
send_message = template.render(Context(context,
autoescape=False))