manage_access problems
Hello, I would like find a function like "manage_acces" which can give me the roles cheked for a permission. Example : I have a folder "myFolder" and I use this function : <dtml-let folderPermissions="folderEditing.rolesOfPermission('Access contents information')"> <dtml-var folderPermissions> </dtml-let> the variable folderPermissions return me this list : [{'selected': '', 'name': 'Anonymous'}, {'selected': 'SELECTED', 'name': 'Manager'}, {'selected': '', 'name': 'Member'}, {'selected': '', 'name': 'Owner'}, {'selected': 'SELECTED', 'name': 'Reviewer'}, {'selected': '', 'name': 'User'}, {'selected': '', 'name': 'publisher'}] With this list I can see "Manager" and "Reviewer" roles are checked because the string SELECTED appears. if I use <dtml-var folderPermissions[4]>, that's give me {'selected': 'SELECTED', 'name': 'Reviewer'}. But I can't access in this object if I want 'Reviewer' ??? it isn't a list or a string because I canp't use : <dtml-var folderPermissions[4][3]> for access to the 3th element, and I can't use <dtml-var expr="_.string.find(folderPermissions[4],'SELECTED',0)"> because it isn't a string .... Can you help me and tell me how I can use this object. Regards, Johan Beaucé.
But I can't access in this object if I want 'Reviewer' ??? it isn't a list or a string because I canp't use
No its a dictionary, have a look at the python documentation to understand what a dict is. http://www.python.org/doc/current/tut/node7.html#SECTION00740000000000000000 0 Since this is a complicated data structure, you should really be using a Python script. However if what you are trying to do is who has the Access Contents Information role, this will work: <dtml-in "folderEditing.rolesOfPermission('Access contents information')"> <dtml-if "_['sequence-item']['selected']=='SELECTED'"> <dtml-var "_['sequence-item']['name']"> </dtml-if> </dtml-in>
On Thu, Aug 30, 2001 at 07:33:23AM -0700, Zopista wrote:
But I can't access in this object if I want 'Reviewer' ??? it isn't a list or a string because I canp't use
No its a dictionary, have a look at the python documentation to understand what a dict is.
http://www.python.org/doc/current/tut/node7.html#SECTION00740000000000000000 0
Since this is a complicated data structure, you should really be using a Python script. However if what you are trying to do is who has the Access Contents Information role, this will work:
<dtml-in "folderEditing.rolesOfPermission('Access contents information')"> <dtml-if "_['sequence-item']['selected']=='SELECTED'"> <dtml-var "_['sequence-item']['name']"> </dtml-if> </dtml-in>
Alternativelly, you could use (note that I didn't test it) <dtml-in "folderEditing.rolesOfPermission('Access contents information')" mapping> <dtml-if "selected == 'SELECTED'" <dtml-var name> </dtml-if> </dtml-in> the 'mapping' attribute of dtml-in assumes sequence-key to be a mapping (i.e. a dictionary) and pushes the key-value pairs onto the namespace. Regards, Leo
Johan Beauce writes:
I would like find a function like "manage_acces" which can give me the roles cheked for a permission. Example : I have a folder "myFolder" and I use this function : <dtml-let folderPermissions="folderEditing.rolesOfPermission('Access contents information')"> <dtml-var folderPermissions> </dtml-let> the variable folderPermissions return me this list : [{'selected': '', 'name': 'Anonymous'}, {'selected': 'SELECTED', 'name': 'Manager'}, {'selected': '', 'name': 'Member'}, {'selected': '', 'name': 'Owner'}, {'selected': 'SELECTED', 'name': 'Reviewer'}, {'selected': '', 'name': 'User'}, {'selected': '', 'name': 'publisher'}]
Python Script: Arguments: obj, permission Body: roles= [] for d in obj.rolesOfPermission(permission): if d['selected']: roles.append(d['name']) return roles Dieter
participants (4)
-
Dieter Maurer -
Johan Beauce -
Leonardo Rochael Almeida -
Zopista