Bug 42144 - Cut username generation at first double-barrelled lastname
Cut username generation at first double-barrelled lastname
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.1 R2
Other Linux
: P5 normal (vote)
: UCS@school 4.2 v4
Assigned To: Daniel Tröder
Sönke Schwardt-Krummrich
:
Depends on:
Blocks: 45524 45525
  Show dependency treegraph
 
Reported: 2016-08-26 12:08 CEST by Michel Smidt
Modified: 2017-10-16 21:33 CEST (History)
6 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 2: Improvement: Would be a product improvement
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.103
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2016082421000167
Bug group (optional): External feedback
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michel Smidt 2016-08-26 12:08:01 CEST
According to Feedback on Ticket#2016082421000167 related to the Import-Interface.

Use case from the customer:
Import user with double-barrelled name (e.g. Nadine Mueller-Meier)

Configuration:
"username": {"default": "<:umlauts><firstname>[0]<lastname><:lower>[COUNTER2]"}

Result:
username = nmueller-mei3

The customer would like to have the possibility (e.g. via schema option) to cut the name at the hyphen and don't use the second lastname in the username generation.
username = nmueller3

This requirement was requested and implemented in a project specific import tool for the customer 09711 as well. So, I guess it is not a customer specific requirement.
Comment 1 Michael Grandjean univentionstaff 2016-08-26 12:37:25 CEST
Just for completeness: The customer implementation for 09711 especially handles cases such as:

"username": {"default": "<:umlauts><firstname><lastname>[0]<:lower>[COUNTER2]"}

Firstname: Karl-Theodor Maria 
Lastname: Müller
Product import: karltheodormariam2
Project import: karlm2

