ucsschool.importer.mass_import package#
Submodules#
ucsschool.importer.mass_import.mass_import module#
Default mass import class.
- class ucsschool.importer.mass_import.mass_import.MassImport(dry_run: bool | None = True)[source]#
Bases:
objectCreate/modify/delete all objects from the input.
Currently only implemented for users.
- Parameters:
dry_run (bool) – set to False to actually commit changes to LDAP
- pyhooks_base_path = '/usr/share/ucs-school-import/pyhooks'#
ucsschool.importer.mass_import.sisopi_user_import module#
Single source database, partial import user import class.
- class ucsschool.importer.mass_import.sisopi_user_import.SingleSourcePartialUserImport(dry_run=True)[source]#
Bases:
UserImportCurrently used by MassImport like this:
read_input()
detect_users_to_delete()
delete_users()
create_and_modify_users()
log_stats()
get_result_data()
In the SingleSourcePartialImport scenario the following is done:
Deletion: if a user is a member of the school being imported and is not part of the import data set, then only this school is removed from its
schoolsattribute. If it was the last school, then the limbo school is added, and thus user object is moved there. A user never gets truly deleted in this scenario.Creation: if a user is to be created, then first a search is done if it exists in any school (including the limbo school). If if exists somewhere, the school being imported is added to its
schoolsattribute. If it was the limbo school, it’s removed from it and thus moved from it to the school being imported. A new user object is only created, if it doesn’t exist anywhere in the domain.
- Parameters:
dry_run (bool) – set to False to actually commit changes to LDAP
- prepare_imported_user(imported_user: ImportUser, old_user: ImportUser | None) ImportUser[source]#
Prepare attributes of
imported_userobject. Optionally save existing user (old_user) object reference inimported_user.old_user. Setsimported_user.actionaccording tois_new_user.In case of SingleSourcePartialImport, when a user exists:
when user is in limbo OU: move to new school
when user is any other OU: keep old
schooland add new school toschools
- Parameters:
imported_user (ImportUser) – object to prepare attributes of
old_user (ImportUser or None) – imported_user equivalent already existing in LDAP or None
- Returns:
ImportUser object with attributes prepared
- Return type:
- get_existing_users_search_filter()[source]#
Create LDAP filter with which to find existing users.
In the case of SingleSourcePartialImport, we look at:
user.source_uid == config[source_uid] && config[school] in user.schools
- Returns:
LDAP filter
- Return type:
- do_delete(user)[source]#
Delete or deactivate a user.
In the case of SingleSourcePartialImport:
if member of multiple schools, only remove from school being imported
if member of only one school (the one being imported), deactivate immediately and move to limbo school
- Parameters:
user (ImportUser) – user to be deleted
- Returns:
whether the deletion worked
- Return type:
ucsschool.importer.mass_import.user_import module#
Default user import class.
- class ucsschool.importer.mass_import.user_import.UserImport(dry_run=True)[source]#
Bases:
objectCurrently used by MassImport like this:
read_input()
detect_users_to_delete()
delete_users()
create_and_modify_users()
log_stats()
get_result_data()
- Parameters:
dry_run (bool) – set to False to actually commit changes to LDAP
- read_input() List[ImportUser][source]#
Read users from input data.
UcsSchoolImportErrorsare stored in in self.errors (with input entry number inerror.entry_count).
- Returns:
ImportUsers found in input
- Return type:
- create_and_modify_users(imported_users: List[ImportUser]) Tuple[List[UcsSchoolImportError], Dict[str, List[Dict[str, Any]]], Dict[str, List[Dict[str, Any]]]][source]#
Create and modify users.
- self.added_users and self.modified_users will hold created / modified
ImportUserobjects.
UcsSchoolImportErrorsare stored in self.errors (with failedImportUserobjects in error.import_user).
- find_importuser_in_ldap(import_user: ImportUser) ImportUser[source]#
Fetch fresh
ImportUserobject from LDAP.- Parameters:
import_user (ImportUser) – ImportUser object to use as reference for search
- Returns:
fresh ImportUser object
- Return type:
- Raises:
NoObject – if ImportUser cannot be found
WrongUserType – if the user in LDAP is not of the same type as the import_user object
- prepare_imported_user(imported_user: ImportUser, old_user: ImportUser | None) ImportUser[source]#
Prepare attributes of
imported_userobject. Optionally save existing user (old_user) object reference inimported_user.old_user. Setsimported_user.actionaccording tois_new_user.- Parameters:
imported_user (ImportUser) – object to prepare attributes of
old_user (ImportUser or None) – imported_user equivalent already existing in LDAP or None
- Returns:
ImportUser object with attributes prepared
- Return type:
- determine_add_modify_action(imported_user: ImportUser) ImportUser[source]#
Determine what to do with the ImportUser. Should set attribute action to either A or M. If set to M the returned user must be a opened
ImportUserfrom LDAP.Run modify preparations here, like school-move etc.
- Parameters:
imported_user (ImportUser) – ImportUser from input
- Returns:
ImportUser with action set and possibly fetched from LDAP
- Return type:
- Raises:
WrongUserType – if the user in LDAP is not of the same type as the import_user object
- get_existing_users_search_filter() str[source]#
Create LDAP filter with which to find existing users.
In the case of the default UserImport, we look at: user.source_uid == config[source_uid]
- Returns:
LDAP filter
- Return type:
- detect_users_to_delete() List[Tuple[str, str, List[str]]][source]#
Find difference between source database and UCS user database.
- delete_users(users: List[Tuple[str, str, List[str]]] | None = None) Tuple[List[UcsSchoolImportError], Dict[str, List[Dict[str, Any]]]][source]#
Delete users.
detect_users_to_delete()should have run before this.self.deleted_users will hold objects of deleted
ImportUser.UcsSchoolImportErrorsare stored in self.errors (with failedImportUserobject in error.import_user).
To add or change a deletion strategy overwrite
do_delete().
- Parameters:
users (
list()) –list()of tuples: [(source_uid, record_uid, input_data), ..]- Returns:
(self.errors, self.deleted_users)
- Return type:
- school_move(imported_user: ImportUser, user: ImportUser) ImportUser[source]#
Change users primary school.
- Parameters:
imported_user (ImportUser) – User from input with target school
user (ImportUser) – existing User with old school
- Returns:
user in new position, freshly fetched from LDAP
- Return type:
- do_school_move(imported_user: ImportUser, user: ImportUser) ImportUser[source]#
Change users primary school -
school_move()without calling Python hooks (ucsschool lib calls executables anyway).- Parameters:
imported_user (ImportUser) – User from input with target school
user (ImportUser) – existing User with old school
- Returns:
user in new position, freshly fetched from LDAP
- Return type:
- do_delete(user: ImportUser) bool[source]#
Delete or deactivate a user.
IMPLEMENTME to add or change a deletion variant.
- Parameters:
user (ImportUser) – user to be deleted
- Returns:
whether the deletion worked
- Return type:
- deactivate_user_now(user: ImportUser) bool[source]#
Deactivate the user. Does not run user.modify().
- Parameters:
user (ImportUser) – user to deactivate when
modidy()is run- Returns:
whether any changes were made to the object and
user.modify()is required- Return type:
- delete_user_now(user: ImportUser) bool[source]#
Truly delete the user.
- Parameters:
user (ImportUser) – object to delete
- Returns:
return value from the ucsschool.lib.model remove() call
- Return type:
- set_deactivation_grace(user: ImportUser, grace: int) bool[source]#
Sets the account expiration date (UDM attribute userexpiry) on the user object. Does not run
user.modify().- Parameters:
user (ImportUser) – object to delete
grace (int) – days until deactivation
- Returns:
whether any changes were made to the object and user.modify() is required
- Return type:
- set_deletion_grace(user: ImportUser, grace: int) bool[source]#
Sets the account deletion timestamp (UDM attribute ucsschoolPurgeTimestamp) on the user object. Does not run
user.modify().- Parameters:
user (ImportUser) – user to schedule the deletion for
grace (int) – days until deletion
- Returns:
whether any changes were made to the object and user.modify() is required
- Return type:
- get_result_data() UserImportData[source]#
- class ucsschool.importer.mass_import.user_import.UserImportData(user_import: UserImport)[source]#
Bases:
object