Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何设置灵巧内容类型的编辑权限?_Python_Plone_Dexterity - Fatal编程技术网

Python 如何设置灵巧内容类型的编辑权限?

Python 如何设置灵巧内容类型的编辑权限?,python,plone,dexterity,Python,Plone,Dexterity,我有一个灵巧的内容类型,只有网站管理员应该能够编辑它。为此,我创建了一个额外的权限,并将其授予站点管理员。对于我添加的xml类型: <property name="add_permission">my.product.EditContent</property> my.product.EditContent 这会阻止没有适当权限的所有人创建此类型。此外,我希望防止修改内容,并希望出现以下情况: <property name="edit_permission"&g

我有一个灵巧的内容类型,只有网站管理员应该能够编辑它。为此,我创建了一个额外的权限,并将其授予站点管理员。对于我添加的xml类型:

<property name="add_permission">my.product.EditContent</property>
my.product.EditContent
这会阻止没有适当权限的所有人创建此类型。此外,我希望防止修改内容,并希望出现以下情况:

<property name="edit_permission">unimr.subsite.EditTheme</property>
unimr.subsite.EditTheme

但这是行不通的。我如何管理它?

基于敏捷的内容类型的工厂类型信息(FTI)在
plone.dexterity/plone/dexterity/FTI.py
中声明了一个添加权限属性,但没有编辑权限属性

如果您的唯一要求是,要向经理授予“添加”权限,而不需要进一步改进,实际上您不需要定义新权限,只需立即将其授予经理,如下所示:

cmf.ManagePortal

为了只允许对管理器进行编辑,我将在contenttype的类声明中使用以下行阻止本地权限分配的继承:

class YourDexterityContenttypeClassName(dexterity.Item):
__ac\u本地\u角色\u块\u=真

但是,这也会阻止继承的查看和审阅权限。如果您也需要单独处理这些问题,另一种方法是在创建contenttype时添加eventlistener,检查继承的角色并删除其编辑角色:

from Acquisition import aq_inner

def blockEditors(obj, event):
    """ Remove possibly inherited editor-role.
    """

    context = aq_inner(obj)
    editors = context.users_with_local_role('Editor')

    # For any editor:
    for editor in editors:

        # Get her local-roles:
        roles = list(context.get_local_roles_for_userid(editor))

        # Subtract editor-role of roles:
        roles.remove('Editor')

        # Set roles (the old roles without editor):
        context.manage_setLocalRoles(editor, roles)

        # Update changes:
        context.reindexObjectSecurity()
默认情况下,管理员可以通过持有全局修改权限来编辑您的内容类型


注意:这是一个昂贵的呼叫,本例仅查找用户分配,您可能需要扩展本例,以查找分配的组。

我想最好的方法是为您的类型创建自定义工作流。在此工作流中,您只允许站点管理员
mofiny portal content
添加您的内容类型