Bug 41243 - normalize username, firstname, lastname, email address when importing users
normalize username, firstname, lastname, email address when importing users
Status: RESOLVED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
unspecified
Other Linux
: P5 normal (vote)
: UCS@school 4.1 R2
Assigned To: Daniel Tröder
Sönke Schwardt-Krummrich
: interim-1
Depends on: 41244
Blocks: 41239
  Show dependency treegraph
 
Reported: 2016-05-10 14:30 CEST by Daniel Tröder
Modified: 2016-09-30 11:57 CEST (History)
1 user (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 Daniel Tröder univentionstaff 2016-05-10 14:30:57 CEST
* Use univention.admin.property → _replace() so the syntax from user-templates can be used.
* Additionally replace the following strings for name clashes:
** [ALWAYSCOUNTER] ==> anton1, anton2, anton3
** [COUNTER2] ==> anton, anton2, anton3
* usernames may have different schemes for different user roles
Comment 1 Daniel Tröder univentionstaff 2016-05-10 14:34:06 CEST
After formatting from scheme, usernames shall be shortened to 12 characters and have the mentioned numbers (counter) appended.
Comment 2 Sönke Schwardt-Krummrich univentionstaff 2016-05-26 11:20:04 CEST
(In reply to Daniel Tröder from comment #1)
> After formatting from scheme, usernames shall be shortened to 12 characters
> and have the mentioned numbers (counter) appended.

This is done, to ensure that the usernames are usually not longer than 15 characters, so they do not exceed 20 characters if the "exam-" prefix is prepended. Otherwise windows will have problem with the username length.
Comment 3 Daniel Tröder univentionstaff 2016-05-26 15:42:58 CEST
Implemented in r69557 as described in comment #1.

The maximum username length can be changed by code or subclasses by changing the attribute ImportUser.username_max_length. Defaults to 15.
Comment 4 Sönke Schwardt-Krummrich univentionstaff 2016-06-10 16:19:39 CEST
(In reply to Daniel Tröder from comment #3)
> The maximum username length can be changed by code or subclasses by changing
> the attribute ImportUser.username_max_length. Defaults to 15.

Do not hardcode the length to 15. Other code parts of UCS@school use something like this:

--- a/ucs-school-4.1r2/ucs-school-import/modules/ucsschool/importer/models/import_user.py
+++ b/ucs-school-4.1r2/ucs-school-import/modules/ucsschool/importer/models/import_user.py
@@ -67,7 +67,7 @@ class ImportUser(User):
 	record_uid = RecordUID("RecordUID")
 
 	config = None
-	username_max_length = 15
+	username_max_length = None
 	_unique_ids = defaultdict(set)
 	factory = None
 	ucr = None
@@ -84,6 +84,8 @@ class ImportUser(User):
 			self.ucr = self.factory.make_ucr()
 			self.config = Configuration()
 			self.reader = self.factory.make_reader()
+		if self.username_max_length is None:
+			self.username_max_length = 20 - len(self.ucr.get('ucsschool/ldap/default/userprefix/exam', 'exam-'))
 		super(ImportUser, self).__init__(name, school, **kwargs)
 
 	def build_hook_line(self, hook_time, func_name):
Comment 5 Daniel Tröder univentionstaff 2016-06-13 13:14:48 CEST
(In reply to Sönke Schwardt-Krummrich from comment #4)
> Do not hardcode the length to 15
Fixed in r70131.
Comment 6 Sönke Schwardt-Krummrich univentionstaff 2016-06-14 03:23:36 CEST
(In reply to Daniel Tröder from comment #5)
> (In reply to Sönke Schwardt-Krummrich from comment #4)
> > Do not hardcode the length to 15
> Fixed in r70131.
→ r70131 verified
Comment 7 Sönke Schwardt-Krummrich univentionstaff 2016-07-05 15:08:22 CEST
[ALWAYSCOUNTER] and [COUNTER2] are covered by 34_import-users_via_cli_v2.

Missing is currently a test, that the usernames are not reused if a previous user has been removed.
Comment 8 Sönke Schwardt-Krummrich univentionstaff 2016-07-05 15:09:00 CEST
(In reply to Sönke Schwardt-Krummrich from comment #7)
> [ALWAYSCOUNTER] and [COUNTER2] are covered by 34_import-users_via_cli_v2.
> 
> Missing is currently a test, that the usernames are not reused if a previous
> user has been removed.
That was meant for bug 41244.