From a6e1df9b3af28af0502e363ba64c6e03c48e7234 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 17 Jun 2012 00:38:00 -0400 Subject: [PATCH] Allow giving access to the history of specific documents via ACLs --- apps/history/__init__.py | 3 +-- apps/history/views.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/history/__init__.py b/apps/history/__init__.py index b0b4025a3e..24469fbd2c 100644 --- a/apps/history/__init__.py +++ b/apps/history/__init__.py @@ -6,7 +6,6 @@ from project_tools.api import register_tool from .permissions import PERMISSION_HISTORY_VIEW - -history_list = {'text': _(u'history'), 'view': 'history_list', 'famfam': 'book', 'icon': 'book.png', 'permissions': [PERMISSION_HISTORY_VIEW], 'children_view_regex': [r'history_[l,v]']} +history_list = {'text': _(u'history'), 'view': 'history_list', 'famfam': 'book', 'icon': 'book.png', 'children_view_regex': [r'history_[l,v]']} register_tool(history_list) diff --git a/apps/history/views.py b/apps/history/views.py index 7f61bf80e0..8b29a5d1ca 100644 --- a/apps/history/views.py +++ b/apps/history/views.py @@ -19,12 +19,22 @@ from .permissions import PERMISSION_HISTORY_VIEW from .widgets import history_entry_object_link, history_entry_summary -def history_list(request): - Permission.objects.check_permissions(request.user, [PERMISSION_HISTORY_VIEW]) +def history_list(request, object_list=None, title=None, extra_context=None): + pre_object_list = object_list if not (object_list is None) else History.objects.all() + + try: + Permission.objects.check_permissions(request.user, [PERMISSION_HISTORY_VIEW]) + except PermissionDenied: + # If user doesn't have global permission, get a list of document + # for which he/she does hace access use it to filter the + # provided object_list + final_object_list = AccessEntry.objects.filter_objects_by_access(PERMISSION_HISTORY_VIEW, request.user, pre_object_list, related='content_object') + else: + final_object_list = pre_object_list context = { - 'object_list': History.objects.all(), - 'title': _(u'history events'), + 'object_list': final_object_list, + 'title': title if title else _(u'history events'), 'extra_columns': [ { 'name': _(u'date and time'), @@ -42,6 +52,9 @@ def history_list(request): 'hide_object': True, } + if extra_context: + context.update(extra_context) + return render_to_response('generic_list.html', context, context_instance=RequestContext(request))