您必须按如下方式自定义您的工作流程:
- 转到 Zope 管理界面-> portal_workflow
- 创建一个新状态,比如说“预告片”(这是可选的,您可以改为自定义现有状态...也许私有状态是处理特定用户/组限制的好选择)
- 从处于该特定状态的匿名用户移除除“访问内容信息”之外的所有权限
- 按下“更新安全设置”按钮
完成!
现在所有处于“预告片”状态的内容都可以搜索,但匿名用户无法查看。
注意:如果您按照我的建议选择创建新状态,请务必添加所有需要的转换。
编辑:
不幸的是,我不知道在最近的 Plone 版本中,portal_catalog (allowedRolesAndUsers) 中有一个新索引会阻止上述过程像以前一样工作。上述过程仍然正确,但您需要覆盖默认索引器。
首先create a new package with paster 使用“plone”模板。然后在包的主层(例如 my.package/my/package)中添加一个名为 indexers.py 的文件:
from zope.interface import Interface
from plone.indexer.decorator import indexer
from AccessControl.PermissionRole import rolesForPermissionOn
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.CatalogTool import _mergedLocalRoles
@indexer(Interface)
def allowedRolesAndUsers(obj):
"""Return a list of roles and users with View permission.
Used by PortalCatalog to filter out items you're not allowed to see.
"""
allowed = {}
for r in rolesForPermissionOn('Access contents information', obj):
allowed[r] = 1
# shortcut roles and only index the most basic system role if the object
# is viewable by either of those
if 'Anonymous' in allowed:
return ['Anonymous']
elif 'Authenticated' in allowed:
return ['Authenticated']
localroles = {}
try:
acl_users = getToolByName(obj, 'acl_users', None)
if acl_users is not None:
localroles = acl_users._getAllLocalRoles(obj)
except AttributeError:
localroles = _mergedLocalRoles(obj)
for user, roles in localroles.items():
for role in roles:
if role in allowed:
allowed['user:' + user] = 1
if 'Owner' in allowed:
del allowed['Owner']
return list(allowed.keys())
然后在同一级别添加一个文件overrides.zcml :
<configure xmlns="http://namespaces.zope.org/zope">
<adapter factory=".indexers.allowedRolesAndUsers" name="allowedRolesAndUsers" />
</configure>
最后你的产品树应该是这样的:
my.package/
├── my
│ ├── __init__.py
│ └── package
│ ├── configure.zcml
│ ├── overrides.zcml
│ ├── indexers.py
│ ├── __init__.py
│ ├── profiles
│ │ └── default
│ │ └── metadata.xml
│ └── tests.py
├── README.txt
├── setup.cfg
└── setup.py
最后,您需要在 buildout.cfg 中包含新创建的 egg:
eggs =
my.package
develop =
src/my.package
重新运行构建。就是这样。