ucsschool.importer.models package¶
Submodules¶
ucsschool.importer.models.import_user module¶
Representation of a user read from a file.
-
class
ucsschool.importer.models.import_user.
FunctionSignature
(name, args, kwargs)¶ Bases:
tuple
Create new instance of FunctionSignature(name, args, kwargs)
-
_asdict
()¶ Return a new OrderedDict which maps field names to their values
-
_fields
= ('name', 'args', 'kwargs')¶
-
classmethod
_make
(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)¶ Make a new FunctionSignature object from a sequence or iterable
-
_replace
(_self, **kwds)¶ Return a new FunctionSignature object replacing specified fields with new values
-
args
¶ Alias for field number 1
-
kwargs
¶ Alias for field number 2
-
name
¶ Alias for field number 0
-
-
class
ucsschool.importer.models.import_user.
UsernameUniquenessTuple
(record_uid, source_uid, dn)¶ Bases:
tuple
Create new instance of UsernameUniquenessTuple(record_uid, source_uid, dn)
-
_asdict
()¶ Return a new OrderedDict which maps field names to their values
-
_fields
= ('record_uid', 'source_uid', 'dn')¶
-
classmethod
_make
(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)¶ Make a new UsernameUniquenessTuple object from a sequence or iterable
-
_replace
(_self, **kwds)¶ Return a new UsernameUniquenessTuple object replacing specified fields with new values
-
dn
¶ Alias for field number 2
-
record_uid
¶ Alias for field number 0
-
source_uid
¶ Alias for field number 1
-
-
class
ucsschool.importer.models.import_user.
ImportUser
(name=None, school=None, **kwargs)[source]¶ Bases:
ucsschool.lib.models.user.User
Representation of a user read from a file. Abstract class, please use one of its subclasses ImportStaff etc.
An import profile and a factory must have been loaded, before the class can be used. A convenience module does this:
from ucsschool.importer.utils.shell import * user = factory.make_import_user(roles)
Create ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
Parameters: -
source_uid
= <ucsschool.lib.models.attributes.SourceUID object>¶
-
record_uid
= <ucsschool.lib.models.attributes.RecordUID object>¶
-
config
= <Proxy at 0x7fe0a22b2b90 with factory <function <lambda>>>¶
-
no_overwrite_attributes
= <Proxy at 0x7fe0a22b2a70 wrapping ['mailPrimaryAddress', 'uid'] at 0x7fe0a22e0518 with factory <function <lambda>>>¶
-
_unique_ids
= defaultdict(<type 'dict'>, {})¶
-
factory
= <Proxy at 0x7fe0a22b2998 with factory <function <lambda>>>¶
-
ucr
= <Proxy at 0x7fe0a22b2950 with factory <function <lambda>>>¶
-
reader
= <Proxy at 0x7fe0a22b2908 with factory <function <lambda>>>¶
-
_username_handler_cache
= {}¶
-
_unique_email_handler_cache
= {}¶
-
_additional_props
= ('action', 'entry_count', 'udm_properties', 'input_data', 'old_user', 'in_hook', 'roles')¶
-
prop
= <univention.admin.property instance>¶
-
_all_school_names
= None¶
-
_all_usernames
= {}¶
-
_attribute_udm_names
= None¶
-
_prop_regex
= <_sre.SRE_Pattern object>¶
-
_prop_providers
= {'username': 'make_username', 'school': 'make_school', 'birthday': 'make_birthday', 'record_uid': 'make_record_uid', 'firstname': 'make_firstname', 'lastname': 'make_lastname', 'source_uid': 'make_source_uid', 'email': 'make_email', 'ucsschool_roles': 'make_ucsschool_roles', 'name': 'make_username'}¶
-
build_hook_line
(hook_time, func_name)[source]¶ Recreate original input data for hook creation.
IMPLEMENTME if the Reader class in use does not put a list with the original input text in self.input_data. return _build_hook_line() with a list as argument.
Parameters: Returns: return code of lib hooks
Return type:
-
call_hooks
(hook_time, func_name)[source]¶ Runs PyHooks, then ucs-school-libs fork hooks.
Parameters: Returns: return code of lib hooks
Return type: bool: result of a legacy hook or None if no legacy hook ran
-
call_format_hook
(prop_name, fields)[source]¶ Run format hooks.
Parameters: Returns: manipulated dictionary
Return type:
-
change_school
(school, lo)[source]¶ Change primary school of user.
Parameters: - school (str) – new OU
- connection lo (univention.admin.uldap.access) – LDAP connection object
Returns: whether the school change succeeded
Return type:
-
check_schools
(lo, additional_schools=None)[source]¶ Verify that the “school” and “schools” attributes are correct. Check is case sensitive (Bug #42456).
Parameters: - connection lo (univention.admin.uldap.access) – LDAP connection object
- additional_schools (list(str)) – list of school name to check additionally to the one in self.schools
Returns: None
Return type: Raises: UnknownSchoolName – if a school is not known
-
create
(lo, validate=True)[source]¶ Create user object.
Parameters: - connection lo (univention.admin.uldap.access) – LDAP connection object
- validate (bool) – if the users attributes should be checked by UDM
Returns: whether the object created succeeded
Return type:
-
classmethod
get_by_import_id
(connection, source_uid, record_uid, superordinate=None)[source]¶ Retrieve an ImportUser.
Parameters: - connection (univention.admin.uldap.access) – uldap object
- source_uid (str) – source DB identifier
- record_uid (str) – source record identifier
- superordinate (str) – superordinate
Returns: object of
ImportUser
subclass loaded from LDAP or raises NoObjectReturn type: Raises: ucsschool.lib.models.base.NoObject – if no user was found
-
expire
(expiry)[source]¶ Set the account expiration date. Caller must run modify().
Parameters: expiry (str) – expire date “%Y-%m-%d” or “”
-
classmethod
from_dict
(a_dict)[source]¶ Create user object from a dictionary created by to_dict().
Parameters: a_dict (dict) – dictionary created by to_dict() Returns: ImportUser instance Return type: ImportUser
-
has_purge_timestamp
(connection)[source]¶ Check if the user account has a purge timestamp set (regardless if it is in the future or past).
Parameters: connection (univention.admin.uldap.access) – uldap connection object Returns: whether the user account has a purge timestamp set Return type: bool
-
has_expired
(connection)[source]¶ Check if the user account has expired.
Parameters: connection (univention.admin.uldap.access) – uldap connection object Returns: whether the user account has expired Return type: bool
-
has_expiry
(connection)[source]¶ Check if the user account has an expiry date set (regardless if it is in the future or past).
Parameters: connection (univention.admin.uldap.access) – uldap connection object Returns: whether the user account has an expiry date set Return type: bool
-
lo
¶ LDAP connection object
Read-write cn=admin connection in a real run, read-only cn=admin connection during a dry-run.
-
prepare_all
(new_user=False)[source]¶ Necessary preparation to modify a user in UCS. Runs all make_* functions.
Parameters: new_user (bool) – if a password should be created Returns: None
-
prepare_attributes
(new_user=False)[source]¶ Run make_* functions for all Attributes of ucsschool.lib.models.user.User.
Parameters: new_user (bool) – if a password should be created Returns: None
-
prepare_udm_properties
()[source]¶ Create self.udm_properties from schemes configured in config[“scheme”]. Existing entries will be overwritten unless listed in UCRV ucsschool/import/generate/user/attributes/no-overwrite-by-schema.
- Attributes (email, record_uid, [user]name etc.) are ignored, as they are processed separately
- in make_*.
- See /usr/share/doc/ucs-school-import/user_import_configuration_readme.txt.gz section “scheme”
- for details on the configuration.
-
prepare_uids
()[source]¶ Necessary preparation to detect if user exists in UCS. Runs make_* functions for record_uid and source_uid Attributes of ImportUser.
-
make_classes
()[source]¶ Create school classes.
- This should run after make_school().
- If attribute already exists as a dict, it is not changed.
- Attribute is only written if it is set to a string like ‘school1-cls2,school3-cls4’.
-
make_email
()[source]¶ Create email from scheme (if not already set).
If any of the other attributes is used in the format scheme of the email address, its make_* function should have run before this!
-
make_school
()[source]¶ Create ‘school’ attribute - the position of the object in LDAP (if not already set).
Order of detection:
- already set (object creation or reading from input)
- from configuration (file or cmdline)
- first (alphanum-sorted) school in attribute schools
-
make_schools
()[source]¶ Create list of schools this user is in. If possible, this should run after make_school()
- If empty, it is set to self.school.
- If it is a string like ‘school1,school2,school3’ the attribute is created from it.
-
make_udm_property
(property_name)[source]¶ Create
self.udm_properties[property_name]
from scheme if not already existent.Parameters: property_name (str) – name of UDM property Returns: value read from CSV or calculated from scheme or None Return type: str or None
-
make_username
()[source]¶ Create username if not already set in self.name or self.udm_properties[“username”]. [ALWAYSCOUNTER] and [COUNTER2] are supported, but only one may be used per name.
-
classmethod
normalize
(s)[source]¶ Normalize string (german umlauts etc)
Parameters: s (str) – str to normalize Returns: normalized s Return type: str
-
reactivate
()[source]¶ Reactivate a deactivated user account, reset the account expiry setting and purge timestamp. Run this only on existing users fetched from LDAP.
-
validate
(lo, validate_unlikely_changes=False, check_username=False)[source]¶ Runs self-tests in the following order:
- check existence of mandatory_attributes
- check uniqueness of record_uid in this import job
- check uniqueness of username in this import job
- check uniqueness of email (mailPrimaryAddress) in this import job
- check that username is not empty
- check maximum username length
- check minimum password_length
- check email has valid format
- check birthday has valid format
- check school_classes is a dict
- check schools is a list
- check format of entries in school_classes
- check existence of schools in school and schools
- check that a username is not already in use by another user
Parameters: Returns: None
Raises: - MissingMandatoryAttribute –
...
- UniqueIdError –
...
- NoUsername –
...
- UsernameToLong –
...
- BadPassword –
...
- InvalidEmail –
...
- InvalidBirthday –
...
- InvalidSchoolClasses –
...
- InvalidSchools –
...
-
_check_username_uniqueness
()[source]¶ Check that
self.name
is not already in use by another user.Raises: UniqueIdError – if username is already taken by another user
-
set_purge_timestamp
(ts)[source]¶ Set the date at which the account whould be deleted by the ucs-school-purge-expired-users script. Caller must run modify().
Parameters: ts (str) – account deletion date “%Y-%m-%d” or “” Returns: None
-
role_sting
¶ Mapping from self.roles to string used in configuration.
Returns: one of staff, student, teacher, teacher_and_staff Return type: str
-
school_classes_as_str
¶ Create a string representation of the school_classes attribute.
Returns: string representation of school_classes attribute Return type: str
-
unique_email_handler
¶
-
username_handler
¶
-
username_scheme
¶ Fetch scheme for username for role.
Returns: scheme for the role from configuration Return type: str
-
solve_format_dependencies
(prop_to_format, scheme, **kwargs)[source]¶ Call make_*() methods required to create values for <properties> used in scheme.
Parameters: Returns: None
-
format_from_scheme
(prop_name, scheme, **kwargs)[source]¶ Format property with scheme for current import_user. * Uses the replacement code from users:templates. * This does not do the counter variable replacements for username. * Replacement <variables> are filled in the following oder (later additions overwriting previous ones): - from raw input data - from Attributes of self (ImportUser & ucsschool.lib.models.user.User) - from self.udm_properties - from kwargs
Parameters: Returns: formatted string
Return type:
-
_prevent_mapped_attributes_in_udm_properties
()[source]¶ Make sure users do not store values for ucsschool.lib mapped Attributes in udm_properties.
-
update
(other)[source]¶ Copy attributes of other ImportUser into this one.
IMPLEMENTME if you subclass and add attributes that are not ucsschool.lib.models.attributes.
Parameters: other (ImportUser) – data source
-
username_max_length
¶
-
classmethod
school_classes_invalid_character_replacement
(school_class, char_replacement)[source]¶ Replace disallowed characters in
school_class
withchar_replacement
. Allowed chars:[string.digits, string.ascii_letters, " -._"]
. Ifchar_replacement
is empty no replacement will be done.Parameters: Returns: (possibly modified) name of school class
Return type:
-
_attributes
= {'school': <ucsschool.lib.models.attributes.SchoolAttribute object>, 'name': <ucsschool.lib.models.attributes.Username object>, 'firstname': <ucsschool.lib.models.attributes.Firstname object>, 'lastname': <ucsschool.lib.models.attributes.Lastname object>, 'ucsschool_roles': <ucsschool.lib.models.attributes.Roles object>, 'school_classes': <ucsschool.lib.models.attributes.SchoolClassesAttribute object>, 'disabled': <ucsschool.lib.models.attributes.Disabled object>, 'birthday': <ucsschool.lib.models.attributes.Birthday object>, 'record_uid': <ucsschool.lib.models.attributes.RecordUID object>, 'schools': <ucsschool.lib.models.attributes.Schools object>, 'password': <ucsschool.lib.models.attributes.Password object>, 'source_uid': <ucsschool.lib.models.attributes.SourceUID object>, 'email': <ucsschool.lib.models.attributes.Email object>}¶
-
_meta
= <ucsschool.lib.models.meta.UCSSchoolHelperOptions object>¶
-
logger
= <Proxy at 0x7fe0a22b2878 wrapping <logging.Logger object> at 0x7fe0a2266490 with factory <function <lambda>>>¶
-
-
class
ucsschool.importer.models.import_user.
ImportStaff
(name=None, school=None, **kwargs)[source]¶ Bases:
ucsschool.importer.models.import_user.ImportUser
,ucsschool.lib.models.user.Staff
Create ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
Parameters: -
_attributes
= {'firstname': <ucsschool.lib.models.attributes.Firstname object>, 'lastname': <ucsschool.lib.models.attributes.Lastname object>, 'disabled': <ucsschool.lib.models.attributes.Disabled object>, 'birthday': <ucsschool.lib.models.attributes.Birthday object>, 'record_uid': <ucsschool.lib.models.attributes.RecordUID object>, 'schools': <ucsschool.lib.models.attributes.Schools object>, 'password': <ucsschool.lib.models.attributes.Password object>, 'source_uid': <ucsschool.lib.models.attributes.SourceUID object>, 'school': <ucsschool.lib.models.attributes.SchoolAttribute object>, 'name': <ucsschool.lib.models.attributes.Username object>, 'ucsschool_roles': <ucsschool.lib.models.attributes.Roles object>, 'school_classes': <ucsschool.lib.models.attributes.SchoolClassesAttribute object>, 'email': <ucsschool.lib.models.attributes.Email object>}¶
-
_meta
= <ucsschool.lib.models.meta.UCSSchoolHelperOptions object>¶
-
logger
= <Proxy at 0x7fe0a22b2830 wrapping <logging.Logger object> at 0x7fe0a2266490 with factory <function <lambda>>>¶
-
-
class
ucsschool.importer.models.import_user.
ImportStudent
(name=None, school=None, **kwargs)[source]¶ Bases:
ucsschool.importer.models.import_user.ImportUser
,ucsschool.lib.models.user.Student
Create ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
Parameters: -
_attributes
= {'firstname': <ucsschool.lib.models.attributes.Firstname object>, 'lastname': <ucsschool.lib.models.attributes.Lastname object>, 'disabled': <ucsschool.lib.models.attributes.Disabled object>, 'birthday': <ucsschool.lib.models.attributes.Birthday object>, 'record_uid': <ucsschool.lib.models.attributes.RecordUID object>, 'schools': <ucsschool.lib.models.attributes.Schools object>, 'password': <ucsschool.lib.models.attributes.Password object>, 'source_uid': <ucsschool.lib.models.attributes.SourceUID object>, 'school': <ucsschool.lib.models.attributes.SchoolAttribute object>, 'name': <ucsschool.lib.models.attributes.Username object>, 'ucsschool_roles': <ucsschool.lib.models.attributes.Roles object>, 'school_classes': <ucsschool.lib.models.attributes.SchoolClassesAttribute object>, 'email': <ucsschool.lib.models.attributes.Email object>}¶
-
_meta
= <ucsschool.lib.models.meta.UCSSchoolHelperOptions object>¶
-
logger
= <Proxy at 0x7fe0a22b2368 wrapping <logging.Logger object> at 0x7fe0a2266490 with factory <function <lambda>>>¶
-
-
class
ucsschool.importer.models.import_user.
ImportTeacher
(name=None, school=None, **kwargs)[source]¶ Bases:
ucsschool.importer.models.import_user.ImportUser
,ucsschool.lib.models.user.Teacher
Create ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
Parameters: -
_attributes
= {'firstname': <ucsschool.lib.models.attributes.Firstname object>, 'lastname': <ucsschool.lib.models.attributes.Lastname object>, 'disabled': <ucsschool.lib.models.attributes.Disabled object>, 'birthday': <ucsschool.lib.models.attributes.Birthday object>, 'record_uid': <ucsschool.lib.models.attributes.RecordUID object>, 'schools': <ucsschool.lib.models.attributes.Schools object>, 'password': <ucsschool.lib.models.attributes.Password object>, 'source_uid': <ucsschool.lib.models.attributes.SourceUID object>, 'school': <ucsschool.lib.models.attributes.SchoolAttribute object>, 'name': <ucsschool.lib.models.attributes.Username object>, 'ucsschool_roles': <ucsschool.lib.models.attributes.Roles object>, 'school_classes': <ucsschool.lib.models.attributes.SchoolClassesAttribute object>, 'email': <ucsschool.lib.models.attributes.Email object>}¶
-
_meta
= <ucsschool.lib.models.meta.UCSSchoolHelperOptions object>¶
-
logger
= <Proxy at 0x7fe0a22b2680 wrapping <logging.Logger object> at 0x7fe0a2266490 with factory <function <lambda>>>¶
-
-
class
ucsschool.importer.models.import_user.
ImportTeachersAndStaff
(name=None, school=None, **kwargs)[source]¶ Bases:
ucsschool.importer.models.import_user.ImportUser
,ucsschool.lib.models.user.TeachersAndStaff
Create ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
Parameters: -
_attributes
= {'firstname': <ucsschool.lib.models.attributes.Firstname object>, 'lastname': <ucsschool.lib.models.attributes.Lastname object>, 'disabled': <ucsschool.lib.models.attributes.Disabled object>, 'birthday': <ucsschool.lib.models.attributes.Birthday object>, 'record_uid': <ucsschool.lib.models.attributes.RecordUID object>, 'schools': <ucsschool.lib.models.attributes.Schools object>, 'password': <ucsschool.lib.models.attributes.Password object>, 'source_uid': <ucsschool.lib.models.attributes.SourceUID object>, 'school': <ucsschool.lib.models.attributes.SchoolAttribute object>, 'name': <ucsschool.lib.models.attributes.Username object>, 'ucsschool_roles': <ucsschool.lib.models.attributes.Roles object>, 'school_classes': <ucsschool.lib.models.attributes.SchoolClassesAttribute object>, 'email': <ucsschool.lib.models.attributes.Email object>}¶
-
_meta
= <ucsschool.lib.models.meta.UCSSchoolHelperOptions object>¶
-
logger
= <Proxy at 0x7fe0a22b27a0 wrapping <logging.Logger object> at 0x7fe0a2266490 with factory <function <lambda>>>¶
-