The project implementation is able to split firstnames (and lastnames) at a hyphen ( - ) and/or a space character. 
This was requested by primary schools to make it more easy for primary school students to type their username.
Comment 2 Daniel Tröder univentionstaff 2016-08-26 12:47:45 CEST
This feature is indeed not supported by user templates (http://docs.software-univention.de/manual-4.1.html#users:templates).

I suggest to implemented it either as an extension of ucsschool.importer.utils.username_handler.UsernameHandler.format_username() or by adding it as a feature to univention.admin.property (univention-directory-manager-modules).

The latter would profit the whole of UCS.
Comment 3 Daniel Tröder univentionstaff 2016-10-04 13:07:56 CEST
It's not forked from the product, but code in the prof. services' import script.
Comment 4 Michael Grandjean univentionstaff 2016-10-04 13:26:27 CEST
(In reply to Daniel Tröder from comment #3)
> It's not forked from the product, but code in the prof. services' import
> script.

But we would have forked from the product, if we didn't already had this prof. services' import script ;)
Comment 5 Sönke Schwardt-Krummrich univentionstaff 2016-10-13 13:50:57 CEST
(In reply to Michael Grandjean from comment #4)
> But we would have forked from the product, if we didn't already had this
> prof. services' import script ;)

I think that there is no need to fork the product package since it is possible to overload the corresponding function via the factory mechanism.
Comment 6 Sönke Schwardt-Krummrich univentionstaff 2017-08-28 08:53:08 CEST
Is there still a constant and urgent need to fix this?
Comment 7 Michel Smidt 2017-08-28 09:05:51 CEST
It's not my customer. (In reply to Sönke Schwardt-Krummrich from comment #6)
> Is there still a constant and urgent need to fix this?

It's not my customer ;-) Tobi?
Comment 8 Michael Grandjean univentionstaff 2017-08-28 09:20:25 CEST
09711 is "my" customer and this issue prevents the switch from the custom import script to "ucs-school-user-import". The custom one lacks some features compared to the product import (e.g. multiple schools), so this is in fact a constant problem.
Comment 9 Sönke Schwardt-Krummrich univentionstaff 2017-09-04 13:54:15 CEST
(In reply to Michael Grandjean from comment #1)
> The project implementation is able to split firstnames (and lastnames) at a
> hyphen ( - ) and/or a space character. 

Suggestion:
The product should be able to split firstnames/lastnames at a set of delimiters.
The delimiters ("-", " ", ...) should default to hyphen and space, but should be overrideable via UCRV.
It should be configurable via UCR variables if splitting is enabled for firstname and/or lastname.

Would this be a proper solution for all known (and imaginable ;-) customer environments?
Comment 10 Daniel Tröder univentionstaff 2017-09-06 13:58:01 CEST
Add hook/interface to modify format_from_scheme() behavior.
Comment 11 Daniel Tröder univentionstaff 2017-09-15 16:57:55 CEST
It is now possible to modify the attributes (in a dictionary) that are used for formatting user properties from a schema by using a pyhook. It is possible to do this for all properties that are created using templates (that is: _all_ including those in udm_properties).

The hook class must be a decedent from ucsschool.importer.utils.format_pyhook.FormatPyHook

Four methods exist: patch_fields_staff(), patch_fields_student(), patch_fields_teacher(), patch_fields_teacher_and_staff() and will be called for the respective user objects.

FormatPyHook.priority is used (like with UserPyHook.priority) to prioritize or disable methods.
FormatPyHook.properties is a list of property names that the hook will be run for. All other properties will be ignored (performance optimization).

A working example is in ucs-school-import/usr/share/doc/ucs-school-import/format_hook_example.py
Copy it to /usr/share/ucs-school-import/pyhooks/ and run an import with users in a CSV that have multiple/double-barrelled firstname/lastnames.

Code: e8a2aadfafb7a1fbade9c9905861429d5814e344
Advisory: cca317d198b0ac8b227714b3675599694b3fde0c

Package: ucs-school-import
Version: 15.0.0-43A~4.2.0.201709151643
Branch: ucs_4.2-0
Scope: ucs-school-4.2
Comment 12 Sönke Schwardt-Krummrich univentionstaff 2017-10-12 22:56:20 CEST
OK: code change
OK: functional test (manually)
    → used a slight variation of the example hook that uses the first 
      3 characters of the firstname and the last 3 characters of the lastname 
      (result see below)
OK: advisory



ucs-school-testuser-import \
   --staff 2 --students 2 --teachers 2 --staffteachers 2 \
   --classes=3 --inclasses 1 --schools 1 --create-email-addresses gsnord
===>
"2","1","0","A","staff","ber.lte","gsnord","Bertolf","Stolte","","bertolf.stolte@nstx.local","0","","TESTID","Bertolf.Stolte",""
"3","1","0","A","staff","ber.rst","gsnord","Bertram","Stomphorst","","bertram.stomphorst@nstx.local","0","","TESTID","Bertram.Stomphorst",""
"4","1","0","A","student","bertrand.sto","gsnord","Bertrand","Stoner","","ber.ner@nstx.local","0","gsnord-1a","TESTID","Bertrand.Stoner",""
"5","1","0","A","student","bertraude.st","gsnord","Bertraude","Storch","","ber.rch@nstx.local","0","gsnord-1b","TESTID","Bertraude.Storch",""
"6","1","0","A","teacher","ber.aus","gsnord","Bertrun","Storllaus","","bertrun.storllaus@nstx.local","0","gsnord-1c","TESTID","Bertrun.Storllaus",""
"7","1","0","A","teacher","ber.orm","gsnord","Bertwin","Storm","","bertwin.storm@nstx.local","0","gsnord-1a","TESTID","Bertwin.Storm",""
"8","1","0","A","teacher_and_staff","beryl.stroem","gsnord","Beryl","Stroem","","ber.oem@nstx.local","0","gsnord-1b","TESTID","Beryl.Ström",""
"9","1","0","A","teacher_and_staff","bes.struebe","gsnord","Bes","Struebe","","bes.ebe@nstx.local","0","gsnord-1c","TESTID","Bes.Strübe",""
Comment 13 Sönke Schwardt-Krummrich univentionstaff 2017-10-16 21:32:04 CEST
UCS@school 4.2 v4 has been released.

http://docs.software-univention.de/changelog-ucsschool-4.2v4-de.html

If this error occurs again, please clone this bug.