refactor and fixed insufficant pirvileges when the user doesn't have access to the target
This commit is contained in:
parent
da0f1e22b7
commit
ac857ced83
|
@ -1,6 +1,7 @@
|
|||
from AccessControl import getSecurityManager
|
||||
from zope.interface import Interface, implements, implementer
|
||||
from zope.cachedescriptors.property import CachedProperty
|
||||
from five import grok
|
||||
from zope import schema
|
||||
from plone.directives import form
|
||||
|
||||
from plone.dexterity.content import Item
|
||||
|
@ -8,6 +9,7 @@ from plone.dexterity.content import Item
|
|||
from plone.supermodel import model
|
||||
|
||||
from plone.formwidget.contenttree import ObjPathSourceBinder
|
||||
from plone import api
|
||||
|
||||
from z3c.relationfield.schema import RelationChoice
|
||||
|
||||
|
@ -40,21 +42,37 @@ from collective.dms.basecontent.dmsdocument import IDmsDocument
|
|||
grok.templatedir('templates')
|
||||
grok.context(IDmsDocument)
|
||||
|
||||
from collective.dms.basecontent.browser.viewlets import BaseViewlet, DmsBelowContentViewletManager
|
||||
from collective.dms.basecontent.browser.viewlets import BaseViewlet
|
||||
|
||||
|
||||
from collective.dms.basecontent.browser.listing import BaseTable, BaseTitleColumn
|
||||
from collective.dms.basecontent.browser import column
|
||||
|
||||
class LinksTable(BaseTable):
|
||||
def setUpColumns(self):
|
||||
columns = super(LinksTable, self).setUpColumns()
|
||||
column_names = [column.__name__ for column in columns]
|
||||
selected_columns = ('dms.delete', 'dms.title')
|
||||
return [column for column in columns if column.__name__ in selected_columns]
|
||||
from collective.dms.basecontent.browser.table import Table
|
||||
|
||||
|
||||
class TitleColumn(BaseTitleColumn):
|
||||
class LinksTable(Table):
|
||||
|
||||
@CachedProperty
|
||||
def values(self):
|
||||
links = []
|
||||
sm = getSecurityManager()
|
||||
portal_catalog = api.portal.get_tool('portal_catalog')
|
||||
folder_path = '/'.join(self.context.getPhysicalPath())
|
||||
query = {'path': {'query' : folder_path},
|
||||
'portal_type': 'pfwbgedlink',
|
||||
'sort_on': 'sortable_title',
|
||||
'sort_order': 'ascending'}
|
||||
results = portal_catalog.searchResults(query)
|
||||
for brain in results:
|
||||
link = brain.getObject()
|
||||
target = link.folder.to_object
|
||||
if sm.checkPermission('View', target):
|
||||
links.append(brain)
|
||||
|
||||
return links
|
||||
|
||||
|
||||
class TitleColumn(column.TitleColumn):
|
||||
grok.name('dms.title')
|
||||
grok.adapts(Interface, Interface, LinksTable)
|
||||
|
||||
def getLinkContent(self, item):
|
||||
|
@ -69,24 +87,7 @@ class DeleteColumn(column.DeleteColumn):
|
|||
grok.adapts(Interface, Interface, LinksTable)
|
||||
|
||||
|
||||
class LinkViewlet(grok.Viewlet):
|
||||
grok.template('linksviewlet')
|
||||
grok.viewletmanager(DmsBelowContentViewletManager)
|
||||
class LinkViewlet(BaseViewlet):
|
||||
grok.order(15)
|
||||
portal_type = 'pfwbgedlink'
|
||||
label = _(u"Filed in Folders")
|
||||
|
||||
@property
|
||||
def table(self):
|
||||
table = LinksTable(self.context, self.request)
|
||||
table.values = self.links()
|
||||
table.update()
|
||||
return table
|
||||
|
||||
def links(self):
|
||||
links = []
|
||||
for child in self.context.getFolderContents():
|
||||
if child.portal_type != 'pfwbgedlink':
|
||||
continue
|
||||
links.append(child)
|
||||
return links
|
||||
label = _(u"Filed in folders")
|
||||
__table__ = LinksTable
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<tal:block tal:define="links viewlet/links">
|
||||
<fieldset tal:condition="links">
|
||||
<legend
|
||||
i18n:translate=""
|
||||
tal:content="viewlet/label">label</legend>
|
||||
<table tal:replace="structure viewlet/table/render"/>
|
||||
</fieldset>
|
||||
</tal:block>
|
Reference in New Issue