From df44b0daf428f1cd6d0079c4994be6070ecf82b2 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 17 Apr 2014 19:32:30 +0000 Subject: [PATCH] make per item document info editable if user can edit item --- pandora/document/models.py | 5 +++-- pandora/document/views.py | 4 ++-- static/js/documentsPanel.js | 3 ++- static/js/item.js | 5 ++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pandora/document/models.py b/pandora/document/models.py index cb2d3557..705e2bdf 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -98,12 +98,13 @@ class Document(models.Model): def get_id(self): return ox.toAZ(self.id) - def editable(self, user): + def editable(self, user, item=None): if not user or user.is_anonymous(): return False if self.user == user or \ user.is_staff or \ - user.get_profile().capability('canEditDocuments') == True: + user.get_profile().capability('canEditDocuments') == True or \ + (item and item.editable(user)): return True return False diff --git a/pandora/document/views.py b/pandora/document/views.py index 505e4f79..7783bf1d 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -82,8 +82,8 @@ def editDocument(request): item = 'item' in data and Item.objects.get(itemId=data['item']) or None if data['id']: document = models.Document.get(data['id']) - if document.editable(request.user): - document.edit(data, request.user, item=item) + if document.editable(request.user, item): + document.edit(data, request.user, item) document.save() response['data'] = document.json(user=request.user, item=item) else: diff --git a/static/js/documentsPanel.js b/static/js/documentsPanel.js index 0afb7400..f6a49d0b 100644 --- a/static/js/documentsPanel.js +++ b/static/js/documentsPanel.js @@ -520,7 +520,8 @@ pandora.ui.documentsPanel = function(options) { var $name, $description, item = $list.value($list.options('selected')[0]), editable = item.user == pandora.user.username - || pandora.site.capabilities.canEditDocuments[pandora.user.level], + || pandora.site.capabilities.canEditDocuments[pandora.user.level] + || options.editable, labelWidth = 80, width = ui.documentSize - 16 - Ox.UI.SCROLLBAR_SIZE; return isItemView diff --git a/static/js/item.js b/static/js/item.js index 8f87ce44..baee8721 100644 --- a/static/js/item.js +++ b/static/js/item.js @@ -68,7 +68,10 @@ pandora.ui.item = function() { } else if (pandora.user.ui.itemView == 'documents') { pandora.$ui.contentPanel.replaceElement(1, - pandora.$ui.documents = pandora.ui.documentsPanel({isItemView: true}) + pandora.$ui.documents = pandora.ui.documentsPanel({ + editable: result.data.editable, + isItemView: true + }) ); } else if (pandora.user.ui.itemView == 'player') {