diff --git a/opentech/apply/activity/models.py b/opentech/apply/activity/models.py index a052f0422c71cdfba204327840901ef142ee37f8..014c646d5dae552f5aae1328e28cc1e7bf6034dc 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 c0f42b5b3dccefed9c527a468dc6b68a37ce031b..033cd5fe772e64b367f493af150d4239e1a40393 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)