From ae898e10f717f672755adbe336fdd7d553ac0262 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 7 Mar 2018 16:34:06 +0000 Subject: [PATCH] Filter the displayed comments --- opentech/apply/activity/models.py | 7 ++++++- opentech/apply/activity/views.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/opentech/apply/activity/models.py b/opentech/apply/activity/models.py index a052f0422..014c646d5 100644 --- a/opentech/apply/activity/models.py +++ b/opentech/apply/activity/models.py @@ -27,6 +27,11 @@ class ActivityBaseManager(models.Manager): return super().get_queryset().filter(type=self.type) +class CommentQueryset(models.QuerySet): + def visibile_to(self, user): + return self.filter(visibility__in=self.model.visibility_for(user)) + + class CommentManger(ActivityBaseManager): type = COMMENT @@ -44,7 +49,7 @@ class Activity(models.Model): visibility = models.CharField(choices=VISIBILITY.items(), default=PUBLIC, max_length=10) objects = models.Manager() - comments = CommentManger() + comments = CommentManger.from_queryset(CommentQueryset)() actions = ActionManager() class Meta: diff --git a/opentech/apply/activity/views.py b/opentech/apply/activity/views.py index c0f42b5b3..033cd5fe7 100644 --- a/opentech/apply/activity/views.py +++ b/opentech/apply/activity/views.py @@ -23,7 +23,7 @@ class ActivityContextMixin: def get_context_data(self, **kwargs): extra = { 'actions': Activity.actions.filter(submission=self.object), - 'comments': Activity.comments.filter(submission=self.object), + 'comments': Activity.comments.filter(submission=self.object).visibile_to(self.request.user), } return super().get_context_data(**extra, **kwargs) -- GitLab