diff --git a/src/postorius/models.py b/src/postorius/models.py index b3e388b..0269c71 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -129,24 +129,18 @@ def __init__(self): super(MailmanListManager, self).__init__('list', 'lists') - def all(self, only_public=False): + def all(self, advertised=False): try: - objects = getattr(get_mailman_client(), self.resource_name_plural) + method = getattr( + get_mailman_client(), 'get_' + self.resource_name_plural) + return method(advertised=advertised) except AttributeError: raise MailmanApiError except MailmanConnectionError as e: raise MailmanApiError(e) - if only_public: - public = [] - for obj in objects: - if obj.settings.get('advertised', False): - public.append(obj) - return public - else: - return objects - def by_mail_host(self, mail_host, only_public=False): - objects = self.all(only_public) + def by_mail_host(self, mail_host, advertised=False): + objects = self.all(advertised) host_objects = [] for obj in objects: if obj.mail_host == mail_host: diff --git a/src/postorius/templates/postorius/index.html b/src/postorius/templates/postorius/index.html index b0cae21..6c76350 100644 --- a/src/postorius/templates/postorius/index.html +++ b/src/postorius/templates/postorius/index.html @@ -36,7 +36,7 @@ {{ list.display_name }} - {% if not list.settings.advertised %} ({% trans 'unadvertised' %}*){% endif %} + {% if user.is_superuser and not list.settings.advertised %} ({% trans 'unadvertised' %}*){% endif %} {{ list.fqdn_listname }} {{ list.settings.description }} diff --git a/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_contains_the_lists.yaml b/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_contains_the_lists.yaml index 10cac47..538217d 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_contains_the_lists.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_contains_the_lists.yaml @@ -1,10 +1,10 @@ interactions: - request: - body: !!python/unicode mail_host=example.com + body: !!python/unicode 'mail_host=example.com' headers: accept-encoding: ['gzip, deflate'] - !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] - method: !!python/unicode POST + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/domains response: body: {string: !!python/unicode ''} @@ -17,7 +17,7 @@ body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET + method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/domains/example.com response: body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", @@ -27,11 +27,11 @@ content-type: [application/json; charset=UTF-8] status: {code: 200, message: OK} - request: - body: !!python/unicode fqdn_listname=foo%40example.com + body: !!python/unicode 'fqdn_listname=foo%40example.com' headers: accept-encoding: ['gzip, deflate'] - !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] - method: !!python/unicode POST + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/lists response: body: {string: !!python/unicode ''} @@ -41,11 +41,11 @@ location: ['http://localhost:9001/3.0/lists/foo.example.com'] status: {code: 201, message: Created} - request: - body: !!python/unicode fqdn_listname=bar%40example.com + body: !!python/unicode 'fqdn_listname=bar%40example.com' headers: accept-encoding: ['gzip, deflate'] - !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] - method: !!python/unicode POST + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/lists response: body: {string: !!python/unicode ''} @@ -58,8 +58,21 @@ body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET - uri: http://localhost:9001/3.0/lists + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists?advertised=true&count=0&page=1 + response: + body: {string: !!python/unicode '{"http_etag": "\"f14dfdb06627a6336a504885e036239a5b208434\"", + "start": 0, "total_size": 2}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists?advertised=true&count=10&page=1 response: body: {string: !!python/unicode '{"entries": [{"display_name": "Bar", "fqdn_listname": "bar@example.com", "http_etag": "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", @@ -79,7 +92,36 @@ body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": + "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", "mail_host": "example.com", + "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": + "\"2ec9679269ad1f741705a62db0162f5585ae5c3c\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['277'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", + "mail_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + headers: + content-length: ['172'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists/bar@example.com/config response: body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": @@ -95,25 +137,25 @@ true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", "digests_enabled": true, "display_name": "Bar", "filter_content": false, "first_strip_reply_to": false, "footer_uri": "", "fqdn_listname": "bar@example.com", "goodbye_message_uri": - "", "header_uri": "", "http_etag": "\"e24c842e50f43f703c1ab0c65345650808e9b85e\"", - "include_rfc2369_headers": true, "join_address": "bar-join@example.com", "last_post_at": - null, "leave_address": "bar-leave@example.com", "list_name": "bar", "mail_host": - "example.com", "moderator_password": null, "next_digest_number": 1, "no_reply_address": - "noreply@example.com", "owner_address": "bar-owner@example.com", "post_id": - 1, "posting_address": "bar@example.com", "posting_pipeline": "default-posting-pipeline", + "", "header_uri": "", "http_etag": "\"6a420444739ae906b975d89d07c185193d4afab6\"", + "include_rfc2369_headers": true, "info": "", "join_address": "bar-join@example.com", + "last_post_at": null, "leave_address": "bar-leave@example.com", "list_name": + "bar", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "bar-owner@example.com", + "post_id": 1, "posting_address": "bar@example.com", "posting_pipeline": "default-posting-pipeline", "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": "bar-request@example.com", "send_welcome_message": true, "subject_prefix": "[Bar] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": ""}'} headers: - content-length: ['1777'] + content-length: ['1789'] content-type: [application/json; charset=UTF-8] status: {code: 200, message: OK} - request: body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET + method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/lists/foo@example.com/config response: body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": @@ -129,25 +171,25 @@ true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", "digests_enabled": true, "display_name": "Foo", "filter_content": false, "first_strip_reply_to": false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": - "", "header_uri": "", "http_etag": "\"9c0047d131626776afd9a0187d91b2a4a7ea0b15\"", - "include_rfc2369_headers": true, "join_address": "foo-join@example.com", "last_post_at": - null, "leave_address": "foo-leave@example.com", "list_name": "foo", "mail_host": - "example.com", "moderator_password": null, "next_digest_number": 1, "no_reply_address": - "noreply@example.com", "owner_address": "foo-owner@example.com", "post_id": - 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "", "header_uri": "", "http_etag": "\"e752899e2a568ccaad1d891e72c137a4cbc82d5d\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": "foo-request@example.com", "send_welcome_message": true, "subject_prefix": "[Foo] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": ""}'} headers: - content-length: ['1777'] + content-length: ['1789'] content-type: [application/json; charset=UTF-8] status: {code: 200, message: OK} - request: body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET + method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/domains response: body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": @@ -163,36 +205,7 @@ body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET - uri: http://localhost:9001/3.0/domains/example.com - response: - body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", - "mail_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} - headers: - content-length: ['172'] - content-type: [application/json; charset=UTF-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET - uri: http://localhost:9001/3.0/domains - response: - body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": - "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", "mail_host": "example.com", - "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": - "\"2ec9679269ad1f741705a62db0162f5585ae5c3c\"", "start": 0, "total_size": - 1}'} - headers: - content-length: ['277'] - content-type: [application/json; charset=UTF-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode DELETE + method: !!python/unicode 'DELETE' uri: http://localhost:9001/3.0/domains/example.com response: body: {string: !!python/unicode ''} @@ -203,7 +216,7 @@ body: null headers: accept-encoding: ['gzip, deflate'] - method: !!python/unicode GET + method: !!python/unicode 'GET' uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", diff --git a/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_only_contains_advertised_lists.yaml b/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_only_contains_advertised_lists.yaml new file mode 100644 index 0000000..160531f --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/ListIndexPageTest.test_list_index_only_contains_advertised_lists.yaml @@ -0,0 +1,303 @@ +interactions: +- request: + body: !!python/unicode 'mail_host=example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/domains/example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", + "mail_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + headers: + content-length: ['172'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: !!python/unicode 'fqdn_listname=foo%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/lists/foo.example.com'] + status: {code: 201, message: Created} +- request: + body: !!python/unicode 'fqdn_listname=bar%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/lists/bar.example.com'] + status: {code: 201, message: Created} +- request: + body: !!python/unicode 'fqdn_listname=baz%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/lists/baz.example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/baz.example.com + response: + body: {string: !!python/unicode '{"display_name": "Baz", "fqdn_listname": "baz@example.com", + "http_etag": "\"4eec713d151af9d161047a5e3b814c05b6c958f0\"", "list_id": "baz.example.com", + "list_name": "baz", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/baz.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/baz@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "baz-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "Baz", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "baz@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"7331faacc9b01fc2247dac57065effc4a4deaf94\"", + "include_rfc2369_headers": true, "info": "", "join_address": "baz-join@example.com", + "last_post_at": null, "leave_address": "baz-leave@example.com", "list_name": + "baz", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "baz-owner@example.com", + "post_id": 1, "posting_address": "baz@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "baz-request@example.com", "send_welcome_message": true, "subject_prefix": + "[Baz] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1789'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: !!python/unicode 'advertised=False' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'PATCH' + uri: http://localhost:9001/3.0/lists/baz@example.com/config + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists?advertised=true&count=0&page=1 + response: + body: {string: !!python/unicode '{"http_etag": "\"f14dfdb06627a6336a504885e036239a5b208434\"", + "start": 0, "total_size": 2}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists?advertised=true&count=10&page=1 + response: + body: {string: !!python/unicode '{"entries": [{"display_name": "Bar", "fqdn_listname": + "bar@example.com", "http_etag": "\"ca42a69a3bab5619e147cc6cbbfca16115976764\"", + "list_id": "bar.example.com", "list_name": "bar", "mail_host": "example.com", + "member_count": 0, "self_link": "http://localhost:9001/3.0/lists/bar.example.com", + "volume": 1}, {"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}], "http_etag": + "\"70914f3f48a7570173531843e3ca4768008a9428\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['695'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": + "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", "mail_host": "example.com", + "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": + "\"2ec9679269ad1f741705a62db0162f5585ae5c3c\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['277'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", + "mail_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + headers: + content-length: ['172'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/bar@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "bar-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "Bar", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "bar@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"6a420444739ae906b975d89d07c185193d4afab6\"", + "include_rfc2369_headers": true, "info": "", "join_address": "bar-join@example.com", + "last_post_at": null, "leave_address": "bar-leave@example.com", "list_name": + "bar", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "bar-owner@example.com", + "post_id": 1, "posting_address": "bar@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "bar-request@example.com", "send_welcome_message": true, "subject_prefix": + "[Bar] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1789'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "foo-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "Foo", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"e752899e2a568ccaad1d891e72c137a4cbc82d5d\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "foo-request@example.com", "send_welcome_message": true, "subject_prefix": + "[Foo] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1789'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": + "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", "mail_host": "example.com", + "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": + "\"2ec9679269ad1f741705a62db0162f5585ae5c3c\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['277'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +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 96a3f3e..ca8eb3d 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_index.py +++ b/src/postorius/tests/mailman_api_tests/test_list_index.py @@ -39,3 +39,15 @@ # The lists should be sorted by address self.assertEqual([l.fqdn_listname for l in response.context['lists']], ['bar@example.com', 'foo@example.com']) + + def test_list_index_only_contains_advertised_lists(self): + # The list index page should contain only contain the advertised lists + baz_list = self.domain.create_list('baz') + baz_list.settings['advertised'] = False + baz_list.settings.save() + response = self.client.get(reverse('list_index')) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['lists']), 2) + self.assertNotIn( + 'baz.example.com', + [ml.list_id for ml in response.context['lists']]) diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index faf79e4..fc18a50 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -550,25 +550,21 @@ """ if request.method == 'POST': return redirect("list_summary", list_id=request.POST["list"]) - lists = [] - error = None - only_public = True - if request.user.is_superuser: - only_public = False + + def _get_list_page(count, page): + client = get_mailman_client() + advertised = not request.user.is_superuser + return client.get_list_page( + advertised=advertised, count=count, page=page) try: - # FIXME: this is not paginated, all lists will - # always be retrieved. - lists = sorted(List.objects.all(only_public=only_public), - key=lambda l: l.fqdn_listname) - logger.debug(lists) + lists = paginate( + _get_list_page, request.GET.get('page'), request.GET.get('count'), + paginator_class=MailmanPaginator) except MailmanApiError: return utils.render_api_error(request) choosable_domains = _get_choosable_domains(request) return render(request, template, - {'error': error, - 'lists': paginate( - lists, request.GET.get('page'), - request.GET.get('count', 10)), + {'lists': lists, 'domain_count': len(choosable_domains)})