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:
tupleCreate new instance of FunctionSignature(name, args, kwargs)
- 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:
tupleCreate new instance of UsernameUniquenessTuple(record_uid, source_uid, dn)
- 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: str = None, school: str = None, **kwargs: str)[source]#
Bases:
UserRepresentation 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.
- factory = None#
- ucr = {}#
- prop = <univention.admin.property object>#
- build_hook_line(hook_time: str, func_name: str) str[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.
- call_hooks(hook_time: str, func_name: str, lo: LoType) None[source]#
Runs PyHooks, then ucs-school-libs fork hooks.
- Parameters:
hook_time (str) – pre or post
func_name (str) – create, modify, move or remove
lo (univention.admin.uldap.access) – LDAP connection object
- Returns:
return code of lib hooks
- check_schools(lo: LoType, additional_schools: Iterable[str] | None = None) None[source]#
Verify that the “school” and “schools” attributes are correct. Check is case sensitive (Bug #42456).
- Parameters:
- Returns:
None
- Return type:
None
- Raises:
UnknownSchoolName – if a school is not known
- create_without_hooks_roles(lo: LoType) None[source]#
Run by py:meth:create_without_hooks() before py:meth:validate() (and thus before py:meth:do_create()).
- classmethod get_by_import_id(connection: LoType, source_uid: str, record_uid: str, superordinate: str | None = None, udm_properties: Iterable | None = None) ImportUser[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
udm_properties (iterable) – list of udm attributes to load into self.udm_properties
- Returns:
object of
ImportUsersubclass loaded from LDAP or raises NoObject- Return type:
- Raises:
ucsschool.lib.models.base.NoObject – if no user was found
- expire(expiry: str) None[source]#
Set the account expiration date. Caller must run modify().
- Parameters:
expiry (str) – expire date “%Y-%m-%d” or “”
Deprecated since version 4.4: v9 Use user.self.expiration_date = expiry instead.
- classmethod from_dict(a_dict: Dict[str, Any]) ImportUser[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:
- has_purge_timestamp(connection: LoType) bool[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:
- has_expired(connection: LoType) bool[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:
- has_expiry(connection: LoType) bool[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:
- property reader#
- property lo: LoType#
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: bool | None = False) None[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: bool | None = False) None[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() None[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() None[source]#
Necessary preparation to detect if user exists in UCS. Runs make_* functions for record_uid and source_uid Attributes of ImportUser.
- make_classes() Dict[str, Dict[str, List[str]]][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() str[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() str[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() List[str][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: str) str | None[source]#
Create
self.udm_properties[property_name]from scheme if not already existent.
- make_username() str[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.
- modify(lo: LoType, validate: bool | None = True, move_if_necessary: bool | None = None) bool[source]#
Modifies an existing UDM instance. Calls pre-hooks. If the object does not exist, returns False. If the object exists, modifies it, returns True and calls post-hooks.
- modify_without_hooks(lo: LoType, validate: bool | None = True, move_if_necessary: bool | None = None) bool[source]#
- reactivate() None[source]#
Reactivate a deactivated user account, reset the account expiry setting and purge timestamp. Run this only on existing users fetched from LDAP.
- remove(lo: LoType) bool[source]#
Removes an existing UDM instance. Calls pre-hooks. If the object does not exist, returns False. If the object exists, removes it, returns True and calls post-hooks.
- validate()[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:
…
…
…
…
…
…
…
…
…
- set_purge_timestamp(ts: str) None[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
- property role_sting: str#
Mapping from self.roles to string used in configuration.
- Returns:
one of staff, student, teacher, teacher_and_staff
- Return type:
- property school_classes_as_str: str#
Create a string representation of the school_classes attribute.
- Returns:
string representation of school_classes attribute
- Return type:
- property unique_email_handler: UsernameHandler#
- property username_handler: UsernameHandler#
- property username_scheme: str#
Fetch scheme for username for role.
- Returns:
scheme for the role from configuration
- Return type:
- solve_format_dependencies(prop_to_format: str, scheme: str, **kwargs: str) None[source]#
Call make_*() methods required to create values for <properties> used in scheme.
- format_from_scheme(prop_name: str, scheme: str, **kwargs: str) str[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
- classmethod get_class_for_udm_obj(udm_obj: UdmObjectType, school: str) None | Type['ImportUser'][source]#
IMPLEMENTME if you subclass!
- to_dict() Dict[str, Any][source]#
Returns a dictionary somewhat representing this instance. This dictionary is usually used when sending the instance to a browser as JSON. By default the attributes are present as well as the dn and the udm_module.
- update(other: ImportUser) None[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
- classmethod school_classes_invalid_character_replacement(school_class: str, char_replacement: str) str[source]#
Replace disallowed characters in
school_classwithchar_replacement. Allowed chars:[string.digits, string.ascii_letters, " -._"]. Ifchar_replacementis empty no replacement will be done.
- logger = <Proxy at 0x7f6d6ffe2e00 wrapping <Logger ucsschool.importer.models.import_user (INFO)> at 0x7f6d6f7a1a10 with factory <function UCSSchoolHelperMetaClass.__new__.<locals>.<lambda>>>#
- class ucsschool.importer.models.import_user.ImportStaff(name: str = None, school: str = None, **kwargs: str)[source]#
Bases:
ImportUser,StaffCreate ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
- logger = <Proxy at 0x7f6d6fd92c00 wrapping <Logger ucsschool.importer.models.import_user (INFO)> at 0x7f6d6f7a1a10 with factory <function UCSSchoolHelperMetaClass.__new__.<locals>.<lambda>>>#
- class ucsschool.importer.models.import_user.ImportStudent(name: str = None, school: str = None, **kwargs: str)[source]#
Bases:
ImportUser,StudentCreate ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
- logger = <Proxy at 0x7f6d6fd91780 wrapping <Logger ucsschool.importer.models.import_user (INFO)> at 0x7f6d6f7a1a10 with factory <function UCSSchoolHelperMetaClass.__new__.<locals>.<lambda>>>#
- class ucsschool.importer.models.import_user.ImportTeacher(name: str = None, school: str = None, **kwargs: str)[source]#
Bases:
ImportUser,TeacherCreate ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
- logger = <Proxy at 0x7f6d6fd92000 wrapping <Logger ucsschool.importer.models.import_user (INFO)> at 0x7f6d6f7a1a10 with factory <function UCSSchoolHelperMetaClass.__new__.<locals>.<lambda>>>#
- class ucsschool.importer.models.import_user.ImportTeachersAndStaff(name: str = None, school: str = None, **kwargs: str)[source]#
Bases:
ImportUser,TeachersAndStaffCreate ImportUser object (neither saved nor loaded from LDAP yet). The dn attribute is calculated.
- logger = <Proxy at 0x7f6d6fd91b80 wrapping <Logger ucsschool.importer.models.import_user (INFO)> at 0x7f6d6f7a1a10 with factory <function UCSSchoolHelperMetaClass.__new__.<locals>.<lambda>>>#