|
Lines 36-42
import datetime
Link Here
|
| 36 |
from collections import defaultdict |
36 |
from collections import defaultdict |
| 37 |
from ldap.filter import filter_format |
37 |
from ldap.filter import filter_format |
| 38 |
|
38 |
|
| 39 |
from univention.admin.uexceptions import noObject |
39 |
from univention.admin.uexceptions import noObject, noProperty, valueError, valueInvalidSyntax |
| 40 |
from univention.admin import property as uadmin_property |
40 |
from univention.admin import property as uadmin_property |
| 41 |
from ucsschool.lib.roles import role_pupil, role_teacher, role_staff |
41 |
from ucsschool.lib.roles import role_pupil, role_teacher, role_staff |
| 42 |
from ucsschool.lib.models import Staff, Student, Teacher, TeachersAndStaff, User |
42 |
from ucsschool.lib.models import Staff, Student, Teacher, TeachersAndStaff, User |
|
Lines 147-159
class ImportUser(User):
Link Here
|
| 147 |
self.logger.warn("Running create() from within a hook.") |
147 |
self.logger.warn("Running create() from within a hook.") |
| 148 |
return self.create_without_hooks(lo, validate) |
148 |
return self.create_without_hooks(lo, validate) |
| 149 |
else: |
149 |
else: |
|
|
150 |
self._check_consistency() |
| 150 |
return super(ImportUser, self).create(lo, validate) |
151 |
return super(ImportUser, self).create(lo, validate) |
| 151 |
|
152 |
|
| 152 |
def create_without_hooks(self, lo, validate): |
|
|
| 153 |
success = super(ImportUser, self).create_without_hooks(lo, validate) |
| 154 |
self.store_udm_properties(lo) |
| 155 |
return success |
| 156 |
|
| 157 |
@classmethod |
153 |
@classmethod |
| 158 |
def get_by_import_id(cls, connection, source_uid, record_uid, superordinate=None): |
154 |
def get_by_import_id(cls, connection, source_uid, record_uid, superordinate=None): |
| 159 |
""" |
155 |
""" |
|
Lines 191-196
class ImportUser(User):
Link Here
|
| 191 |
if self._userexpiry is not None: |
187 |
if self._userexpiry is not None: |
| 192 |
udm_obj["userexpiry"] = self._userexpiry |
188 |
udm_obj["userexpiry"] = self._userexpiry |
| 193 |
|
189 |
|
|
|
190 |
for property_, value in (self.udm_properties or {}).items(): |
| 191 |
try: |
| 192 |
udm_obj[property_] = value |
| 193 |
except (KeyError, noProperty) as exc: |
| 194 |
raise UnknownProperty("UDM properties could not be set. Unknown property: '{}'".format(exc), |
| 195 |
entry=self.entry_count, import_user=self) |
| 196 |
except (valueError, valueInvalidSyntax) as exc: |
| 197 |
raise # TODO: maybe another importer subclass? |
| 198 |
|
| 194 |
def has_expired(self, connection): |
199 |
def has_expired(self, connection): |
| 195 |
""" |
200 |
""" |
| 196 |
Check if the user account has expired. |
201 |
Check if the user account has expired. |
|
Lines 492-507
class ImportUser(User):
Link Here
|
| 492 |
return super(ImportUser, self).modify(lo, validate, move_if_necessary) |
497 |
return super(ImportUser, self).modify(lo, validate, move_if_necessary) |
| 493 |
|
498 |
|
| 494 |
def modify_without_hooks(self, lo, validate=True, move_if_necessary=None): |
499 |
def modify_without_hooks(self, lo, validate=True, move_if_necessary=None): |
| 495 |
# must set udm_properties first, as they contain overridePWHistory and |
500 |
self._check_consistency() |
| 496 |
# overridePWLength |
|
|
| 497 |
self.store_udm_properties(lo) |
| 498 |
if not self.school_classes: |
501 |
if not self.school_classes: |
| 499 |
# empty classes input means: don't change existing classes (Bug #42288) |
502 |
# empty classes input means: don't change existing classes (Bug #42288) |
| 500 |
self.logger.debug("No school_classes are set, not modifying existing ones.") |
503 |
self.logger.debug("No school_classes are set, not modifying existing ones.") |
| 501 |
udm_obj = self.get_udm_object(lo) |
504 |
udm_obj = self.get_udm_object(lo) |
| 502 |
self.school_classes = self.get_school_classes(udm_obj, self) |
505 |
self.school_classes = self.get_school_classes(udm_obj, self) |
| 503 |
success = super(ImportUser, self).modify_without_hooks(lo, validate, move_if_necessary) |
506 |
return super(ImportUser, self).modify_without_hooks(lo, validate, move_if_necessary) |
| 504 |
return success |
|
|
| 505 |
|
507 |
|
| 506 |
def move(self, lo, udm_obj=None, force=False): |
508 |
def move(self, lo, udm_obj=None, force=False): |
| 507 |
self._lo = lo |
509 |
self._lo = lo |
|
Lines 728-741
class ImportUser(User):
Link Here
|
| 728 |
for meth_name, meths in self._pyhook_cache.items()])) |
730 |
for meth_name, meths in self._pyhook_cache.items()])) |
| 729 |
return pyhooks |
731 |
return pyhooks |
| 730 |
|
732 |
|
| 731 |
def store_udm_properties(self, connection): |
733 |
def _check_consistency(self): |
| 732 |
""" |
|
|
| 733 |
Copy data from self.udm_properties into UDM object of this user. |
| 734 |
|
| 735 |
:param connection: LDAP connection |
| 736 |
""" |
| 737 |
if not self.udm_properties: |
734 |
if not self.udm_properties: |
| 738 |
return |
735 |
return |
|
|
736 |
|
| 739 |
forbidden_attributes = {"birthday", "disabled", "firstname", "lastname", |
737 |
forbidden_attributes = {"birthday", "disabled", "firstname", "lastname", |
| 740 |
"mailPrimaryAddress", "name", "password", "school", "schools", "school_classes", "sn", "uid", "username"} |
738 |
"mailPrimaryAddress", "name", "password", "school", "schools", "school_classes", "sn", "uid", "username"} |
| 741 |
bad_props = set(self.udm_properties.keys()).intersection(forbidden_attributes) |
739 |
bad_props = set(self.udm_properties.keys()).intersection(forbidden_attributes) |
|
Lines 747-760
class ImportUser(User):
Link Here
|
| 747 |
"address is strored in the 'email' attribute of the {} object (not in udm_properties).".format( |
745 |
"address is strored in the 'email' attribute of the {} object (not in udm_properties).".format( |
| 748 |
self.__class__.__name__)) |
746 |
self.__class__.__name__)) |
| 749 |
|
747 |
|
| 750 |
udm_obj = self.get_udm_object(connection) |
|
|
| 751 |
udm_obj.info.update(self.udm_properties) |
| 752 |
try: |
| 753 |
udm_obj.modify() |
| 754 |
except KeyError as exc: |
| 755 |
raise UnknownProperty("UDM properties could not be set. Unknown property: '{}'".format(exc), |
| 756 |
entry=self.entry_count, import_user=self) |
| 757 |
|
| 758 |
def update(self, other): |
748 |
def update(self, other): |
| 759 |
""" |
749 |
""" |
| 760 |
Copy attributes of other ImportUser into this one. |
750 |
Copy attributes of other ImportUser into this one. |