2014-03-07 44 views
0

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

<property name="add_permission">my.product.EditContent</property> 

这可以防止每个人都创建这种没有适当权限的类型。此外,我想防止修改内容,并期望类似于:

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

但这不起作用。我怎样才能管理这个?

+2

我想最好的方法是为您的类型创建一个自定义工作流程。在此工作流程中,您只允许网站管理员“Mofify门户内容”和“添加您的内容类型”。 – Mathias

回答

1

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

如果您只是要求,为管理员授予添加权限并且不需要进一步优化,您实际上不需要定义新的权限,只需将其立即授予管理员,如下所示:

<property name="add_permission">cmf.ManagePortal</property>

对于允许编辑只经理,我会阻止本地权限的分配的继承与这条线在你的contentType的类声明:

class YourDexterityContenttypeClassName(dexterity.Item): __ac_local_roles_block__ = True

但是,这也会阻止继承的查看和查看权限。如果你需要照顾这些分开过,另一种方法是添加上创造你的contentType中的事件监听,检查继承的角色,并删除它的编辑角色:

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() 

管理者可以编辑自己的无论如何默认情况下,contenttypes拥有全局修改权限。

注意:这是昂贵的调用,并且此示例仅查找用户分配,您可能必须扩展此示例以查找分配的组。

相关问题