- Timestamp:
- 13 Jul 2012, 16:17:44 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8995 r9001 184 184 185 185 # Update password 186 # XXX: Tale DELETION_MARKER into consideration 186 187 if row.has_key('password'): 187 188 passwd = row.get('password', IGNORE_MARKER) -
main/waeup.kofa/trunk/src/waeup/kofa/university/batching.py
r8996 r9001 30 30 from zope.catalog.interfaces import ICatalog 31 31 from zope.event import notify 32 from zope.securitypolicy.interfaces import IPrincipalRoleManager 32 from zope.securitypolicy.interfaces import ( 33 IPrincipalRoleManager, IPrincipalRoleMap) 33 34 from waeup.kofa.authentication import LocalRoleSetEvent 34 from waeup.kofa.interfaces import IBatchProcessor, IGNORE_MARKER, FatalCSVError 35 from waeup.kofa.interfaces import ( 36 IBatchProcessor, IGNORE_MARKER, DELETION_MARKER, FatalCSVError) 35 37 from waeup.kofa.university.interfaces import ( 36 38 IFacultiesContainer, IFaculty, ICourse, IDepartment, ICertificate, … … 95 97 items_changed = '' 96 98 97 if row.has_key('local_roles'): 98 local_roles = eval(row['local_roles']) 99 for rolemap in local_roles: 100 user = rolemap['user_name'] 101 local_role = rolemap['local_role'] 102 role_manager = IPrincipalRoleManager(obj) 103 role_manager.assignRoleToPrincipal(local_role, user) 104 notify(LocalRoleSetEvent(obj, local_role, user, granted=True)) 105 items_changed += ( 106 '%s=%s, ' % ('local_roles', '%s|%s' % (user,local_role))) 99 if row.has_key('local_roles') and row['local_roles'] not in ( 100 None, IGNORE_MARKER): 101 role_manager = IPrincipalRoleManager(obj) 102 role_map = IPrincipalRoleMap(obj) 103 # Remove all existing local roles. 104 for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): 105 role_manager.unsetRoleForPrincipal(local_role, user_name) 106 notify(LocalRoleSetEvent( 107 obj, local_role, user_name, granted=False)) 108 # Add new local roles. 109 if row['local_roles'] != DELETION_MARKER: 110 local_roles = eval(row['local_roles']) 111 for rolemap in local_roles: 112 user = rolemap['user_name'] 113 local_role = rolemap['local_role'] 114 role_manager.assignRoleToPrincipal(local_role, user) 115 notify(LocalRoleSetEvent(obj, local_role, user, granted=True)) 116 items_changed += ( 117 '%s=%s, ' % ('local_roles', '%s|%s' % (user,local_role))) 107 118 row.pop('local_roles') 108 119 … … 122 133 FacultyProcessor, self).checkConversion(row, mode=mode) 123 134 if row.has_key('local_roles'): 135 if row['local_roles'] in (None, DELETION_MARKER, IGNORE_MARKER): 136 return errs, inv_errs, conv_dict 124 137 try: 125 138 local_roles = eval(row['local_roles']) -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r9000 r9001 24 24 from zope.component.hooks import setSite, clearSite 25 25 from zope.component import createObject 26 from zope.securitypolicy.interfaces import IPrincipalRoleMap 26 from zope.securitypolicy.interfaces import ( 27 IPrincipalRoleMap, IPrincipalRoleManager) 27 28 from zope.interface.verify import verifyClass, verifyObject 28 29 from waeup.kofa.interfaces import IBatchProcessor … … 42 43 43 44 FACULTY_HEADER_FIELDS = FACULTY_SAMPLE_DATA.split( 45 '\n')[0].split(',') 46 47 FACULTY_SAMPLE_DATA_UPDATE = open( 48 os.path.join(os.path.dirname(__file__), 'sample_faculty_data_update.csv'), 49 'rb').read() 50 51 FACULTY_HEADER_FIELDS_UPDATE = FACULTY_SAMPLE_DATA_UPDATE.split( 44 52 '\n')[0].split(',') 45 53 … … 108 116 self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv') 109 117 open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA) 118 self.csv_file_faculty_update = os.path.join(self.workdir, 'sample_faculty_data_update.csv') 119 open(self.csv_file_faculty_update, 'wb').write(FACULTY_SAMPLE_DATA_UPDATE) 110 120 return 111 121 … … 214 224 self.assertEqual(user_name, 'bob') 215 225 self.assertEqual(local_role, 'waeup.local.DepartmentManager') 226 shutil.rmtree(os.path.dirname(fin_file)) 227 return 228 229 def test_import_update(self): 230 self.app['faculties']['FAC2'] = Faculty(code='FAC2') 231 self.app['faculties']['FAC3'] = Faculty(code='FAC3') 232 self.app['faculties']['FAC4'] = Faculty(code='FAC4') 233 234 role_manager1 = IPrincipalRoleManager(self.app['faculties']['FAC1']) 235 role_manager1.assignRoleToPrincipal('alfonsrole', 'alfons') 236 role_map1 = IPrincipalRoleMap(self.app['faculties']['FAC1']) 237 self.assertEqual(len(role_map1.getPrincipalsAndRoles()), 1) 238 239 role_manager2 = IPrincipalRoleManager(self.app['faculties']['FAC2']) 240 role_manager2.assignRoleToPrincipal('alfonsrole', 'alfons') 241 role_map2 = IPrincipalRoleMap(self.app['faculties']['FAC2']) 242 self.assertEqual(len(role_map2.getPrincipalsAndRoles()), 1) 243 244 role_manager3 = IPrincipalRoleManager(self.app['faculties']['FAC3']) 245 role_manager3.assignRoleToPrincipal('alfonsrole', 'alfons') 246 role_map3 = IPrincipalRoleMap(self.app['faculties']['FAC3']) 247 self.assertEqual(len(role_map3.getPrincipalsAndRoles()), 1) 248 249 role_manager4 = IPrincipalRoleManager(self.app['faculties']['FAC4']) 250 role_manager4.assignRoleToPrincipal('alfonsrole', 'alfons') 251 role_map4 = IPrincipalRoleMap(self.app['faculties']['FAC4']) 252 self.assertEqual(len(role_map4.getPrincipalsAndRoles()), 1) 253 254 local_role, user_name, setting = role_map2.getPrincipalsAndRoles()[0] 255 self.assertEqual(user_name, 'alfons') 256 self.assertEqual(local_role, 'alfonsrole') 257 258 num, num_warns, fin_file, fail_file = self.proc.doImport( 259 self.csv_file_faculty_update, FACULTY_HEADER_FIELDS_UPDATE, 'update') 260 self.assertEqual(num_warns,0) 261 # Local roles have been removed in FAC1 due to deletion marker. 262 self.assertEqual(len(role_map1.getPrincipalsAndRoles()), 0) 263 # Old local roles have been removed and new roles have been added in FAC2. 264 self.assertEqual(len(role_map2.getPrincipalsAndRoles()), 1) 265 local_role, user_name, setting = role_map2.getPrincipalsAndRoles()[0] 266 self.assertEqual(user_name, 'bob') 267 self.assertEqual(local_role, 'waeup.local.DepartmentManager') 268 # Local roles are not touched in FAC3 due to ignore marker. 269 self.assertEqual(len(role_map3.getPrincipalsAndRoles()), 1) 270 local_role, user_name, setting = role_map3.getPrincipalsAndRoles()[0] 271 self.assertEqual(user_name, 'alfons') 272 self.assertEqual(local_role, 'alfonsrole') 273 # Local roles are not touched in FAC4 due to empty cell. 274 self.assertEqual(len(role_map4.getPrincipalsAndRoles()), 1) 275 local_role, user_name, setting = role_map4.getPrincipalsAndRoles()[0] 276 self.assertEqual(user_name, 'alfons') 277 self.assertEqual(local_role, 'alfonsrole') 216 278 shutil.rmtree(os.path.dirname(fin_file)) 217 279 return
Note: See TracChangeset for help on using the changeset viewer.