[Product-Developers] How to display borg.localrole in Sharing tab

Asko Soukka asko.soukka at iki.fi
Mon Dec 3 18:45:43 UTC 2012


Sean Upton wrote:
> On Fri, Mar 23, 2012 at 3:11 PM, Marcos Romero
> <marcos.romero at inter-cultura.com>  wrote:
>> I'm adding principals (users and groups) to existing roles
>> programatically via borg.localrole. I'd like those principals to be
>> shown under "Can read", "Can edit", "Can review" columns in the
>> Sharing tab.
>>
>> I don't wont to add new roles there, just to see people who
>> effectively have those roles,
>
>
> Override the sharing view to meet your needs, perhaps?

Hi Marcos,

did you eventually manage to find way to display borg.localroles on the 
sharing tab?

I did follow follow Sean's idea on overriding the sharing view,
actually monkeypatching

plone.app.workflow.browser.sharing.SharingView._inherited_roles *)

so that roles provided by borg.localrole adapter are shown as
inherited roles.

Maybe we could try to PLIP this into Plone on some day.

Best Regards,
Asko

*)

from Products.CMFCore.utils import getToolByName


def _inherited_roles(self):
     # Get the default values:
     result = self._old__inherited_roles()

     # Get all local roles (includeding those provided
     # by borg_localroles) and editable local roles
     # (only those stored in the object):
     pas = getToolByName(self.context, "acl_users")
     editable_local_roles = dict(self.context.get_local_roles())

     # Calculate borg_local_roles by substracting editable local
     # roles from all available local roles (including the
     #  borg_localrole provided roles):
     borg_local_roles = pas.getAllLocalRoles(self.context)
     for one_user, roles in editable_local_roles.items():
         borg_local_roles[one_user] =
             filter(lambda x: x not in roles,
                    borg_local_roles.get(one_user, ()))
         if not borg_local_roles[one_user]:
             del borg_local_roles[one_user]

     # Adapted from: PluggableAuthService._getLocalRolesForDisplay
     borg_result = []
     for one_user in borg_local_roles.items():
         username = userid = one_user[0]
         roles = one_user[1]
         userType = 'user'
         if pas.getGroup(userid):
             userType = 'group'
         else:
             user = pas.getUserById(userid) or pas.getUser(username)
             if user:
                 username = user.getUserName()
                 userid = user.getId()
         borg_result.append((username, tuple(roles), userType, userid))

     return result + tuple(borg_result)


More information about the Product-Developers mailing list