diff --git a/src/postorius/auth/decorators.py b/src/postorius/auth/decorators.py
index 7fc369b..e6fa531 100644
--- a/src/postorius/auth/decorators.py
+++ b/src/postorius/auth/decorators.py
@@ -47,7 +47,7 @@
def list_owner_required(fn):
"""Check if the logged in user is the list owner of the given list.
- Assumes that the request object is the first arg and that fqdn_listname
+ Assumes that the request object is the first arg and that list_id
is present in kwargs.
"""
def wrapper(*args, **kwargs):
diff --git a/src/postorius/middleware.py b/src/postorius/middleware.py
new file mode 100644
index 0000000..be44670
--- /dev/null
+++ b/src/postorius/middleware.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 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 .
+
+
+from postorius import utils
+from postorius.models import MailmanApiError
+
+
+class PostoriusMiddleware(object):
+
+ def process_request(self, request):
+ utils.set_other_emails(request.user)
+
+ def process_exception(self, request, exception):
+ if isinstance(exception, MailmanApiError):
+ return utils.render_api_error(request)
diff --git a/src/postorius/templates/postorius/lists/memberoptions.html b/src/postorius/templates/postorius/lists/memberoptions.html
index 542581e..eff7aa1 100644
--- a/src/postorius/templates/postorius/lists/memberoptions.html
+++ b/src/postorius/templates/postorius/lists/memberoptions.html
@@ -16,7 +16,7 @@
{% trans 'You are not the owner for this list' %}
{% else %}
{% endif %}
diff --git a/src/postorius/urls.py b/src/postorius/urls.py
index bb63702..68c8f17 100644
--- a/src/postorius/urls.py
+++ b/src/postorius/urls.py
@@ -27,8 +27,8 @@
url(r'^csv_view/$',
'csv_view', name='csv_view'),
url(r'^members/options/(?P[^/]+)/$',
- ListMemberOptionsView.as_view(
- ), name='list_member_options'),
+ list_member_options,
+ name='list_member_options'),
url(r'^members/(?P\w+)/$',
'list_members_view', name='list_members'),
url(r'^$',
diff --git a/src/postorius/utils.py b/src/postorius/utils.py
index 0e3bb30..63a2564 100644
--- a/src/postorius/utils.py
+++ b/src/postorius/utils.py
@@ -99,6 +99,8 @@
def set_other_emails(user):
from postorius.models import MailmanUser, MailmanApiError, Mailman404Error
+ if hasattr(user, 'other_emails'):
+ return
user.other_emails = []
if not user.is_authenticated():
return
diff --git a/src/postorius/views/generic.py b/src/postorius/views/generic.py
index 6432bc5..e12e846 100644
--- a/src/postorius/views/generic.py
+++ b/src/postorius/views/generic.py
@@ -39,7 +39,7 @@
"""A generic view for everything based on a mailman.client
list object.
- Sets self.mailing_list to list object if fqdn_listname in **kwargs.
+ Sets self.mailing_list to list object if list_id is in **kwargs.
"""
def _get_list(self, list_id, page):
diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py
index 0542c66..873e81f 100644
--- a/src/postorius/views/list.py
+++ b/src/postorius/views/list.py
@@ -97,62 +97,42 @@
return render(request, 'postorius/lists/members.html', context)
-class ListMemberOptionsView(MailingListView):
- '''View the preferences for a single member of a mailing list'''
-
- @method_decorator(list_owner_required)
- def post(self, request, list_id, email):
- try:
- client = utils.get_client()
- mm_member = client.get_member(list_id, email)
- mm_list = List.objects.get_or_404(fqdn_listname=list_id)
- preferences_form = UserPreferences(request.POST)
- if preferences_form.is_valid():
- preferences = mm_member.preferences
- for key in preferences_form.fields.keys():
- preferences[key] = preferences_form.cleaned_data[key]
- preferences.save()
- messages.success(request, _("The member's preferences have been updated."))
+@login_required
+@list_owner_required
+def list_member_options(request, list_id, email):
+ template_name = 'postorius/lists/memberoptions.html'
+ client = utils.get_client()
+ mm_list = List.objects.get_or_404(fqdn_listname=list_id)
+ try:
+ mm_member = client.get_member(list_id, email)
+ member_prefs = mm_member.preferences
+ except Mailman404Error:
+ return render(request, template_name, {'nolists': 'true'})
+ if request.method == 'POST':
+ preferences_form = UserPreferences(
+ request.POST, initial=member_prefs)
+ if preferences_form.is_valid():
+ if not preferences_form.has_changed():
+ messages.info(request,
+ _("No change to the member's preferences."))
+ return redirect('list_member_options', list_id, email)
+ for key in preferences_form.fields.keys():
+ member_prefs[key] = preferences_form.cleaned_data[key]
+ try:
+ member_prefs.save()
+ except HTTPError as e:
+ messages.error(request, e.msg)
else:
- messages.error(request, _('Something went wrong.'))
-
- # this is a bit silly, since we already have the preferences,
- # but I want to be sure we don't show stale data.
- settingsform = UserPreferences(initial=mm_member.preferences)
- except MailmanApiError:
- return utils.render_api_error(request)
- except HTTPError as e:
- messages.error(request, e.msg)
- return render_to_response(
- 'postorius/lists/memberoptions.html',
- {'mm_member': mm_member,
- 'list': mm_list,
- 'settingsform': settingsform,
- },
- context_instance=RequestContext(request))
-
- @method_decorator(login_required)
- @method_decorator(list_owner_required)
- def get(self, request, list_id, email):
- try:
- client = utils.get_client()
- mm_member = client.get_member(list_id, email)
- mm_list = List.objects.get_or_404(fqdn_listname=list_id)
- settingsform = UserPreferences(initial=mm_member.preferences)
- except MailmanApiError:
- return utils.render_api_error(request)
- except Mailman404Error:
- return render_to_response(
- 'postorius/lists/memberoptions.html',
- {'nolists': 'true'},
- context_instance=RequestContext(request))
- return render_to_response(
- 'postorius/lists/memberoptions.html',
- {'mm_member': mm_member,
- 'list': mm_list,
- 'settingsform': settingsform,
- },
- context_instance=RequestContext(request))
+ messages.success(request,
+ _("The member's preferences have been updated."))
+ return redirect('list_member_options', list_id, email)
+ else:
+ preferences_form = UserPreferences(initial=member_prefs)
+ return render(request, template_name, {
+ 'mm_member': mm_member,
+ 'list': mm_list,
+ 'preferences_form': preferences_form,
+ })
class ListSummaryView(MailingListView):