|
Lines 253-297
class User(UCSSchoolHelperAbstractClass):
Link Here
|
| 253 |
self.password = old_password |
253 |
self.password = old_password |
| 254 |
return success |
254 |
return success |
| 255 |
|
255 |
|
| 256 |
def do_modify(self, udm_obj, lo): |
256 |
def do_modify(self, udm_obj, lo): |
| 257 |
self.create_mail_domain(lo) |
257 |
self.create_mail_domain(lo) |
| 258 |
self.password = self.password or None |
258 |
self.password = self.password or None |
| 259 |
mandatory_groups = self.groups_used(lo) |
259 |
mandatory_groups = self.groups_used(lo) |
| 260 |
for group_dn in udm_obj['groups'][:]: |
260 |
for group_dn in udm_obj['groups'][:]: |
| 261 |
# User might have been removed from school(s), remove class |
261 |
logger.debug('Checking group %s for removal', group_dn) |
| 262 |
# and workgroup memberships for those. Leave other group types |
262 |
if group_dn not in mandatory_groups: |
| 263 |
# (e.g. global groups) untouched. |
263 |
logger.debug('Group not mandatory! Part of a school?') |
| 264 |
logger.debug('Checking group %s for removal', group_dn) |
264 |
try: |
| 265 |
if group_dn not in mandatory_groups: |
265 |
school_class = SchoolClass.from_dn(group_dn, None, lo) |
| 266 |
logger.debug('Group not mandatory! Part of a school?') |
266 |
except noObject: |
| 267 |
try: |
267 |
logger.debug('No. Leaving it alone...') |
| 268 |
school_group = Group.from_dn(group_dn, None, lo) |
268 |
continue |
| 269 |
except noObject: |
269 |
logger.debug('Yes, part of %s!', school_class.school) |
| 270 |
logger.debug('No. Leaving it alone...') |
270 |
if school_class.school not in self.school_classes: |
| 271 |
continue |
271 |
continue # if the key isn't set we don't change anything to the groups. to remove the groups it has to be an empty list |
| 272 |
# Bug 41907: |
272 |
classes = self.school_classes[school_class.school] |
| 273 |
# SchoolClass.from_dn does not throw WrongModel if no class or workgroup. |
273 |
remove = school_class.name not in classes and school_class.get_relative_name() not in classes |
| 274 |
# But self_is_class() and self_is_workgroup() return correct values. |
274 |
if remove: |
| 275 |
if school_group.self_is_class(): |
275 |
logger.debug('Removing it!') |
| 276 |
classes = self.school_classes.get(school_group.school, []) |
276 |
udm_obj['groups'].remove(group_dn) |
| 277 |
remove = school_group.name not in classes and school_group.get_relative_name() not in classes |
277 |
else: |
| 278 |
elif school_group.self_is_workgroup(): |
278 |
logger.debug('Leaving it alone: Part of own school and either non-school class or new school classes were not defined at all') |
| 279 |
remove = school_group.school not in self.schools |
279 |
for group_dn in mandatory_groups: |
| 280 |
else: |
280 |
logger.debug('Checking group %s for adding', group_dn) |
| 281 |
logger.debug('Group is no school class or workgroup. Leave it untouched.') |
281 |
if group_dn not in udm_obj['groups']: |
| 282 |
continue |
282 |
logger.debug('Group is not yet part of the user. Adding...') |
| 283 |
logger.debug('Yes, part of %s!', school_group.school) |
283 |
udm_obj['groups'].append(group_dn) |
| 284 |
if remove: |
284 |
return super(User, self).do_modify(udm_obj, lo) |
| 285 |
logger.debug('Removing it!') |
|
|
| 286 |
udm_obj['groups'].remove(group_dn) |
| 287 |
else: |
| 288 |
logger.debug('Leaving it alone: Part of own school and either non-school class or new school classes were not defined at all.') |
| 289 |
for group_dn in mandatory_groups: |
| 290 |
logger.debug('Checking group %s for adding', group_dn) |
| 291 |
if group_dn not in udm_obj['groups']: |
| 292 |
logger.debug('Group is not yet part of the user. Adding...') |
| 293 |
udm_obj['groups'].append(group_dn) |
| 294 |
return super(User, self).do_modify(udm_obj, lo) |
| 295 |
|
285 |
|
| 296 |
def do_school_change(self, udm_obj, lo, old_school): |
286 |
def do_school_change(self, udm_obj, lo, old_school): |
| 297 |
super(User, self).do_school_change(udm_obj, lo, old_school) |
287 |
super(User, self).do_school_change(udm_obj, lo, old_school) |