diff --git a/src/postorius/templates/postorius/lists/summary.html b/src/postorius/templates/postorius/lists/summary.html index 23343dc..a95c3d2 100644 --- a/src/postorius/templates/postorius/lists/summary.html +++ b/src/postorius/templates/postorius/lists/summary.html @@ -9,9 +9,7 @@ {% block main %} - {% if user.is_superuser or user.is_list_owner or user.is_list_moderator %} - {% list_nav 'list_summary' 'Summary' %} - {% endif %} + {% list_nav 'list_summary' 'Summary' %}

{{ list.settings.description }}

{% trans 'To contact the list owners, use the following email address:' %} {{ list.settings.owner_address }}

@@ -28,16 +26,19 @@
{# Subscription #} -

{% trans 'Subscription' %}

{% if user.is_authenticated %} {% if userSubscribed %} +

{% trans 'Subscription' %}

{% trans 'You are subscribed to this list with the following address:' %} {{ subscribed_address }}

-
- {% render_form_horizontal change_subscription_form 2 8 'Change subscription' %} -
-

+ {% url 'user_list_options' list.list_id as user_list_options_url %} + {% blocktrans %} +

+ You can manage your subscription here +

+ {% endblocktrans %} +

{% trans 'Unsubscribe' %} {{ subscribed_address }} @@ -49,7 +50,7 @@ {% endif %} {% else %} -

{% trans 'You have to log in to subscribe to this list.' %}

+

{% trans 'If you want to subscribe to this list, you have to log in first.' %}

{% trans 'Log In' %}

{% endif %} diff --git a/src/postorius/templates/postorius/user/list_options.html b/src/postorius/templates/postorius/user/list_options.html new file mode 100644 index 0000000..a766b8a --- /dev/null +++ b/src/postorius/templates/postorius/user/list_options.html @@ -0,0 +1,24 @@ +{% extends postorius_base_template %} +{% load i18n %} +{% load nav_helpers %} +{% load bootstrap_tags %} + +{% block subtitle %} +{% trans 'Member options' %} | {{ list.list_fqdn }} +{% endblock %} + +{% block main %} +

{% trans 'Subscription options for' %} {{ list.fqdn_listname }}

+
+

+{% trans 'Use this form to change the email used for this subscription' %}: +

+
+ {% render_form_horizontal change_subscription_form 3 8 'Change email used for subscription' %} +
+
+
+ {% render_form_horizontal form 3 8 'Save changes' %} + +
+{% endblock main %} diff --git a/src/postorius/tests/mailman_api_tests/test_list_summary.py b/src/postorius/tests/mailman_api_tests/test_list_summary.py index 0472659..163686c 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_summary.py +++ b/src/postorius/tests/mailman_api_tests/test_list_summary.py @@ -94,7 +94,7 @@ self.assertTrue('anotheremail@example.com' in response.content) @MM_VCR.use_cassette('test_change_subscription.yaml') - def test_change_subscription(self): + def test_unsubscribe_button_is_available(self): mlist = self.mmclient.get_list('foo@example.com') mlist.subscribe('test@example.com', pre_verified=True, @@ -103,7 +103,6 @@ response = self.client.get(reverse('list_summary', args=('foo@example.com', ))) self.assertEqual(response.status_code, 200) - self.assertTrue('Change subscription' in response.content) self.assertTrue('Unsubscribe' in response.content) @MM_VCR.use_cassette('test_list_summary_owner.yaml') diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 68c8f17..fe32772 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -102,6 +102,8 @@ url(r'^accounts/mailmansettings/$', UserMailmanSettingsView.as_view(), name='user_mailmansettings'), + url(r'^accounts/list-options/(?P[^/]+)/$', user_list_options, + name='user_list_options'), # /domains/ url(r'^domains/$', 'domain_index', name='domain_index'), url(r'^domains/new/$', 'domain_new', name='domain_new'), diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 3d90b69..d210b85 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -180,12 +180,9 @@ data['userSubscribed'] = True data['subscribed_address'] = address break # no need to test more addresses - data['change_subscription_form'] = ChangeSubscriptionForm( - user_emails, initial={'email': data['subscribed_address']}) data['subscribe_form'] = ListSubscribe(user_emails) else: user_emails = None - data['change_subscription_form'] = None return render_to_response( 'postorius/lists/summary.html', data, context_instance=RequestContext(request)) diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index 3ea293f..8eefd63 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -25,6 +25,8 @@ from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ from django.views.generic import TemplateView +from django.http import Http404 + try: from urllib2 import HTTPError except ImportError: @@ -125,6 +127,36 @@ context_instance=RequestContext(request)) +@login_required +def user_list_options(request, list_id): + utils.set_other_emails(request.user) + mlist = List.objects.get_or_404(fqdn_listname=list_id) + mm_user = MailmanUser.objects.get(address=request.user.email) + subscription = None + for s in mm_user.subscriptions: + if s.role == 'member' and s.list_id == list_id: + subscription = s + break + if not subscription: + raise Http404(_('Subscription does not exist')) + preferences = subscription.preferences + if request.method == 'POST': + form = UserPreferences(request.POST) + if form.is_valid(): + for key in form.cleaned_data.keys(): + preferences[key] = form.cleaned_data[key] + preferences.save() + messages.success(request, _('Your preferences have been updated.')) + else: + messages.error(request, _('Something went wrong.')) + else: + form = UserPreferences(initial=subscription.preferences) + user_emails = [request.user.email] + request.user.other_emails + subscription_form = ChangeSubscriptionForm(user_emails, initial={'email': subscription.email}) + return render_to_response('postorius/user/list_options.html', + {'form': form, 'list': mlist, 'change_subscription_form': subscription_form}, context_instance=RequestContext(request)) + + class UserSubscriptionPreferencesView(MailmanUserView): """The logged-in user's subscription-based Mailman Preferences."""