问题
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.
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.
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"
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!!
回答1:
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)
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.
来源:https://stackoverflow.com/questions/7787352/list-folders-that-a-user-has-reviewer-access-to-in-plone-4