diff --git a/src/postorius/models.py b/src/postorius/models.py index bdc7ee8..9033e9e 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -264,16 +264,6 @@ self.created.replace(tzinfo=None) return age > expiration_delta - def _create_host_url(self, request): - # Create the host url - protocol = 'https' - if not request.is_secure(): - protocol = 'http' - server_name = request.META['SERVER_NAME'] - if server_name[-1] == '/': - server_name = server_name[:len(server_name) - 1] - return '{0}://{1}'.format(protocol, server_name) - def send_confirmation_link(self, request, template_context=None, template_path=None): """ @@ -291,12 +281,10 @@ 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 - host_url = self._create_host_url(request) # Get the url string from url conf. url = reverse('address_activation_link', kwargs={'activation_key': self.activation_key}) - activation_link = '{0}{1}'.format(host_url, url) + activation_link = request.build_absolute_uri(url) # Detect the right template path, either from the param, # the setting or the default if not template_path: @@ -307,7 +295,8 @@ # the activation_link and the host_url. if not template_context: template_context = Context( - {'activation_link': activation_link, 'host_url': host_url}) + {'activation_link': activation_link, + 'host_url': request.build_absolute_uri("/")}) email_subject = getattr( settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed') try: diff --git a/src/postorius/templates/postorius/user_address_activation_link.html b/src/postorius/templates/postorius/user_address_activation_link.html deleted file mode 100644 index b493058..0000000 --- a/src/postorius/templates/postorius/user_address_activation_link.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends postorius_base_template %} -{% load url from future %} -{% load i18n %} - -{% block main %} -{% endblock main %} diff --git a/src/postorius/tests/fixtures/vcr_cassettes/test_list_index.yaml b/src/postorius/tests/fixtures/vcr_cassettes/test_list_index.yaml index 36f5810..c24eccc 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/test_list_index.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/test_list_index.yaml @@ -5,51 +5,33 @@ accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/domains response: - body: {string: !!python/unicode 'Duplicate email host: example.com'} + body: {string: !!python/unicode ''} headers: - content-length: ['33'] - content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + content-length: ['0'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] + location: ['http://localhost:9001/3.0/domains/example.com'] server: [WSGIServer/0.2 CPython/3.4.2] - status: {code: 400, message: Bad Request} + status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/domains/example.com response: - body: {string: !!python/unicode '{"base_url": "http://example.com", "mail_host": - "example.com", "description": null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", - "url_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + body: {string: !!python/unicode '{"base_url": "http://example.com", "http_etag": + "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "self_link": "http://localhost:9001/3.0/domains/example.com", + "description": null, "mail_host": "example.com", "url_host": "example.com"}'} headers: content-length: ['233'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] - server: [WSGIServer/0.2 CPython/3.4.2] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/domains/example.com - response: - body: {string: !!python/unicode '{"base_url": "http://example.com", "mail_host": - "example.com", "description": null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", - "url_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} - headers: - content-length: ['233'] - content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -58,35 +40,56 @@ accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/lists response: body: {string: !!python/unicode ''} headers: content-length: ['0'] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] location: ['http://localhost:9001/3.0/lists/foo.example.com'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 201, message: Created} - request: + body: fqdn_listname=bar%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] + location: ['http://localhost:9001/3.0/lists/bar.example.com'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 201, message: Created} +- request: body: null headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists response: - body: {string: !!python/unicode '{"total_size": 1, "start": 0, "entries": [{"volume": - 1, "mail_host": "example.com", "list_name": "foo", "display_name": "Foo", - "list_id": "foo.example.com", "member_count": 0, "fqdn_listname": "foo@example.com", - "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "self_link": - "http://localhost:9001/3.0/lists/foo.example.com"}], "http_etag": "\"0eb6d0b88c89b5c491b7966eab97a79e221096ad\""}'} + body: {string: !!python/unicode '{"http_etag": "\"32ddcf601b73aeabdba5c18666c75d062c76eac8\"", + "entries": [{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/foo.example.com", + "list_name": "foo", "display_name": "Foo", "mail_host": "example.com", "http_etag": + "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "member_count": 0, "fqdn_listname": + "foo@example.com", "list_id": "foo.example.com"}, {"volume": 1, "self_link": + "http://localhost:9001/3.0/lists/bar.example.com", "list_name": "bar", "display_name": + "Bar", "mail_host": "example.com", "http_etag": "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", + "member_count": 0, "fqdn_listname": "bar@example.com", "list_id": "bar.example.com"}], + "total_size": 2, "start": 0}'} headers: - content-length: ['399'] + content-length: ['695'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -94,18 +97,18 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists/foo.example.com response: - body: {string: !!python/unicode '{"volume": 1, "mail_host": "example.com", "list_name": - "foo", "display_name": "Foo", "list_id": "foo.example.com", "member_count": - 0, "fqdn_listname": "foo@example.com", "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", - "self_link": "http://localhost:9001/3.0/lists/foo.example.com"}'} + body: {string: !!python/unicode '{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/foo.example.com", + "list_name": "foo", "display_name": "Foo", "mail_host": "example.com", "http_etag": + "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "member_count": 0, "fqdn_listname": + "foo@example.com", "list_id": "foo.example.com"}'} headers: content-length: ['294'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -113,34 +116,35 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists/foo@example.com/config response: - body: {string: !!python/unicode '{"scheme": "http", "list_name": "foo", "reply_to_address": - "", "next_digest_number": 1, "post_id": 1, "bounces_address": "foo-bounces@example.com", - "posting_pipeline": "default-posting-pipeline", "advertised": true, "no_reply_address": - "noreply@example.com", "autoresponse_owner_text": "", "last_post_at": null, - "allow_list_posts": true, "join_address": "foo-join@example.com", "acceptable_aliases": - [], "filter_content": false, "web_host": "example.com", "default_member_action": - "defer", "anonymous_list": false, "autorespond_postings": "none", "leave_address": - "foo-leave@example.com", "autoresponse_postings_text": "", "autoresponse_request_text": - "", "description": "", "admin_immed_notify": true, "collapse_alternatives": - true, "archive_policy": "public", "send_welcome_message": true, "created_at": - "2015-04-17T21:49:43.384633", "include_rfc2369_headers": true, "first_strip_reply_to": - false, "welcome_message_uri": "mailman:///welcome.txt", "administrivia": true, - "digest_last_sent_at": null, "admin_notify_mchanges": false, "digest_size_threshold": - 30.0, "default_nonmember_action": "hold", "subject_prefix": "[Foo] ", "request_address": - "foo-request@example.com", "autorespond_requests": "none", "volume": 1, "reply_goes_to_list": - "no_munging", "mail_host": "example.com", "autoresponse_grace_period": "90d", - "subscription_policy": "confirm", "display_name": "Foo", "convert_html_to_plaintext": - false, "owner_address": "foo-owner@example.com", "fqdn_listname": "foo@example.com", - "posting_address": "foo@example.com", "http_etag": "\"1ec2b61b7c20b4896f60090e43838cc722a2f4ab\"", - "autorespond_owner": "none"}'} + body: {string: !!python/unicode '{"bounces_address": "foo-bounces@example.com", + "join_address": "foo-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "foo", "leave_address": "foo-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"193295c218323732142ae2da3a2767f9ae432ffe\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Foo", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "foo@example.com", "fqdn_listname": + "foo@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "foo-owner@example.com", "created_at": "2015-08-06T05:11:52.442675", + "request_address": "foo-request@example.com", "subject_prefix": "[Foo] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} headers: content-length: ['1617'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -148,19 +152,74 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/bar.example.com + response: + body: {string: !!python/unicode '{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/bar.example.com", + "list_name": "bar", "display_name": "Bar", "mail_host": "example.com", "http_etag": + "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", "member_count": 0, "fqdn_listname": + "bar@example.com", "list_id": "bar.example.com"}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/bar@example.com/config + response: + body: {string: !!python/unicode '{"bounces_address": "bar-bounces@example.com", + "join_address": "bar-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "bar", "leave_address": "bar-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"9744725b871c949b1c90abc2a6b27ab4e7b918c2\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Bar", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "bar@example.com", "fqdn_listname": + "bar@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "bar-owner@example.com", "created_at": "2015-08-06T05:11:52.554133", + "request_address": "bar-request@example.com", "subject_prefix": "[Bar] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} + headers: + content-length: ['1617'] + content-type: [application/json; charset=utf-8] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/domains response: - body: {string: !!python/unicode '{"total_size": 1, "start": 0, "entries": [{"base_url": - "http://example.com", "mail_host": "example.com", "description": null, "http_etag": - "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "url_host": "example.com", - "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": - "\"c385b155f8da284bf78dbe075e20f58a30c893ab\""}'} + body: {string: !!python/unicode '{"http_etag": "\"c385b155f8da284bf78dbe075e20f58a30c893ab\"", + "entries": [{"base_url": "http://example.com", "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", + "self_link": "http://localhost:9001/3.0/domains/example.com", "description": + null, "mail_host": "example.com", "url_host": "example.com"}], "total_size": + 1, "start": 0}'} headers: content-length: ['338'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -168,17 +227,17 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/domains/example.com response: - body: {string: !!python/unicode '{"base_url": "http://example.com", "mail_host": - "example.com", "description": null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", - "url_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + body: {string: !!python/unicode '{"base_url": "http://example.com", "http_etag": + "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "self_link": "http://localhost:9001/3.0/domains/example.com", + "description": null, "mail_host": "example.com", "url_host": "example.com"}'} headers: content-length: ['233'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:52 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -186,34 +245,35 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo@example.com/config + uri: http://localhost:9001/3.0/lists/bar@example.com/config response: - body: {string: !!python/unicode '{"scheme": "http", "list_name": "foo", "reply_to_address": - "", "next_digest_number": 1, "post_id": 1, "bounces_address": "foo-bounces@example.com", - "posting_pipeline": "default-posting-pipeline", "advertised": true, "no_reply_address": - "noreply@example.com", "autoresponse_owner_text": "", "last_post_at": null, - "allow_list_posts": true, "join_address": "foo-join@example.com", "acceptable_aliases": - [], "filter_content": false, "web_host": "example.com", "default_member_action": - "defer", "anonymous_list": false, "autorespond_postings": "none", "leave_address": - "foo-leave@example.com", "autoresponse_postings_text": "", "autoresponse_request_text": - "", "description": "", "admin_immed_notify": true, "collapse_alternatives": - true, "archive_policy": "public", "send_welcome_message": true, "created_at": - "2015-04-17T21:49:43.384633", "include_rfc2369_headers": true, "first_strip_reply_to": - false, "welcome_message_uri": "mailman:///welcome.txt", "administrivia": true, - "digest_last_sent_at": null, "admin_notify_mchanges": false, "digest_size_threshold": - 30.0, "default_nonmember_action": "hold", "subject_prefix": "[Foo] ", "request_address": - "foo-request@example.com", "autorespond_requests": "none", "volume": 1, "reply_goes_to_list": - "no_munging", "mail_host": "example.com", "autoresponse_grace_period": "90d", - "subscription_policy": "confirm", "display_name": "Foo", "convert_html_to_plaintext": - false, "owner_address": "foo-owner@example.com", "fqdn_listname": "foo@example.com", - "posting_address": "foo@example.com", "http_etag": "\"1ec2b61b7c20b4896f60090e43838cc722a2f4ab\"", - "autorespond_owner": "none"}'} + body: {string: !!python/unicode '{"bounces_address": "bar-bounces@example.com", + "join_address": "bar-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "bar", "leave_address": "bar-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"9744725b871c949b1c90abc2a6b27ab4e7b918c2\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Bar", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "bar@example.com", "fqdn_listname": + "bar@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "bar-owner@example.com", "created_at": "2015-08-06T05:11:52.554133", + "request_address": "bar-request@example.com", "subject_prefix": "[Bar] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} headers: content-length: ['1617'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -221,34 +281,35 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo@example.com/config + uri: http://localhost:9001/3.0/lists/bar@example.com/config response: - body: {string: !!python/unicode '{"scheme": "http", "list_name": "foo", "reply_to_address": - "", "next_digest_number": 1, "post_id": 1, "bounces_address": "foo-bounces@example.com", - "posting_pipeline": "default-posting-pipeline", "advertised": true, "no_reply_address": - "noreply@example.com", "autoresponse_owner_text": "", "last_post_at": null, - "allow_list_posts": true, "join_address": "foo-join@example.com", "acceptable_aliases": - [], "filter_content": false, "web_host": "example.com", "default_member_action": - "defer", "anonymous_list": false, "autorespond_postings": "none", "leave_address": - "foo-leave@example.com", "autoresponse_postings_text": "", "autoresponse_request_text": - "", "description": "", "admin_immed_notify": true, "collapse_alternatives": - true, "archive_policy": "public", "send_welcome_message": true, "created_at": - "2015-04-17T21:49:43.384633", "include_rfc2369_headers": true, "first_strip_reply_to": - false, "welcome_message_uri": "mailman:///welcome.txt", "administrivia": true, - "digest_last_sent_at": null, "admin_notify_mchanges": false, "digest_size_threshold": - 30.0, "default_nonmember_action": "hold", "subject_prefix": "[Foo] ", "request_address": - "foo-request@example.com", "autorespond_requests": "none", "volume": 1, "reply_goes_to_list": - "no_munging", "mail_host": "example.com", "autoresponse_grace_period": "90d", - "subscription_policy": "confirm", "display_name": "Foo", "convert_html_to_plaintext": - false, "owner_address": "foo-owner@example.com", "fqdn_listname": "foo@example.com", - "posting_address": "foo@example.com", "http_etag": "\"1ec2b61b7c20b4896f60090e43838cc722a2f4ab\"", - "autorespond_owner": "none"}'} + body: {string: !!python/unicode '{"bounces_address": "bar-bounces@example.com", + "join_address": "bar-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "bar", "leave_address": "bar-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"9744725b871c949b1c90abc2a6b27ab4e7b918c2\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Bar", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "bar@example.com", "fqdn_listname": + "bar@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "bar-owner@example.com", "created_at": "2015-08-06T05:11:52.554133", + "request_address": "bar-request@example.com", "subject_prefix": "[Bar] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} headers: content-length: ['1617'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -256,19 +317,95 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"bounces_address": "foo-bounces@example.com", + "join_address": "foo-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "foo", "leave_address": "foo-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"193295c218323732142ae2da3a2767f9ae432ffe\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Foo", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "foo@example.com", "fqdn_listname": + "foo@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "foo-owner@example.com", "created_at": "2015-08-06T05:11:52.442675", + "request_address": "foo-request@example.com", "subject_prefix": "[Foo] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} + headers: + content-length: ['1617'] + content-type: [application/json; charset=utf-8] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"bounces_address": "foo-bounces@example.com", + "join_address": "foo-join@example.com", "next_digest_number": 1, "volume": + 1, "allow_list_posts": true, "scheme": "http", "reply_to_address": "", "digest_last_sent_at": + null, "no_reply_address": "noreply@example.com", "reply_goes_to_list": "no_munging", + "archive_policy": "public", "default_nonmember_action": "hold", "list_name": + "foo", "leave_address": "foo-leave@example.com", "subscription_policy": "confirm", + "posting_pipeline": "default-posting-pipeline", "first_strip_reply_to": false, + "collapse_alternatives": true, "filter_content": false, "admin_immed_notify": + true, "http_etag": "\"193295c218323732142ae2da3a2767f9ae432ffe\"", "anonymous_list": + false, "include_rfc2369_headers": true, "post_id": 1, "display_name": "Foo", + "autorespond_requests": "none", "welcome_message_uri": "mailman:///welcome.txt", + "convert_html_to_plaintext": false, "advertised": true, "digest_size_threshold": + 30.0, "web_host": "example.com", "posting_address": "foo@example.com", "fqdn_listname": + "foo@example.com", "last_post_at": null, "autoresponse_owner_text": "", "acceptable_aliases": + [], "owner_address": "foo-owner@example.com", "created_at": "2015-08-06T05:11:52.442675", + "request_address": "foo-request@example.com", "subject_prefix": "[Foo] ", + "mail_host": "example.com", "admin_notify_mchanges": false, "administrivia": + true, "default_member_action": "defer", "autoresponse_postings_text": "", + "autoresponse_request_text": "", "send_welcome_message": true, "description": + "", "autorespond_postings": "none", "autoresponse_grace_period": "90d", "autorespond_owner": + "none"}'} + headers: + content-length: ['1617'] + content-type: [application/json; charset=utf-8] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists response: - body: {string: !!python/unicode '{"total_size": 1, "start": 0, "entries": [{"volume": - 1, "mail_host": "example.com", "list_name": "foo", "display_name": "Foo", - "list_id": "foo.example.com", "member_count": 0, "fqdn_listname": "foo@example.com", - "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "self_link": - "http://localhost:9001/3.0/lists/foo.example.com"}], "http_etag": "\"0eb6d0b88c89b5c491b7966eab97a79e221096ad\""}'} + body: {string: !!python/unicode '{"http_etag": "\"32ddcf601b73aeabdba5c18666c75d062c76eac8\"", + "entries": [{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/foo.example.com", + "list_name": "foo", "display_name": "Foo", "mail_host": "example.com", "http_etag": + "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "member_count": 0, "fqdn_listname": + "foo@example.com", "list_id": "foo.example.com"}, {"volume": 1, "self_link": + "http://localhost:9001/3.0/lists/bar.example.com", "list_name": "bar", "display_name": + "Bar", "mail_host": "example.com", "http_etag": "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", + "member_count": 0, "fqdn_listname": "bar@example.com", "list_id": "bar.example.com"}], + "total_size": 2, "start": 0}'} headers: - content-length: ['399'] + content-length: ['695'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -276,18 +413,18 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists/foo.example.com response: - body: {string: !!python/unicode '{"volume": 1, "mail_host": "example.com", "list_name": - "foo", "display_name": "Foo", "list_id": "foo.example.com", "member_count": - 0, "fqdn_listname": "foo@example.com", "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", - "self_link": "http://localhost:9001/3.0/lists/foo.example.com"}'} + body: {string: !!python/unicode '{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/foo.example.com", + "list_name": "foo", "display_name": "Foo", "mail_host": "example.com", "http_etag": + "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "member_count": 0, "fqdn_listname": + "foo@example.com", "list_id": "foo.example.com"}'} headers: content-length: ['294'] content-type: [application/json; charset=utf-8] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 200, message: OK} - request: @@ -295,14 +432,48 @@ headers: accept-encoding: ['gzip, deflate'] !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] - !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0b2'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] method: !!python/unicode 'DELETE' uri: http://localhost:9001/3.0/lists/foo@example.com response: body: {string: !!python/unicode ''} headers: content-length: ['0'] - date: ['Fri, 17 Apr 2015 21:49:43 GMT'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/bar.example.com + response: + body: {string: !!python/unicode '{"volume": 1, "self_link": "http://localhost:9001/3.0/lists/bar.example.com", + "list_name": "bar", "display_name": "Bar", "mail_host": "example.com", "http_etag": + "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", "member_count": 0, "fqdn_listname": + "bar@example.com", "list_id": "bar.example.com"}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] + server: [WSGIServer/0.2 CPython/3.4.2] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'authorization': [!!python/unicode 'Basic cmVzdGFkbWluOnJlc3RwYXNz'] + !!python/unicode 'user-agent': [!!python/unicode 'GNU Mailman REST client v1.0.0'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/lists/bar@example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + date: ['Thu, 06 Aug 2015 05:11:53 GMT'] server: [WSGIServer/0.2 CPython/3.4.2] status: {code: 204, message: No Content} version: 1 diff --git a/src/postorius/tests/mailman_api_tests/test_list_index.py b/src/postorius/tests/mailman_api_tests/test_list_index.py index d7d71ac..a55347a 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_index.py +++ b/src/postorius/tests/mailman_api_tests/test_list_index.py @@ -51,6 +51,7 @@ except HTTPError: self.domain = get_client().get_domain('example.com') self.foo_list = self.domain.create_list('foo') + self.bar_list = self.domain.create_list('bar') @MM_VCR.use_cassette('test_list_index.yaml') def tearDown(self): @@ -58,10 +59,11 @@ mlist.delete() @MM_VCR.use_cassette('test_list_index.yaml') - def test_list_index_contains_one_list(self): - # The list index page should contain the + def test_list_index_contains_the_lists(self): + # The list index page should contain the lists response = self.client.get(reverse('list_index')) self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.context['lists']), 1) - self.assertEqual(response.context['lists'][0].fqdn_listname, - 'foo@example.com') + self.assertEqual(len(response.context['lists']), 2) + # The lists should be sorted by address + self.assertEqual([l.fqdn_listname for l in response.context['lists']], + ['bar@example.com', 'foo@example.com']) diff --git a/src/postorius/tests/test_address_activation.py b/src/postorius/tests/test_address_activation.py index b09ee44..8c46f77 100644 --- a/src/postorius/tests/test_address_activation.py +++ b/src/postorius/tests/test_address_activation.py @@ -122,6 +122,7 @@ def tearDown(self): self.profile.delete() self.user.delete() + mail.outbox = [] def test_profile_creation(self): # Profile is created and has all necessary properties. @@ -174,10 +175,14 @@ # set the activation key to a fixed string for testing self.profile.activation_key = \ '6323fba0097781fdb887cfc37a1122ee7c8bb0b0' + # Simulate a VirtualHost with a different name + self.request.META["HTTP_HOST"] = "another-virtualhost" + # Now send the email self.profile.send_confirmation_link(self.request) self.assertEqual(mail.outbox[0].to[0], u'les@example.org') self.assertEqual(mail.outbox[0].subject, u'Confirmation needed') - self.assertTrue(self.profile.activation_key in mail.outbox[0].body) + self.assertIn(self.profile.activation_key, mail.outbox[0].body) + self.assertIn("another-virtualhost", mail.outbox[0].body) class TestAddressActivationLinkSuccess(unittest.TestCase): diff --git a/src/postorius/utils.py b/src/postorius/utils.py index a48b448..7be80b1 100644 --- a/src/postorius/utils.py +++ b/src/postorius/utils.py @@ -26,14 +26,6 @@ logger = logging.getLogger(__name__) -def get_domain_name(request): - """Extracts a domain name from the request object. - """ - if "HTTP_HOST" in request.META.keys(): - return request.META["HTTP_HOST"].split(":")[0] - return None - - def get_client(): return Client('{0}/3.0'.format(settings.MAILMAN_API_URL), settings.MAILMAN_USER, diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 304d7cc..3b63d3a 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -482,11 +482,12 @@ if request.method == 'POST': return redirect("list_summary", list_id=request.POST["list"]) else: - return render_to_response(template, - {'error': error, - 'lists': lists, - 'domain_count': len(choosable_domains)}, - context_instance=RequestContext(request)) + return render_to_response( + template, { + 'error': error, + 'lists': sorted(lists, key=lambda l: l.fqdn_listname), + 'domain_count': len(choosable_domains), + }, context_instance=RequestContext(request)) @login_required diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index 876a432..2bc24c8 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -378,7 +378,12 @@ activation_key=activation_key) if not profile.is_expired: _add_address(request, profile.user.email, profile.email) - except profile.DoesNotExist: - pass - return render_to_response('postorius/user_address_activation_link.html', - {}, context_instance=RequestContext(request)) + profile.delete() + messages.success(request, _('The email address has been activated!')) + else: + profile.delete() + messages.error(request, _('The activation link has expired, please add the email again!')) + return redirect('address_activation') + except AddressConfirmationProfile.DoesNotExist: + messages.error(request, _('The activation link is invalid')) + return redirect('list_index')