diff --git a/dev-requirements.txt b/dev-requirements.txt index 56cf461..e3d882a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,5 +1,4 @@ tox mock -django-nose coverage==3.7.1 vcrpy diff --git a/setup.py b/setup.py index 0ae9bdf..8dcca73 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ packages=find_packages('src'), package_dir={'': 'src'}, include_package_data=True, - install_requires=['django>=1.5', + install_requires=['django>=1.5, <1.8', 'django-browserid', 'mailmanclient'] ) diff --git a/src/postorius/models.py b/src/postorius/models.py index c21147b..295cd24 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -26,6 +26,7 @@ from datetime import datetime, timedelta from django.conf import settings from django.contrib.auth.models import User +from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse from django.core.mail import send_mail from django.db import models @@ -227,7 +228,7 @@ def __unicode__(self): return u'Address Confirmation Profile for {0}'.format(self.email) - + @property def is_expired(self): """ @@ -261,13 +262,13 @@ The following settings are recognized: >>> EMAIL_CONFIRMATION_TEMPLATE = 'postorius/address_confirmation_message.txt' - >>> EMAIL_CONFIRMATION_FROM = 'Confirmation needed' - >>> EMAIL_CONFIRMATION_SUBJECT = 'postmaster@list.org' + >>> EMAIL_CONFIRMATION_FROM = 'postmaster@list.org' + >>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed' :param request: The HTTP request object. - :type request: HTTPRequest + :type request: HTTPRequest :param template_context: The context used when rendering the template. - Falls back to host url and activation link. + Falls back to host url and activation link. :type template_context: django.template.Context """ # create the host url and the activation link need for the template @@ -276,7 +277,7 @@ url = reverse('address_activation_link', kwargs={'activation_key': self.activation_key}) activation_link = '{0}{1}'.format(host_url, url) - # Detect the right template path, either from the param, + # Detect the right template path, either from the param, # the setting or the default if not template_path: template_path = getattr(settings, @@ -289,7 +290,18 @@ {'activation_link': activation_link, 'host_url': host_url}) email_subject = getattr( settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed') + try: + sender_address = getattr(settings, 'EMAIL_CONFIRMATION_FROM') + except AttributeError: + # settings.EMAIL_CONFIRMATION_FROM is not defined, fallback + # settings.DEFAULT_EMAIL_FROM as mentioned in the django + # docs. If that also fails, raise a `ImproperlyConfigured` Error. + try: + sender_address = getattr(settings, 'DEFAULT_FROM_EMAIL') + except AttributeError: + raise ImproperlyConfigured + send_mail(email_subject, get_template(template_path).render(template_context), - getattr(settings, 'EMAIL_CONFIRMATION_FROM'), + sender_address, [self.email]) diff --git a/src/postorius/templates/postorius/base.html b/src/postorius/templates/postorius/base.html index 5c04f6c..307538e 100644 --- a/src/postorius/templates/postorius/base.html +++ b/src/postorius/templates/postorius/base.html @@ -3,7 +3,7 @@ - + Mailman/Postorius @@ -11,7 +11,6 @@ - diff --git a/src/postorius/templates/postorius/lists/memberoptions.html b/src/postorius/templates/postorius/lists/memberoptions.html index 766fc89..ffaa700 100644 --- a/src/postorius/templates/postorius/lists/memberoptions.html +++ b/src/postorius/templates/postorius/lists/memberoptions.html @@ -4,7 +4,7 @@ {% load nav_helpers %} {% block main %} - {% list_nav '' '' %} + {% list_nav '' 'Member Options' %} {% if not user.is_superuser or not user.is_list_owner %}
diff --git a/src/postorius/templates/postorius/lists/summary.html b/src/postorius/templates/postorius/lists/summary.html index f6b0fec..99fc33a 100644 --- a/src/postorius/templates/postorius/lists/summary.html +++ b/src/postorius/templates/postorius/lists/summary.html @@ -6,7 +6,7 @@ {% block body_class %}list_summary{% endblock %} {% block main %} - {% if user.is_superuser %} + {% if user.is_superuser or user.is_list_owner or user.is_list_moderator %} {% include 'postorius/menu/list_nav.html' %} {% endif %}

{{list.display_name}}

diff --git a/src/postorius/templates/postorius/login.html b/src/postorius/templates/postorius/login.html index a139223..d469816 100644 --- a/src/postorius/templates/postorius/login.html +++ b/src/postorius/templates/postorius/login.html @@ -20,7 +20,8 @@
- + + {% trans 'Login using BrowserID' %} @@ -38,22 +39,5 @@ {% endblock %} {% block additionaljs %} - - - - - - - + {% browserid_js %} {% endblock additionaljs %} diff --git a/src/postorius/templates/postorius/menu/list_nav.html b/src/postorius/templates/postorius/menu/list_nav.html index cf70c10..aaf67b0 100644 --- a/src/postorius/templates/postorius/menu/list_nav.html +++ b/src/postorius/templates/postorius/menu/list_nav.html @@ -15,7 +15,7 @@ {% if user.is_superuser or user.is_list_owner %}
  • {% trans "Settings" %}
  • {% endif %} - {% if user.is_superuser or user.is_list_moderator %} + {% if user.is_superuser or user.is_list_owner %}
  • {% trans "Mass Subscribe" %}
  • {% endif %} {% if user.is_superuser or user.is_list_moderator %} diff --git a/src/postorius/templates/postorius/user_address_activation_sent.html b/src/postorius/templates/postorius/user_address_activation_sent.html index 72cb84f..a369f77 100644 --- a/src/postorius/templates/postorius/user_address_activation_sent.html +++ b/src/postorius/templates/postorius/user_address_activation_sent.html @@ -7,4 +7,3 @@

    {% trans 'Email address activation sent' %}

    {% trans "A confirmation link has been sent to the email address you submitted. Please check your email account and click on the confirmation link to add this address for your account." %}

    {% endblock main %} - diff --git a/src/postorius/tests/mailman_api_tests/test_list_members.py b/src/postorius/tests/mailman_api_tests/test_list_members.py index 9bb7984..21884d5 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -18,7 +18,7 @@ from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from django.test import Client, SimpleTestCase +from django.test import Client, TestCase from django.test.utils import override_settings from urllib2 import HTTPError @@ -37,7 +37,7 @@ @override_settings(**API_CREDENTIALS) -class ListMembersAccessTest(SimpleTestCase): +class ListMembersAccessTest(TestCase): """Tests for the list members page. Tests permissions and creation of list owners and moderators. @@ -109,7 +109,7 @@ @override_settings(**API_CREDENTIALS) -class AddOwnerTest(SimpleTestCase): +class AddOwnerTest(TestCase): """Tests for the list members page. Tests creation of list owners. @@ -143,7 +143,7 @@ @override_settings(**API_CREDENTIALS) -class AddModeratorTest(SimpleTestCase): +class AddModeratorTest(TestCase): """Tests for the list members page. Tests creation of moderators. diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 3163da6..79483a3 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -42,7 +42,7 @@ ListSummaryView.as_view( ), name='list_summary'), url(r'^subscribe$', - ListSubsribeView.as_view( + ListSubscribeView.as_view( ), name='list_subscribe'), url(r'^unsubscribe/(?P[^/]+)$', ListUnsubscribeView.as_view( @@ -51,7 +51,7 @@ 'list_subscriptions', name='list_subscriptions'), url(r'^mass_subscribe/$', - ListMassSubsribeView.as_view( + ListMassSubscribeView.as_view( ), name='mass_subscribe'), url(r'^mass_removal/$', ListMassRemovalView.as_view( @@ -88,7 +88,8 @@ 'postorius.views', (r'^$', 'list_index'), # /account/ - url(r'^accounts/login/$', login_view, {"template_name": "postorius/login.html"}, name='user_login'), + url(r'^accounts/login/$', login_view, + {"template_name": "postorius/login.html"}, name='user_login'), url(r'^accounts/logout/$', 'user_logout', name='user_logout'), url(r'^accounts/profile/$', 'user_profile', name='user_profile'), url(r'^tasks/$', 'user_tasks', name='user_tasks'), diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 41f214d..9424c1b 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -22,11 +22,10 @@ from django.contrib.auth.decorators import (login_required, user_passes_test) from django.core.urlresolvers import reverse -from django.core.validators import validate_email -from django.core.exceptions import ValidationError - from django.shortcuts import render_to_response, redirect from django.template import RequestContext +from django.core.validators import validate_email +from django.core.exceptions import ValidationError from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ from urllib2 import HTTPError @@ -191,7 +190,7 @@ context_instance=RequestContext(request)) -class ListSubsribeView(MailingListView): +class ListSubscribeView(MailingListView): """Subscribe a mailing list.""" @@ -233,7 +232,8 @@ messages.error(request, e) return redirect('list_summary', self.mailing_list.list_id) -class ListMassSubsribeView(MailingListView): + +class ListMassSubscribeView(MailingListView): """Mass subscription.""" @@ -251,24 +251,23 @@ else: emails = request.POST["emails"].splitlines() for email in emails: - parts = email.split('@') - if len(parts) != 2 or '.' not in parts[1]: + try: + validate_email(email) + self.mailing_list.subscribe(address=email) + messages.success(request, + 'The address %s has been subscribed to %s.' % + (email, self.mailing_list.fqdn_listname)) + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError, e: + messages.error(request, e) + except ValidationError: messages.error(request, 'The email address %s is not valid.' % email) - else: - try: - self.mailing_list.subscribe(address=email) - messages.success( - request, - 'The address %s has been subscribed to %s.' % - (email, self.mailing_list.fqdn_listname)) - except MailmanApiError: - return utils.render_api_error(request) - except HTTPError, e: - messages.error(request, e) return redirect('mass_subscribe', self.mailing_list.list_id) + class ListMassRemovalView(MailingListView): """Class For Mass Removal""" @@ -305,6 +304,7 @@ email) return redirect('mass_removal', self.mailing_list.list_id) + def _get_choosable_domains(request): try: domains = Domain.objects.all() @@ -511,7 +511,8 @@ context_instance=RequestContext(request)) -@list_owner_required + +@list_moderator_required def list_held_messages(request, list_id): """Shows a list of held messages. """ @@ -524,7 +525,7 @@ context_instance=RequestContext(request)) -@list_owner_required +@list_moderator_required def accept_held_message(request, list_id, msg_id): """Accepts a held message. """ @@ -540,7 +541,7 @@ return redirect('list_held_messages', the_list.list_id) -@list_owner_required +@list_moderator_required def discard_held_message(request, list_id, msg_id): """Accepts a held message. """ @@ -556,7 +557,7 @@ return redirect('list_held_messages', the_list.list_id) -@list_owner_required +@list_moderator_required def defer_held_message(request, list_id, msg_id): """Accepts a held message. """ @@ -572,7 +573,7 @@ return redirect('list_held_messages', the_list.list_id) -@list_owner_required +@list_moderator_required def reject_held_message(request, list_id, msg_id): """Accepts a held message. """ diff --git a/src/postorius/views/views.py b/src/postorius/views/views.py deleted file mode 100644 index 1a9ca2d..0000000 --- a/src/postorius/views/views.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 1998-2015 by the Free Software Foundation, Inc. -# -# This file is part of Postorius. -# -# Postorius is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# Postorius is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# Postorius. If not, see . - - -import re -import sys -import json -import logging - - -from django.conf import settings -from django.contrib import messages -from django.contrib.auth import logout, authenticate, login -from django.contrib.auth.decorators import (login_required, - permission_required, - user_passes_test) -from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, - SetPasswordForm, PasswordChangeForm) -from django.contrib.auth.models import User -from django.core.urlresolvers import reverse -from django.http import HttpResponse, HttpResponseRedirect -from django.shortcuts import render_to_response, redirect -from django.template import Context, loader, RequestContext -from django.utils.decorators import method_decorator -from django.utils.translation import gettext as _ -from urllib2 import HTTPError - -from postorius import utils -from postorius.models import (Domain, List, Member, MailmanUser, - MailmanApiError, Mailman404Error) -from postorius.forms import * -from postorius.auth.decorators import * -from postorius.views.generic import MailingListView, MailmanUserView - - -logger = logging.getLogger(__name__) diff --git a/testing/test_settings.py b/testing/test_settings.py index 5cc5f93..155f454 100755 --- a/testing/test_settings.py +++ b/testing/test_settings.py @@ -149,13 +149,6 @@ return email.rsplit('@', 1)[0] BROWSERID_USERNAME_ALGO = username -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' -NOSE_ARGS = [ - '--with-coverage', - '--cover-package=postorius', - '--cover-erase', - '--cover-html', -] # Set VCR_RECORD_MODE to 'all' to re-record all API responses. # (Remember to use an empty mailman database!) diff --git a/tox.ini b/tox.ini index cf34015..bb2acfd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,37 +1,23 @@ [tox] -envlist = py27-django{1.5,1.6,1.7} +envlist = py27-django{16,17,18} [testenv] usedevelop = True +deps = + -rdev-requirements.txt + django16: Django>=1.6,<1.7 + django17: Django>=1.6,<1.8 + django18: Django==1.8 commands = django-admin.py test --settings=testing.test_settings {posargs:postorius} setenv = PYTHONPATH = {toxinidir} -[base] -deps = - -rdev-requirements.txt - -[testenv:py27-django1.5] -deps = - {[base]deps} - Django<1.6 - -[testenv:py27-django1.6] -deps = - {[base]deps} - Django<1.7 - -[testenv:py27-django1.7] -deps = - {[base]deps} - Django==1.7 - [testenv:record] basepython = python2.7 deps = - {[base]deps} - Django==1.7 + -rdev-requirements.txt + Django==1.8 setenv = PYTHONPATH = {toxinidir} POSTORIUS_VCR_RECORD_MODE = all