如何为匿名用户而不是登录用户授予对字段的写入权限?

How do I grant write permission to a field for anonymous users but not logged-in users?

在我的 dexterity form 中,我有一个字段 "author"anonymous 填写,但没有 logged-in user.

我定义了一个名为 "isAnonymous" 的权限,并将 "isAnonymous" 授予匿名用户,

我这样使用dexterity.write_permission(author='isAnonymous'),

dexterity.write_permission(author='isAnonymous')
author=schema.TextLine(
    title=_(u'Author'),
)

但是,这个方法失败了,即使logged-in user也能看到这个字段。

在这个页面

http://docs.plone.org/develop/plone/security/standard_permissions.html

记下:

if a permission is granted to Anonymous, it is effectively granted to everyone. It is not possible to grant permissions to non-logged in users without also granting them to logged in ones.

那么,有什么建议吗?

Afaik 你不能用安全系统解决你的问题。但是你可以customise the Dexterity add/edit form

那么你就有了全部的权力:-)你可以实施一个条件,显示你的领域与否。

敏捷形式基于 z3c.forms and,因此它们具有多种方法,您可以覆盖这些方法(超级调用并做您的事情)。

在您的情况下,代码可能如下所示。

...

# I would recommend to use the `updateWidgets` method.

def updateWidgets(self):
    super(CustomAddEditView, self).updateWidgets()

    from plone import api
    if not api.user.is_anonymous():

        from z3c.form.interfaces import HIDDEN_MODE
        self.widgets['author'].mode = HIDDEN_MODE


...

More about hiding fields in the z3c.form Docu.