[Plone-Users] Listing content having local "sharing" roles by a specific user

68 views
Skip to first unread message

Jim Biggs

unread,
Dec 30, 2010, 11:24:11 PM12/30/10
to plone...@lists.sourceforge.net

I'm trying to figure out the best way to list all content for which a
specific user has been given a local sharing role -- e.g. view, edit...

It seems the solution rests with
site/portal_catalog/Indexes/allowedRolesAndUsers. Looking in the ZMI, one
can see the allowedRolesAndUsers index has an entry for each user, e.g.
user:member1 -- where the "user:member1" entry has a list of content the
user has the "view" permission -- both globally and locally, via sharing.

A new content share will immediately become visible for the target user in
the allowedRolesAndUsers index. Removing the share immediately removes the
content entry from the allowedRolesAndUsers index for the user.

Per the API, allowedRolesAndUsers(obj, portal, **kwargs) returns a list of
roles and users with View permission -- which is a list from the content
object perspective. My question is:

How does one list the content objects and roles related to a specific user
-- i.e. return a list from the user perspective?

Any direction is appreciated.

Regards... Jim
--
View this message in context: http://plone.293351.n2.nabble.com/Listing-content-having-local-sharing-roles-by-a-specific-user-tp5877749p5877749.html
Sent from the General Questions mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Plone-Users mailing list
Plone...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users

Maurits van Rees

unread,
Dec 31, 2010, 2:59:38 AM12/31/10
to plone...@lists.sourceforge.net
Op 31-12-10 05:24, Jim Biggs schreef:

>
> I'm trying to figure out the best way to list all content for which a
> specific user has been given a local sharing role -- e.g. view, edit...
>
> It seems the solution rests with
> site/portal_catalog/Indexes/allowedRolesAndUsers. Looking in the ZMI, one
> can see the allowedRolesAndUsers index has an entry for each user, e.g.
> user:member1 -- where the "user:member1" entry has a list of content the
> user has the "view" permission -- both globally and locally, via sharing.
>
> A new content share will immediately become visible for the target user in
> the allowedRolesAndUsers index. Removing the share immediately removes the
> content entry from the allowedRolesAndUsers index for the user.
>
> Per the API, allowedRolesAndUsers(obj, portal, **kwargs) returns a list of
> roles and users with View permission -- which is a list from the content
> object perspective. My question is:
>
> How does one list the content objects and roles related to a specific user
> -- i.e. return a list from the user perspective?
>
> Any direction is appreciated.
>
> Regards... Jim

This is not possible with the standard catalog indexes. I also do not
know an add-on product that does this, though you could try your luck by
searching.

So you will have to write your own python code in an extra package. You
can get the local roles of a user in a context like this:

context.get_local_roles_for_userid('joe')

I did something slightly similar just yesterday, so I will post that
code here as an example. At least it deals with local roles too. For
each item in the site it shows which users have a specific local role,
and optionally which other local roles they have there. (The goal for
me was to figure out if the custom 'Áuthor' role that was defined in a
client site was actually used anywhere.)

The zcml:

============================================================
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
name="my-role-info"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
permission="zope2.ViewManagementScreens"
class=".roles.LocalRoleInfo"
/>
</configure>
============================================================

The python code in roles.py:

============================================================
import logging
from Products.Five import BrowserView
from Acquisition import aq_inner

logger = logging.getLogger('roles')


class LocalRoleInfo(BrowserView):

def __call__(self):
"""Give info about local roles.
"""
context = aq_inner(self.context)
self.found = 0
self.messages = []

self.role = self.request.get('role')
if not self.role:
return ("Please specify for example '?role=Manager&more=1' to "
"report local Managers and their other local roles.")
try:
self.more = bool(int(self.request.get('more', '')))
except Exception:
self.more = False

def do_one(obj, path):
try:
users = obj.users_with_local_role(self.role)
except AttributeError:
return
if not users:
return
self.found += 1
msg = "Users with local role %s on %s = %r" % (
self.role, obj.absolute_url(), users)
logger.info(msg)
self.messages.append(msg)
# Maybe specify extra info.
if not self.more:
return
for user in users:
msg = "User %s has local roles %r" % (
user, obj.get_local_roles_for_userid(user))
logger.info(msg)
self.messages.append(msg)

logger.info("Checking for users with local role %s", self.role)
context.ZopeFindAndApply(context, apply_func=do_one,
search_sub=True)
msg = "Found %d objects." % self.found
logger.info(msg)
self.messages.insert(0, msg)
logger.info("Ready.")
return '\n'.join(self.messages)
============================================================

Cheers,

--
Maurits van Rees
Programmer, Zest Software

Jim Biggs

unread,
Jan 3, 2011, 8:59:49 PM1/3/11
to plone...@lists.sourceforge.net

Hello Maurits,

Thank you for the insight and the sample code too. I was always planning to
write the python code since I wish to incorporate this feature into one of
my products. I was just stumped on where to start. As I shared in my
original post, my research led me to allowedRolesAndUsers index, which I
continue to believe has all the information, but the index returns
information from the wrong context.

Your example code gives me another path to follow, so I'll experiment with
your code and let you know how well I progress.

Thanks again... Jim
--
View this message in context: http://plone.293351.n2.nabble.com/Listing-content-having-local-sharing-roles-by-a-specific-user-tp5877749p5887376.html


Sent from the General Questions mailing list archive at Nabble.com.

------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages