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:
  • name (str) – username
  • school (str) – OU
  • kwargs – attributes to set on user object
source_uid = <ucsschool.lib.models.attributes.SourceUID object>
record_uid = <ucsschool.lib.models.attributes.RecordUID object>
config = <Proxy at 0x7f2431008320 with factory <function <lambda>>>
no_overwrite_attributes = <Proxy at 0x7f2431008b00 wrapping ['mailPrimaryAddress', 'uid'] at 0x7f2430fffe18 with factory <function <lambda>>>
_unique_ids = defaultdict(<type 'dict'>, {})
factory = <Proxy at 0x7f2431008908 with factory <function <lambda>>>
ucr = <Proxy at 0x7f24310088c0 with factory <function <lambda>>>
reader = <Proxy at 0x7f24310083f8 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:
  • hook_time (str) – pre or post
  • func_name (str) – create, modify, move or remove
Returns:

return code of lib hooks

Return type:

int

static _pyhook_supports_dry_run(kls)[source]
call_hooks(hook_time, func_name)[source]

Runs PyHooks, then ucs-school-libs fork hooks.

Parameters:
  • hook_time (str) – pre or post
  • func_name (str) – create, modify, move or remove
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:
  • prop_name (str) – the property for format
  • fields (dict) – dictionary to manipulate in hook, will be used later to format the property
Returns:

manipulated dictionary

Return type:

dict

change_school(school, lo)[source]

Change primary school of user.

Parameters:
Returns:

whether the school change succeeded

Return type:

bool

classmethod _unique_ids_replace_dn(old_dn, new_dn)[source]

Change a DN in unique_ids store.

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:

None

Raises:

UnknownSchoolName – if a school is not known

create(lo, validate=True)[source]

Create user object.

Parameters:
Returns:

whether the object created succeeded

Return type:

bool

create_without_hooks_roles(lo)[source]
classmethod get_ldap_filter_for_user_role()[source]
classmethod get_by_import_id(connection, source_uid, record_uid, superordinate=None)[source]

Retrieve an ImportUser.

Parameters:
Returns:

object of ImportUser subclass loaded from LDAP or raises NoObject

Return type:

ImportUser

Raises:

ucsschool.lib.models.base.NoObject – if no user was found

deactivate()[source]

Deactivate user account. Caller must run modify().

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
_alter_udm_obj(udm_obj)[source]
classmethod get_all_school_names(lo)[source]
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_birthday()[source]

Set User.birthday attribute.

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_disabled()[source]

Set User.disabled attribute.

make_firstname()[source]

Normalize given name if set from import data or create from scheme.

make_lastname()[source]

Normalize family name if set from import data or create from scheme.

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_password()[source]

Create random password (if not already set).

make_record_uid()[source]

Create ucsschoolRecordUID (record_uid) (if not already set).

make_source_uid()[source]

Set the ucsschoolSourceUID (source_uid) (if not already set).

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_ucsschool_roles()[source]
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.

modify(lo, validate=True, move_if_necessary=None)[source]
modify_without_hooks(lo, validate=True, move_if_necessary=None)[source]
move(lo, udm_obj=None, force=False)[source]
move_without_hooks(lo, udm_obj, force=False)[source]
classmethod normalize(s)[source]

Normalize string (german umlauts etc)

Parameters:s (str) – str to normalize
Returns:normalized s
Return type:str
normalize_udm_properties()[source]

Normalize data in self.udm_properties.

reactivate()[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)[source]
remove_without_hooks(lo)[source]
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:
  • lo – LDAP connection object
  • validate_unlikely_changes (bool) – whether to create messages in self.warnings for changes to certain attributes
  • check_username (bool) – if username and password checks should run
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:
  • prop_to_format (str) – name of property for which the scheme is
  • scheme (str) – scheme used to format prop_to_format
  • kwargs (dict) – additional data to use for formatting
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:
  • prop_name (str) – name of property to be formatted
  • scheme (str) – scheme to use
  • kwargs (dict) – additional data to use for formatting
Returns:

formatted string

Return type:

str

classmethod get_class_for_udm_obj(udm_obj, school)[source]

IMPLEMENTME if you subclass!

get_school_class_objs()[source]
classmethod attribute_udm_names()[source]
_prevent_mapped_attributes_in_udm_properties()[source]

Make sure users do not store values for ucsschool.lib mapped Attributes in udm_properties.

_schema_write_check(scheme_attr, ucsschool_attr, ldap_attr)[source]
to_dict()[source]
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
_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 0x7f2431008878 wrapping <celery.utils.log.ProcessAwareLogger object> at 0x7f243171d7d0 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:
  • name (str) – username
  • school (str) – OU
  • kwargs – attributes to set on user object
_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 0x7f2431008830 wrapping <celery.utils.log.ProcessAwareLogger object> at 0x7f243171d7d0 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:
  • name (str) – username
  • school (str) – OU
  • kwargs – attributes to set on user object
_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 0x7f2430ffd638 wrapping <celery.utils.log.ProcessAwareLogger object> at 0x7f243171d7d0 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:
  • name (str) – username
  • school (str) – OU
  • kwargs – attributes to set on user object
_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 0x7f2430ffd5f0 wrapping <celery.utils.log.ProcessAwareLogger object> at 0x7f243171d7d0 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:
  • name (str) – username
  • school (str) – OU
  • kwargs – attributes to set on user object
_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 0x7f2430ffd5a8 wrapping <celery.utils.log.ProcessAwareLogger object> at 0x7f243171d7d0 with factory <function <lambda>>>