Mercurial > p > roundup > code
comparison roundup/security.py @ 909:ef9c759c243e
Fix to hasPermission, thanks Stefan Seefeld.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 29 Jul 2002 21:53:29 +0000 |
| parents | a8d80ffe37cc |
| children | 62c49e259047 |
comparison
equal
deleted
inserted
replaced
| 908:a8d80ffe37cc | 909:ef9c759c243e |
|---|---|
| 76 | 76 |
| 77 Raise ValueError if there is no exact match. | 77 Raise ValueError if there is no exact match. |
| 78 ''' | 78 ''' |
| 79 if not self.permission.has_key(permission): | 79 if not self.permission.has_key(permission): |
| 80 raise ValueError, 'No permission "%s" defined'%permission | 80 raise ValueError, 'No permission "%s" defined'%permission |
| 81 | |
| 82 # look through all the permissions of the given name | |
| 81 for perm in self.permission[permission]: | 83 for perm in self.permission[permission]: |
| 84 # if we're passed a classname, the permission must match | |
| 82 if perm.klass is not None and perm.klass == classname: | 85 if perm.klass is not None and perm.klass == classname: |
| 83 return perm | 86 return perm |
| 87 # otherwise the permission klass must be unset | |
| 84 elif not perm.klass and not classname: | 88 elif not perm.klass and not classname: |
| 85 return perm | 89 return perm |
| 86 raise ValueError, 'No permission "%s" defined for "%s"'%(permission, | 90 raise ValueError, 'No permission "%s" defined for "%s"'%(permission, |
| 87 classname) | 91 classname) |
| 88 | 92 |
| 94 if roles is None: | 98 if roles is None: |
| 95 return 0 | 99 return 0 |
| 96 for rolename in roles.split(','): | 100 for rolename in roles.split(','): |
| 97 if not rolename: | 101 if not rolename: |
| 98 continue | 102 continue |
| 103 # for each of the user's Roles, check the permissions | |
| 99 for perm in self.role[rolename].permissions: | 104 for perm in self.role[rolename].permissions: |
| 100 if perm.klass is None or perm.klass == classname: | 105 # permission name match? |
| 101 return 1 | 106 if perm.name == permission: |
| 107 # permission klass match? | |
| 108 if perm.klass is None or perm.klass == classname: | |
| 109 # we have a winner | |
| 110 return 1 | |
| 102 return 0 | 111 return 0 |
| 103 | 112 |
| 104 def hasNodePermission(self, classname, nodeid, **propspec): | 113 def hasNodePermission(self, classname, nodeid, **propspec): |
| 105 ''' Check the named properties of the given node to see if the | 114 ''' Check the named properties of the given node to see if the |
| 106 userid appears in them. If it does, then the user is granted | 115 userid appears in them. If it does, then the user is granted |
