From b3ffd97a0b433647a53ecd7a5cc63f7bdc1e1ee2 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Wed, 4 Dec 2013 10:51:20 +0100 Subject: Add a config option to only display lists from the same virtual host --- hyperkitty/lib/view_helpers.py | 7 +++++++ hyperkitty/templates/index.html | 2 +- hyperkitty/tests/test_lib.py | 44 ++++++++++++++++++++++++++++++++++++++++- hyperkitty/views/index.py | 6 ++++-- 4 files changed, 55 insertions(+), 4 deletions(-) (limited to 'hyperkitty') diff --git a/hyperkitty/lib/view_helpers.py b/hyperkitty/lib/view_helpers.py index fb8e897..283c1e3 100644 --- a/hyperkitty/lib/view_helpers.py +++ b/hyperkitty/lib/view_helpers.py @@ -156,3 +156,10 @@ def get_recent_list_activity(store, mlist): # return the proper format for the javascript chart function return [ {"date": d, "count": emails_per_date[d]} for d in sorted(emails_per_date) ] + + +def show_mlist(mlist, request): + def get_domain(host): + return ".".join(host.split(".")[-2:]) + return (get_domain(mlist.name.partition("@")[2]) + == get_domain(request.get_host())) diff --git a/hyperkitty/templates/index.html b/hyperkitty/templates/index.html index 8d2fcf9..921b31e 100644 --- a/hyperkitty/templates/index.html +++ b/hyperkitty/templates/index.html @@ -59,12 +59,12 @@ {% endif %} +{% if all_lists %}

-{% if all_lists %} diff --git a/hyperkitty/tests/test_lib.py b/hyperkitty/tests/test_lib.py index 289a590..1da1c90 100644 --- a/hyperkitty/tests/test_lib.py +++ b/hyperkitty/tests/test_lib.py @@ -23,9 +23,10 @@ import datetime from django.contrib.auth.models import User, AnonymousUser from django.core.cache import cache +from django.http import HttpRequest from hyperkitty.models import Rating -from hyperkitty.lib.view_helpers import get_display_dates +from hyperkitty.lib.view_helpers import get_display_dates, show_mlist from hyperkitty.lib.voting import set_thread_votes from hyperkitty.lib.paginator import paginate @@ -172,3 +173,44 @@ class VotingTestCase(TestCase): set_thread_votes(thread_2) self.assertEqual(thread_2.likes, 1) self.assertEqual(thread_2.dislikes, 0) + + +# +# view_helpers.show_mlist() +# + +class FakeKSList(object): + def __init__(self, name): + self.name = name + +class ShowMlistTestCase(TestCase): + + def _do_test(self, listdomain, vhost, expected): + mlist = FakeKSList("test@%s" % listdomain) + req = HttpRequest() + req.META["HTTP_HOST"] = vhost + self.assertEqual(show_mlist(mlist, req), expected) + + def test_same_domain(self): + self._do_test("example.com", "example.com", True) + self._do_test("lists.example.com", "lists.example.com", True) + + def test_web_subdomain(self): + self._do_test("example.com", "www.example.com", True) + self._do_test("example.com", "lists.example.com", True) + + def test_mail_subdomain(self): + self._do_test("lists.example.com", "example.com", True) + + def test_different_subdomains(self): + self._do_test("lists.example.com", "archives.example.com", True) + + def test_different_domains(self): + self._do_test("example.com", "another-example.com", False) + self._do_test("lists.example.com", "archives.another-example.com", False) + + def test_single_component_domain(self): + self._do_test("intranet", "intranet", True) + + def test_different_single_component_domain(self): + self._do_test("intranet", "extranet", False) diff --git a/hyperkitty/views/index.py b/hyperkitty/views/index.py index cb3c6b1..55ffa30 100644 --- a/hyperkitty/views/index.py +++ b/hyperkitty/views/index.py @@ -34,13 +34,15 @@ from mailmanclient import Client, MailmanConnectionError from mailman.interfaces.archiver import ArchivePolicy from hyperkitty.lib import get_store +from hyperkitty.lib.view_helpers import show_mlist from hyperkitty.lib.mailman import is_mlist_authorized def index(request): - store = get_store(request) - lists = store.get_lists() now = datetime.datetime.now() + store = get_store(request) + lists = [ l for l in store.get_lists() + if not settings.FILTER_VHOST or show_mlist(l, request) ] initials = set() for mlist in lists: if mlist.archive_policy != ArchivePolicy.private: -- cgit