diff --git a/web/pglister/lists/templates/home.html b/web/pglister/lists/templates/home.html index d122a4b..4b1723d 100644 --- a/web/pglister/lists/templates/home.html +++ b/web/pglister/lists/templates/home.html @@ -4,6 +4,9 @@

Manage subscriptions Unsubscribe + {%if is_moderator%} + Manage lists + {%endif%}

diff --git a/web/pglister/lists/views.py b/web/pglister/lists/views.py index b8981d7..e2ab446 100644 --- a/web/pglister/lists/views.py +++ b/web/pglister/lists/views.py @@ -29,6 +29,23 @@ from lib.baselib.misc import generate_random_token class Home(TemplateView): template_name = 'home.html' + def get_context_data(self, **kwargs): + # get the context from ContextMixin + # it defines the $view variable + context = super().get_context_data(**kwargs) + + is_moderator = False + + # for a viewer which is not not logged in, self.request.user + # is "AnonymousUser" and "is_authenticated" is false + if self.request.user.is_authenticated: + is_moderator = exec_to_scalar("SELECT EXISTS (SELECT 1 FROM lists_list_moderators WHERE subscriber_id=%(userid)s)", { + 'userid': self.request.user.id, + }) + context['is_moderator'] = is_moderator + + return context + class Manage(LoginRequired, View): template_name = 'manage.html'