I want to set the roles of a permission and turn acquisition of a permission
(mapping) on and off programmatically. And of course I want to get a
permission by its name. This looks definitely more complex than simply
changing an object's property!

I took a look at the management screens(Role.py ->
manage_changePermissions). The aX and pYrZ mapping for the *checkboxes*
(=sole purpose) gave me a lot of confusion, I first thought this was Zope
internal naming :-). Then I took a look at Permission.py (setRoles). But I
haven't dealt with this before, and it all looks a little weird. I managed
to write a couple of functions that give me roles to permissions and
permissions to roles or check if a permission setting has been acquired and
so on, but I'm stuck with *setting* permissions with a function of my own.

a) Could this be correct?

# roles as list: acquisition will be turned on

# roles as tuple: acquisition will be turned off

# set as specified

b) How can I get a hold of some_permission when I know its name? This does
not work:

def setRolesForPermission(ob, permission, roles, setacquired):
  permission_trans = '_' + replace(permission, ' ', '_') + '_Permission'
  p = getattr(ob, permission_trans) # this does *not* give me the permission
  if not setacquired:

It must have something to do with acquisition :-)
If it is turned on for that permission, getattr() won't find the attribute.
If it's turned off, it returns a tuple. Where's the permission instance

I see that ac_inherited_permissions(1) gives me a list of permission names,
but I don't know how to access a specific permission directly.

This *did* work:

def permissionAcquired(ob, permission):
# Tell me if acquisition has been turned on
# (There's also some other way, checking if the returned is of type List or
Tuple, I think I saw that somewhere in Role.py)

  permission_trans = '_' + replace(permission, ' ', '_') + '_Permission'
  return (not hasattr(ob.aq_base, permission_trans))

Thank you so much in advance,


Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to