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

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:20:52

问题


I'm back to using Plone after a very long time without using it. We have setup an Intranet with Plone 4.0.5. We have upload lots of documents (mostly File) to the intranet.

The site was installed using the Plone Unified Installer with a ZEO configuration. Some products (eggs) were added (if you need some part of our buildout.cfg and/or versions.cfg; please ask for it) to our buildout.cfg

With both the ZEO server and clients running; I'm doing:

 $ bin/client1 debug
 Starting debugger (the name "app" is bound to the top-level Zope object)
 ... several warnings ...
 >>>

Now, I query the catalog like this:

 >>> len(app.plone.portal_catalog(portal_type="File"))
 17

However if go to the ZMI and traverse to the portal_catalog/Indexes, go to portal_type and browse, the "File" items has a lot more of elements.

This is probably because I have not logged in:

 >>> from Products.CMFCore.utils import _getAuthenticatedUser
 >>> _getAuthenticatedUser(app.ca.portal_catalog)
 <SpecialUser 'Anonymous User'>

How do I put the console in the "context" of an admin user?


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/12150401/plones-portal-catalogportal-type-file-does-not-returns-all-the-objects-i-se

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