Shows the cabinets in the document list.
Signed-off-by: Cornelius Ludmann <dev@cornelius-ludmann.de>
This commit is contained in:
committed by
Roberto Rosario
parent
c96745ce0e
commit
b7361059e2
@@ -10,6 +10,7 @@ from common import (
|
||||
menu_sidebar
|
||||
)
|
||||
from documents.search import document_page_search, document_search
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .links import (
|
||||
@@ -26,6 +27,7 @@ from .permissions import (
|
||||
permission_cabinet_edit, permission_cabinet_remove_document,
|
||||
permission_cabinet_view
|
||||
)
|
||||
from .widgets import widget_document_cabinets
|
||||
|
||||
|
||||
class CabinetsApp(MayanAppConfig):
|
||||
@@ -117,3 +119,10 @@ class CabinetsApp(MayanAppConfig):
|
||||
'cabinets:document_cabinet_remove'
|
||||
)
|
||||
)
|
||||
|
||||
SourceColumn(
|
||||
source=Document, label=_('XCabinets'),
|
||||
func=lambda context: widget_document_cabinets(
|
||||
document=context['object'], user=context['request'].user
|
||||
)
|
||||
)
|
||||
@@ -1,5 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.html import format_html_join
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from .permissions import permission_cabinet_view
|
||||
|
||||
def jstree_data(node, selected_node):
|
||||
result = []
|
||||
@@ -26,3 +32,23 @@ def jstree_data(node, selected_node):
|
||||
result.append('},')
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def widget_document_cabinets(document, user):
|
||||
"""
|
||||
A cabinet widget that displays the cabinets for the given document
|
||||
"""
|
||||
AccessControlList = apps.get_model(
|
||||
app_label='acls', model_name='AccessControlList'
|
||||
)
|
||||
|
||||
cabinets = AccessControlList.objects.filter_by_access(
|
||||
permission_cabinet_view, user, queryset=document.document_cabinets().all()
|
||||
)
|
||||
|
||||
return format_html_join(
|
||||
'\n', '<div class="cabinet-display">{}</div>',
|
||||
(
|
||||
(cabinet.get_full_path(),) for cabinet in cabinets
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user