From 01203b25310617492e5fa613415a63a3473dbe00 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 2 Jul 2015 02:08:19 -0400 Subject: [PATCH] Re-add smart tag document counter that takes into account user permission for the document list. --- mayan/apps/tags/views.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mayan/apps/tags/views.py b/mayan/apps/tags/views.py index f87922fe96..1606edf859 100644 --- a/mayan/apps/tags/views.py +++ b/mayan/apps/tags/views.py @@ -12,6 +12,7 @@ from django.template import RequestContext from django.utils.translation import ugettext_lazy as _, ungettext from acls.models import AccessControlList +from common.utils import encapsulate from common.views import SingleObjectListView from documents.models import Document from documents.views import DocumentListView @@ -110,6 +111,17 @@ def tag_multiple_attach(request): class TagListView(SingleObjectListView): + @staticmethod + def get_document_count(instance, user): + queryset = instance.documents + + try: + Permission.check_permissions(user, [permission_document_view]) + except PermissionDenied: + queryset = AccessControlList.objects.filter_by_access(permission_document_view, user, queryset) + + return queryset.count() + object_permission = permission_tag_view def get_tag_queryset(self): @@ -121,9 +133,12 @@ class TagListView(SingleObjectListView): def get_extra_context(self, **kwargs): return { - 'title': _('Tags'), + 'extra_columns': [ + {'name': _('Documents'), 'attribute': encapsulate(lambda instance: TagListView.get_document_count(instance=instance, user=self.request.user))}, + ], 'hide_link': True, - 'hide_object': True, + + 'title': _('Tags'), } @@ -236,6 +251,7 @@ class DocumentTagListView(TagListView): def get_extra_context(self): return { + 'hide_link': True, 'object': self.document, 'title': _('Tags for document: %s') % self.document, }