如何在工作流转换后禁用本地角色获取?

时间:2014-01-09 17:12:39

标签: plone

使用Intranet工作流,当用户选择隐藏转换以将内容移动到私有状态时,我想禁用本地角色获取。我想当他们把它移回内部草案时我会想重新启用。

我可以看到plone.app.workflow中的共享视图是如何完成的。它有一个方法update_inherit,它将context.__ac_local_roles_block__设置为TrueNone

我如何使用after_script转换做类似的事情?

  • Plone 4.1.5
  • plone.app.workflow 2.0.6

有关我的用例的更多信息:

我们有两个用户,contributor_1和contributor_2,全球只拥有会员角色。在站点根目录下,创建一个文件夹并为两个用户分配本地角色以进行添加,编辑和查看。

这是默认的私有状态/ manage_permissions: default private state permissions

如果contributor_1创建了一个页面并试图隐藏它,那么contributor_2仍然可以查看,编辑并将其转换回内部草稿,因为contributor_2会继承这些本地角色。

这是我第一次尝试: enter image description here

虽然这确实有效地使页面专用于contributor_1和任何Manager,但是当项目处于私有状态时,contributor_1无法与contributor_2共享访问权限。没有私人合作。更新:contributor_1可以操作共享视图(即,他们可以访问委派本地角色),但委派那些本地角色(贡献者,编辑者,阅读器)不会转换为他们各自的访问权限,因为我已经撤销了角色权限映射。以上工作流程。

现在,如果设置回默认权限映射,用户可以通过隐藏内容项然后转到共享选项卡并禁用本地角色获取来实现所需的私有状态。问题是他们不想每次想要隐藏某些东西时都要记得点击共享标签上的复选框。

2 个答案:

答案 0 :(得分:1)

正如SteveM已经评论过的那样,工作流工具可以为您处理。

  1. 您需要使用工作流程管理所有必要的权限,这取决于您的需求。 更新:您的工作流程必须管理“委派角色XYZ [读者/贡献者/等]”和“更改本地角色”权限。这样,用户“contributor_1”可以在“私有”区域中委派角色。

  2. 请勿获取hidden州的任何权限设置。 plone workflow state permissions

  3. 在您的情况下,所有者(可能也是经理)需要一些权限来查看/编辑/更改状态。

  4. 定义工作流程的另一个提示。 检查this package它通常管理操作组中的所有权限,如查看(查看,访问内容权限等)或添加(添加文件夹,添加门户内容,添加...等)所有Plone默认权限均为映射到正确的操作组,它让您在5分钟内创建工作流程。最好的部分是,您可以在人类可读的规范文件(自定义DSL)中编写工作流程。

答案 1 :(得分:0)

我在我的包中创建了一个utils.py模块,其中包含一个方法:共享视图使用的update_inherit方法的(几乎)直接copypasta。然后,我在我的包__init__.py

中导入了utils
from AccessControl import Unauthorized
from AccessControl.SecurityInfo import ModuleSecurityInfo
from Acquisition import aq_base
from Products.CMFCore import permissions
from Products.CMFCore.utils import getToolByName

security = ModuleSecurityInfo( 'united.policy.utils' )

security.declarePublic('update_inherit')
def update_inherit(context, status=True, reindex=True):
    """Enable or disable local role acquisition on the context.

    Returns True if changes were made, or False if the new settings are the
    same as the existing settings.
    """
    portal_membership = getToolByName(context, 'portal_membership')

    if not portal_membership.checkPermission(permissions.ModifyPortalContent,
                                             context):
        raise Unauthorized

    block = not status
    oldblock = bool(getattr(aq_base(context), '__ac_local_roles_block__',
                            False))

    if block == oldblock:
        return False

    if block:
        # If user has inherited local roles and removes inheritance, locally
        # set roles he inherited before to avoid definitive loss of access
        # (refs #11945)
        user = portal_membership.getAuthenticatedMember()
        context_roles = user.getRolesInContext(context)
        global_roles = user.getRoles()
        local_roles = [r for r in context_roles if r not in global_roles]
        if local_roles:
            context.manage_setLocalRoles(user.getId(), local_roles)

    context.__ac_local_roles_block__ = block and True or None
    if reindex:
        context.reindexObjectSecurity()

    return True

然后,我在绑定到各自转换的./profiles/default/workflows/intranet_workflow/scripts/目录中创建了两个脚本:

after_hide.py

## Script (Python) "after_hide"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=review_state
##title=
##
from united.policy.utils import update_inherit

update_inherit(review_state.object, False)

after_show.py

## Script (Python) "after_show"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=review_state
##title=
##
from united.policy.utils import update_inherit

update_inherit(review_state.object, True)