Bug 41472 - Support for auto-generated attributes
Support for auto-generated attributes
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.1 R2
Other Linux
: P5 normal (vote)
: UCS@school 4.1 R2
Assigned To: Daniel Tröder
Sönke Schwardt-Krummrich
:
Depends on: 41239
Blocks:
  Show dependency treegraph
 
Reported: 2016-06-06 12:03 CEST by Jan Christoph Ebersbach
Modified: 2016-09-30 12:43 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Feature Request
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Christoph Ebersbach univentionstaff 2016-06-06 12:03:35 CEST
Currently, only the username attribute can be auto-generated according to a specified scheme.  Other attributes need to be auto-generated as well like e-mail addresses.

In general, it would be very good if there were a mechanism that would make auto-generation of attribute values as easy a possible by reducing it to the JSON configuration for simple attributes.
Comment 1 Daniel Tröder univentionstaff 2016-06-06 15:58:13 CEST
The email address is also created like the username from a scheme (manual-4.1:users:templates). Configuration key is config["scheme"]["email"] (see /usr/share/doc/ucs-school-import/configuration_readme.txt.gz).

But a generic mechanism has been implemented:

To support arbitrary interpretation of user input, overwrite reader.csv_reader.CsvReader.handle_input(). See itself or legacy.legacy_csv_reader.LegacyCsvReader.handle_input() as an example.

The format string can optionally be added to the config-file: "scheme": {"birthday": "30.<month>1976"}

In handle_input() the transformations can be made by hand, or comfortably by accessing the functionality of users:templates, calling
birthday = myImportUser.format_from_scheme("birthday", config["scheme"]["birthday"], **kwargs) 
with kwargs={"month": "02"}.

I will add a routine that will check for every target except ["sourceUID", "source_uid", "__*"] of the user input mapping in config["csv"]["mapping"], if a scheme exists in config["scheme"] and apply it automatically.
Comment 2 Daniel Tröder univentionstaff 2016-06-07 12:05:45 CEST
r69873:
In configuration["scheme"][<udm attribute name>] schemes (manual-4.1:users:templates) can be configured.

When adding/modifying users, UDM attributes will be created/modified from them in ImportUser.prepare_udm_properties().

ucsschool.lib.Attributes are ignored in prepare_udm_properties(), as they are processed separately in ImportUser.make_*(). The following Attributes of User are handled in make_*() methods:
birthday, firstname, lastname, email, record_uid and (user)name.

For them and the UDM attributes the replacement <variables> are filled in the following oder (later additions overwriting previous ones):
 - from "raw" input data (as stored in ImportUser.input_data)
 - from ucsschool.lib.Attributes of self (ImportUser & ucsschool.lib.models.user.User)
 - from self.udm_properties
 - from kwargs to format_from_scheme()


An example: an import with the following addition to ["scheme"] in configs/legacy.json:
{
  "scheme": {
    ..,
    ..,
    "phone": "030-<firstname>12<:lower>",
    "description": "My email address is <email> and my RID is <record_uid>."
  }
}

# /usr/share/ucs-school-import/scripts/import_user /tmp/importtest
..

# univention-ldapsearch -xLLL '(|(ucsschoolSourceUID=*)(ucsschoolRecordUID=*))' ucsschoolSchool ucsschoolSourceUID ucsschoolRecordUID telephoneNumber description
..

dn: uid=vhohfgizqg,cn=lehrer und mitarbeiter,cn=users,ou=schule2,dc=uni,dc=dtr
ucsschoolRecordUID: vhohfgizqg
ucsschoolSchool: schule2
ucsschoolSourceUID: LegacyDB
description: My email address is vhohfgizqg@uni.dtr and my RID is vhohfgizqg.
telephoneNumber: 030-dycfmghr0c12
Comment 3 Sönke Schwardt-Krummrich univentionstaff 2016-06-15 17:52:48 CEST
ucs-test-ucsschool (3.0.12-4):
r70236 | Bug #41472: added test for auto-generated attribute values in 34_import-users_via_cli_v2

→ verified
Comment 4 Florian Best univentionstaff 2016-06-28 18:24:58 CEST
UCS@school 4.1 R2 has been released:
http://docs.software-univention.de/release-notes-ucsschool-4.1R2v1-de.pdf

If this error occurs again, please use "Clone This Bug".