列出用户在Plone 4中具有Reviewer访问权限的文件夹 [英] List folders that a user has Reviewer access to in Plone 4

查看:83
本文介绍了列出用户在Plone 4中具有Reviewer访问权限的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个文件夹,其中包含数百个子文件夹.每个子文件夹代表一个文档提交,并且其中包含与提交相关的项目.每个子文件夹的默认页面是自定义页面模板(基于文档),根据查看用户角色是什么,该页面显示略有不同的信息.例如,具有管理者"角色的用户所看到的内容与具有审阅者"角色或编辑者"角色的用户略有不同.站点上的用户被分配给不同的文件夹不同的角色-例如,管理者可以在文件夹1-5上将用户A分配为审阅者,而在文件夹6-10上将用户B分配为审阅者.

I have a folder in my site that contains hundreds of subfolders. Each subfolder represents a document submission, and has items in it that are related to the submission. The default page for each subfolder is a custom page template (based on Document) that displays slightly different information depending on what the viewing users Role is. For instance, users with Manager role see something slightly different than users with Reviewer role or Editor role. Users on the site are assigned different roles to different folders - for instance, the Manager can assign User A as a Reviewer on folders 1-5, and User B as a Reviewer on folders 6-10.

我想在用户的仪表板中创建一个Portlet,以显示已分配给审阅者访问权限的所有文件夹,或者我可以在仪表板中仅链接到页面模板(如果这样更简单)就可以了.我原本以为我会创建一个集合,但是没有内置的挂钩"来显示用户被分配了特定角色的内容.

I'd like to create a portlet in the user's dashboard that displays all folders that they have been assigned Reviewer access to, or I'd be OK with just a link in the dashboard that goes to a Page Template if that's easier. I originally thought I'd create a collection, but there is no built in "hook" to display content that a user is assigned a certain role on.

我不能简单地限制它,以便除非您具有审阅者角色,否则该内容是不可见的,因为所有已认证的用户都必须可以查看该内容.

I can't simply restrict it so that the content is not viewable unless you have reviewer role, because it needs to be viewable by all authenticated users.

我一直在使用标准视图(folder_listing)模板来尝试找到正确的代码.我尝试在"entry"插槽的开头定义一个"roles"变量:

I've been playing with the standard view (folder_listing) template to try and find the right code. I've tried defining a "roles" variable at the beginning of the "entry" slot:

tal:define="member context/portal_membership/getAuthenticatedMember; 
                   roles python:member.getRolesInContext(item);"

并对项目使用条件,以仅显示用户具有审阅者角色的项目:

and use a condition to the item to display only items that the user has reviewer role on:

tal:condition="python:'Reviewer' in roles"

此处是指向整页模板的链接: http://www. tempfiles.net/download/201110/214265/folder_listing.html

Here is a link to the full page template: http://www.tempfiles.net/download/201110/214265/folder_listing.html

当我使用它时,我什么都没有得到.我对其进行了稍微的修改,以便仅在页面中向我显示它所扮演的角色,并且我认为它不会影响当前项目的角色.

When I use that, I just get no result. I've modified it slightly so that it just shows me in the page what role it's getting, and I don't think it's pulling the role of the current item.

朝正确方向的推动将不胜感激!

A push in the right direction would be greatly appreciated!!

推荐答案

我认为问题在于,正如名称所说,getRolesInContext期望有一个上下文,而不仅仅是大脑.您应该尝试提供真实的对象:

I think the problem is that getRolesInContext, as the name says, expects a context, not only a brain. You should try to provide the real object:

tal:define="member context/portal_membership/getAuthenticatedMember; 
            itemObj item/getObject
            roles python:member.getRolesInContext(itemObj);"

否则,如果您只想查找本地分配的角色,则可以使用以下代码:

Otherwise if you want to find only local assigned roles you could use this code:

from Products.CMFCore.utils import getToolByName

portal_url = getToolByName(context, "portal_url")
portal = portal_url.getPortalObject()
acl_users = portal.acl_users

res = []

for item in items:
    itemObj = item.getObject()
    local_roles = acl_users._getLocalRolesForDisplay(itemObj)
    for name, roles, rtype, rid in local_roles:
        if member.getId() == rid and 'Reviewer' in roles:
           res.append(item)

此(未经测试)代码的灵感来自共享视图在plone.app.workflow程序包中. 您可以将此代码放在自定义portlet中,也可以放在Renderer类的方法中.

This (untested) code is inspired to the sharing view in plone.app.workflow package. You can put this code in a custom portlet, maybe in a method in the Renderer class.

这篇关于列出用户在Plone 4中具有Reviewer访问权限的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