diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-12-04 10:51:20 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-12-04 10:51:20 +0100 |
commit | b3ffd97a0b433647a53ecd7a5cc63f7bdc1e1ee2 (patch) | |
tree | b2461e717a2ea893cbf59a20a5ef5b04ae1b2f90 | |
parent | 0bd5582a75d5a610885241ba52186033e2272424 (diff) | |
download | hyperkitty-b3ffd97a0b433647a53ecd7a5cc63f7bdc1e1ee2.tar.gz hyperkitty-b3ffd97a0b433647a53ecd7a5cc63f7bdc1e1ee2.tar.xz hyperkitty-b3ffd97a0b433647a53ecd7a5cc63f7bdc1e1ee2.zip |
Add a config option to only display lists from the same virtual host
-rw-r--r-- | hyperkitty/lib/view_helpers.py | 7 | ||||
-rw-r--r-- | hyperkitty/templates/index.html | 2 | ||||
-rw-r--r-- | hyperkitty/tests/test_lib.py | 44 | ||||
-rw-r--r-- | hyperkitty/views/index.py | 6 |
4 files changed, 55 insertions, 4 deletions
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 %} </h1> +{% if all_lists %} <p class="hide-switches"> <label><input type="checkbox" value="inactive" /> Hide inactive</label> <label><input type="checkbox" value="private" /> Hide private</label> </p> -{% if all_lists %} <table class="lists table"> <thead> <tr> 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: |