Abhilash Raj has proposed merging lp:~raj-abhilash1/postorius/sprints into
lp:postorius.
Requested reviews:
Mailman Coders (mailman-coders)
For more details, see:
https://code.launchpad.net/~raj-abhilash1/postorius/sprints/+merge/256055
User can subscribe using any of its addresses now.
--
Your team Mailman Coders is requested to review the proposed merge of
lp:~raj-abhilash1/postorius/sprints into lp:postorius.
=== modified file 'src/postorius/forms.py'
--- src/postorius/forms.py 2015-02-09 14:35:44 +0000
+++ src/postorius/forms.py 2015-04-13 22:57:37 +0000
@@ -168,17 +168,23 @@
class ListSubscribe(FieldsetForm):
-
"""Form fields to join an existing list.
"""
- email = forms.EmailField(
+
+ email = forms.ChoiceField(
label=_('Your email address'),
- widget=forms.HiddenInput(),
+ validators=[validate_email],
+ widget=forms.Select(),
error_messages={'required': _('Please enter an email address.'),
'invalid': _('Please enter a valid email address.')})
display_name = forms.CharField(label=_('Your name (optional)'),
required=False)
+ def __init__(self, user_emails, *args, **kwargs):
+ super(ListSubscribe, self).__init__(*args, **kwargs)
+ self.fields['email'].choices = ((address, address)
+ for address in user_emails)
+
class ListUnsubscribe(FieldsetForm):
=== modified file 'src/postorius/templates/postorius/domain_index.html'
--- src/postorius/templates/postorius/domain_index.html 2014-10-15 20:59:52 +0000
+++ src/postorius/templates/postorius/domain_index.html 2015-04-13 22:57:37 +0000
@@ -23,7 +23,7 @@
<tr>
<td>{{ domain.mail_host }}</td>
<td>{{ domain.base_url }}</td>
- <td>{{ domain.contact_address }}</td>
+ <td> </td>
<td>{{ domain.description }}</td>
<td><a href="{% url 'domain_delete' domain.mail_host %}" class="btn btn-mini btn-danger">{% trans 'Delete' %}</a></td>
</tr>
=== modified file 'src/postorius/templates/postorius/lists/summary.html'
--- src/postorius/templates/postorius/lists/summary.html 2015-03-22 14:57:17 +0000
+++ src/postorius/templates/postorius/lists/summary.html 2015-04-13 22:57:37 +0000
@@ -14,10 +14,13 @@
<h2>{% trans 'Description' %}</h2>
<p>{{list.settings.description }}</p>
-
+
{% if user.is_authenticated %}
{% if userSubscribed %}
- <a href="{% url 'list_unsubscribe' list.list_id user.email %}" class="btn btn-danger">{% trans "Unsubscribe" %}</a>
+ {% trans "You are subscribed to this list with your address:" %}
+ <em>{{ subscribed_address }}</em>
+ <br/>
+ <a href="{% url 'list_unsubscribe' list.list_id user.email %}" class="btn btn-danger">{% trans "Unsubscribe" %} {{ subscribed_address }}</a>
{% else %}
<h2>{% trans 'Subscribe to this list' %}</h2>
<form action="{% url 'list_subscribe' list.list_id %}" method="post" class="list_subscribe"> {% csrf_token %}
=== modified file 'src/postorius/templates/postorius/user_mailmansettings.html'
--- src/postorius/templates/postorius/user_mailmansettings.html 2015-01-09 15:40:51 +0000
+++ src/postorius/templates/postorius/user_mailmansettings.html 2015-04-13 22:57:37 +0000
@@ -28,7 +28,7 @@
<p> {% trans "Mail Delivery" %}: </p>
</p>
[<span class="more_info"><a href="#" target="_blank">{% trans 'More info' %}</a><span>{{ settingsform.delivery_status.help_text }}
- </span></span>] </p>
+ </span></span>] </p>
</td>
<td> {{settingsform.delivery_status }} </td>
</tr>
=== modified file 'src/postorius/tests/test_forms.py'
--- src/postorius/tests/test_forms.py 2015-02-09 14:35:44 +0000
+++ src/postorius/tests/test_forms.py 2015-04-13 22:57:37 +0000
@@ -16,7 +16,8 @@
# Postorius. If not, see <http://www.gnu.org/licenses/>.
from django.utils import unittest
-from postorius.forms import UserPreferences, DomainNew
+from postorius.forms import (
+ UserPreferences, DomainNew, ListSubscribe)
class UserPreferencesTest(unittest.TestCase):
@@ -49,3 +50,29 @@
'contact_address': '[email protected]',
})
self.assertFalse(form.is_valid())
+
+class ListSubscribeTest(unittest.TestCase):
+ def test_subscribe_works(self):
+ user_emails = ['[email protected]']
+ form = ListSubscribe(user_emails, {
+ 'email' : '[email protected]',
+ 'display_name' : 'Someone',
+ })
+ self.assertTrue(form.is_valid())
+
+
+ def test_subscribe_fails(self):
+ user_emails = ['[email protected]']
+ form = ListSubscribe(user_emails, {
+ 'email' : 'notaemail',
+ 'display_name' : 'Someone',
+ })
+ self.assertFalse(form.is_valid())
+
+ def test_subscribe_validates_email(self):
+ user_emails = ['something']
+ form = ListSubscribe(user_emails, {
+ 'email' : 'something',
+ 'display_name' : 'Someone',
+ })
+ self.assertFalse(form.is_valid())
=== modified file 'src/postorius/views/list.py'
--- src/postorius/views/list.py 2015-04-13 20:25:18 +0000
+++ src/postorius/views/list.py 2015-04-13 22:57:37 +0000
@@ -174,19 +174,32 @@
"""
def get(self, request, list_id):
- user_email = getattr(request.user, 'email', None)
+ try:
+ mm_user = MailmanUser.objects.get(address=request.user.email)
+ user_emails = [str(address) for address in getattr(mm_user, 'addresses')]
+ # TODO:maxking - add the clause below in above
+ # statement after the subscription policy is sorted
+ # out
+ # if address.verified_on is not None]
+ except Mailman404Error:
+ # The user does not have a mailman user associated with it.
+ user_emails = [request.user.email]
userSubscribed = False
- try:
- userMember = self.mailing_list.get_member(user_email)
- except ValueError:
- pass
- else:
- userSubscribed = True
+ subscribed_address = None
+ for address in user_emails:
+ try:
+ userMember = self.mailing_list.get_member(address)
+ except ValueError:
+ pass
+ else:
+ userSubscribed = True
+ subscribed_address = address
return render_to_response(
'postorius/lists/summary.html',
{'list': self.mailing_list,
- 'subscribe_form': ListSubscribe(initial={'email': user_email}),
- 'userSubscribed': userSubscribed},
+ 'subscribe_form': ListSubscribe(user_emails),
+ 'userSubscribed': userSubscribed,
+ 'subscribed_address': subscribed_address},
context_instance=RequestContext(request))
@@ -197,13 +210,15 @@
@method_decorator(login_required)
def post(self, request, list_id):
try:
- form = ListSubscribe(request.POST)
+ mm_user = MailmanUser.objects.get(address=request.user.email)
+ user_addresses = [str(address) for address in mm_user.addresses]
+ form = ListSubscribe(user_addresses, request.POST)
if form.is_valid():
email = request.POST.get('email')
self.mailing_list.subscribe(email)
messages.success(
- request, 'You are subscribed to %s.' %
- self.mailing_list.fqdn_listname)
+ request, 'You are subscribed to %s using your %s address' %
+ (self.mailing_list.fqdn_listname, email))
else:
messages.error(request, 'Something went wrong. '
'Please try again.')
@@ -473,7 +488,7 @@
context_instance=RequestContext(request))
-
+
@list_moderator_required
def list_held_messages(request, list_id):
"""Shows a list of held messages.
_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders