Plone的portal_catalog(portal_type =“File”)不返回我在ZMI portal_catalog页面中看到的所有对象

时间:2012-08-27 22:18:45

标签: plone

我很长一段时间没有使用它,我又回来使用Plone了。我们已经使用Plone 4.0.5建立了一个Intranet。我们已经将大量文档(主要是文件)上传到Intranet。

使用具有ZEO配置的Plone Unified Installer安装该站点。我们的buildout.cfg中添加了一些产品(鸡蛋)(如果你需要我们的buildout.cfg的一部分和/或versions.cfg;请问它)

ZEO服务器和客户端都在运行;我在做:

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

现在,我像这样查询目录:

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

但是,如果转到ZMI并遍历portal_catalog / Indexes,转到portal_type并浏览,则“File”项目中包含更多元素。

这可能是因为我还没有登录:

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

如何将控制台置于管理员用户的“上下文”中?

2 个答案:

答案 0 :(得分:6)

目录没有返回所有条目可能有几个原因:

  • 他们的许可不允许你看到它们,完全停止。在这方面,使用匿名用户肯定没有帮助。 : - )

  • 条目已过期;他们的过期日期现在已经过去,您无权查看这些过期日期。同样,使用非特权用户也无济于事。

  • 您正在使用多语言设置,而且这些项目不是“当前”语言。如果您的查询包含Language='all',则此过滤器已停用。

要在控制台上设置备用用户(最好是具有Manager角色的用户),请使用以下代码:

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)

就个人而言,每当我使用控制台时,我都会使用以下代码段;如果在我的Quicksilver Shelf中有这个,方便访问。首先我输入:

site_id = '<id of Plone site>' # Adjust as needed
然后粘贴:

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)

现在我已经完成了readline并且我需要在我的网站上做一些真正的损坏!

答案 1 :(得分:5)

对于非常特殊的情况(例如迁移),您可以使用

results = catalog.unrestrictedSearchResults(...)

这将返回所有结果而不进行过滤(绕过所有安全检查等)。

然而,这种方法是官方的私人方法,并且如下所示:小心使用它。