Plone's portal_catalog(portal_type=“File”) does not returns all the objects I see in the ZMI portal_catalog page

最后都变了- 提交于 2019-12-04 14:34:42

There can be several reasons the catalog doesn't return all entries:

  • Their permission doesn't allow you to see them, full stop. Using the anonymous user certainly doesn't help in that regard. :-)

  • The entries are expired; they have a expiration date that is now in the past and you don't have permission to see these. Again, using a non-privileged user won't help.

  • You are using a multi-lingual setup and the items are not in the 'current' language. If your query includes Language='all' this filter is disabled.

To set an alternative user (preferably one with the Manager role) on the console, use the following code:

from AccessControl.SecurityManagement import newSecurityManager

site = app['Plone'] # Adjust as needed
# Assuming your username is 'admin', adjust as needed again:
user = app.acl_users.getUser('admin').__of__(site.acl_users) 
newSecurityManager(None, user)

Personally, I use the following snippet whenever I use the console; if have this in my Quicksilver Shelf for easy access. First I type in:

site_id = '<id of Plone site>' # Adjust as needed

then paste:

import transaction, pdb
from zope.interface import implementedBy
from zope.component import getUtility, queryUtility, queryAdapter
from Zope2 import debug
from Acquisition import aq_inner, aq_parent, aq_chain
from zope.app.component.hooks import setSite, getSiteManager
from Testing.makerequest import makerequest
from AccessControl.SecurityManagement import newSecurityManager, getSecurityManager

try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")

app = makerequest(app)
site = app[site_id]
setSite(site)
user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)

Now I have readline completion and everything I need to do some real damage in my sites!

For very special cases (e.g. migrations) you might use the

results = catalog.unrestrictedSearchResults(...)

This will return all results without filtering (by-passing all security checks etc.)

However this method is official a private method and as written: use it with care.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!