comparison roundup/security.py @ 5128:4058fc1ec746

replacing depricated has_key references by in to support python 3. Errors reported by python -3 roundup_server. Unit tests test_config test_security pass although test_config is a bit weak in coverage.
author John Rouillard <rouilj@ieee.org>
date Mon, 04 Jul 2016 15:14:54 -0400
parents 425b4c4fc345
children 36630a062fb5
comparison
equal deleted inserted replaced
5127:425b4c4fc345 5128:4058fc1ec746
142 ''' Find the Permission matching the name and for the class, if the 142 ''' Find the Permission matching the name and for the class, if the
143 classname is specified. 143 classname is specified.
144 144
145 Raise ValueError if there is no exact match. 145 Raise ValueError if there is no exact match.
146 ''' 146 '''
147 if not self.permission.has_key(permission): 147 if permission not in self.permission:
148 raise ValueError, 'No permission "%s" defined'%permission 148 raise ValueError, 'No permission "%s" defined'%permission
149 149
150 if classname: 150 if classname:
151 try: 151 try:
152 self.db.getclass(classname) 152 self.db.getclass(classname)
185 Permission.test() method. 185 Permission.test() method.
186 ''' 186 '''
187 if itemid and classname is None: 187 if itemid and classname is None:
188 raise ValueError, 'classname must accompany itemid' 188 raise ValueError, 'classname must accompany itemid'
189 for rolename in self.db.user.get_roles(userid): 189 for rolename in self.db.user.get_roles(userid):
190 if not rolename or not self.role.has_key(rolename): 190 if not rolename or (rolename not in self.role):
191 continue 191 continue
192 # for each of the user's Roles, check the permissions 192 # for each of the user's Roles, check the permissions
193 for perm in self.role[rolename].permissions: 193 for perm in self.role[rolename].permissions:
194 # permission match? 194 # permission match?
195 if perm.test(self.db, permission, classname, property, 195 if perm.test(self.db, permission, classname, property,
267 Concerning property, the Permission matched must have 267 Concerning property, the Permission matched must have
268 either no properties listed or the property must appear in 268 either no properties listed or the property must appear in
269 the list. 269 the list.
270 ''' 270 '''
271 roles = [r for r in self.db.user.get_roles(userid) 271 roles = [r for r in self.db.user.get_roles(userid)
272 if r and self.role.has_key(r)] 272 if r and (r in self.role)]
273 return self.roleHasSearchPermission (classname, property, *roles) 273 return self.roleHasSearchPermission (classname, property, *roles)
274 274
275 def addPermission(self, **propspec): 275 def addPermission(self, **propspec):
276 ''' Create a new Permission with the properties defined in 276 ''' Create a new Permission with the properties defined in
277 'propspec'. See the Permission class for the possible 277 'propspec'. See the Permission class for the possible

Roundup Issue Tracker: http://roundup-tracker.org/