Bug 42112 - ucsschool-import: import script updates account expire date every time
ucsschool-import: import script updates account expire date every time
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 vXXX
Assigned To: Daniel Tröder
Florian Best
: interim-3
Depends on: 41344
Blocks:
  Show dependency treegraph
 
Reported: 2016-08-24 16:37 CEST by Daniel Tröder
Modified: 2016-12-12 13:10 CET (History)
1 user (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 4: A User would return the product
User Pain: 0.343
Enterprise Customer affected?:
School Customer affected?: Yes
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-08-24 16:37:14 CEST
+++ This bug was initially created as a clone of Bug #41344 +++

* store an expiration data (that is in the future) for the user, so it can access its data for some days, before deletion

--------

If self.config["user_deletion"]["expiration"] is set, the account expiration date is calculated as
datetime.datetime.now() + datetime.timedelta(days=self.config["user_deletion"]["expiration"])
and set in the users account  -  every time the script runs. That effectively pushes the expiration date forward.

In case the account already has an expiration date, we won't touch it. We could calculate the "nearest" date, but as we don't know what the admins intentions are, we'll simply won't change it.

Replace in lines
ucsschool/importer/mass_import/user_import.py:336 and ucsschool/importer/mass_import/user_import.py:346

user.expire()

with

if not user.has_expiry():
    user.expire()
Comment 1 Daniel Tröder univentionstaff 2016-11-18 12:48:31 CET
r74568: if a user already has an expiration date set, it is not changed anymore

This also allows the administrator to change expiration dates in UCS, without the import overwriting it.

Package has not been built yet, because the build system is currently down.
Comment 2 Daniel Tröder univentionstaff 2016-11-18 12:57:32 CET
A test was not written, as I cannot think of a safe way to do a 2nd import and test if the expiration date is untouched - on another day - without screwing with the system clock.
Comment 3 Florian Best univentionstaff 2016-11-25 18:05:32 CET
Please give me a snipped how I can test this.
I don't know how to delete a user using the importer and at the same time set attributes (disabled/expired) for him.
Comment 4 Daniel Tröder univentionstaff 2016-11-28 11:35:46 CET
See 90_ucsschool/216_import-users_delete_variants:

person = Person(self.ou_A.name, role)
config.update_entry("user_deletion:delete", True)  # or False
config.update_entry("user_deletion:expiration", exp_days)
create_csv_file(person_list=[person], mapping=config['csv']['mapping'])
run_import(['-c', fn_config])
# imports a list of users → creates: person_list=[person]

create_csv_file(person_list=[], mapping=config['csv']['mapping'])
run_import(['-c', fn_config])
# imports a list with users missing -> deletes: person_list=[]
# but with user_deletion:delete=<bool> user_deletion:expiration=<DAYS> it deactivates or just expires them instead
Comment 5 Florian Best univentionstaff 2016-12-01 19:07:44 CET
Seems not to work:

# cat foo.csv 
"school","role","firstname","lastname","class","description","telephone"
"oldschool","student","Verita","Studberg","oldschool-1,oldschool-a","A student.","+49-194-123802"
"oldschool","student","Veritas","Stuetzer","oldschool-1,oldschool-b","A student.","+63-357-360032"
# /usr/share/ucs-school-import/scripts/ucs-school-user-import -i foo.csv --set user_deletion:delete=True --set user_deletion:expiration=5 --sourceUID foo -u student -s oldschool
# modify expiration date of user via UMC to 1.12
# univention-ldapsearch -LLLb uid=v.studberg,cn=schueler,cn=users,ou=oldschool,dc=school,dc=local | ldapsearch-wrapper  | grep -v krb5Key > 1.ldif
# change foo.csv into:
# cat foo.csv 
"school","role","firstname","lastname","class","description","telephone"
"oldschool","student","Veritas","Stuetzer","oldschool-1,oldschool-b","A student.","+63-357-360032"
# /usr/share/ucs-school-import/scripts/ucs-school-user-import -i foo.csv --set user_deletion:delete=True --set user_deletion:expiration=5 --sourceUID foo -u student -s oldschool
# univention-ldapsearch -LLLb uid=v.studberg,cn=schueler,cn=users,ou=oldschool,dc=school,dc=local | ldapsearch-wrapper  | grep -v krb5Key > 2.ldif
# ldiff 1.ldif 2.ldif
 dn: uid=v.studberg,cn=schueler,cn=users,ou=oldschool,dc=school,dc=local
+shadowExpire: 17141
-shadowExpire: 17136
+sambaKickoffTime: 1480978800
-sambaKickoffTime: 1480546800
+krb5ValidEnd: 20161206000000Z
-krb5ValidEnd: 20161201000000Z


The configuration is:

{u'activate_new_users': {u'default': True},
 u'classes': {},
 u'csv': {u'header_lines': 1,
          u'incell-delimiter': {u'default': u','},
          u'mapping': {u'firstname': u'firstname',
                       u'lastname': u'lastname',
                       u'school': u'school',
                       u'username': u'username'}},
 u'dry_run': False,
 u'factory': u'ucsschool.importer.default_user_import_factory.DefaultUserImportFactory',
 u'input': {u'filename': 'foo.csv', u'type': u'csv'},
 u'logfile': u'/var/log/univention/ucs-school-import.log',
 u'maildomain': None,
 u'mandatory_attributes': [u'firstname', u'lastname', u'name', u'school'],
 u'no_delete': False,
 u'output': {u'new_user_passwords': None,
             u'user_import_summary': u'/var/lib/ucs-school-import/user_import_summary_%Y-%m-%d_%H:%M:%S.csv'},
 u'password_length': 15,
 u'scheme': {u'email': u'<firstname>[0].<lastname>@<maildomain>',
             u'recordUID': u'<:umlauts><firstname>[0].<lastname><:lower>',
             u'username': {u'allow_rename': False,
                           u'default': u'<:umlauts><firstname>[0].<lastname><:lower>'}},
 u'school': 'oldschool',
 u'sourceUID': 'foo',
 u'tolerate_errors': 0,
 u'user_deletion': {u'delete': True, u'expiration': 5},
 u'user_role': 'student',
 u'verbose': True}
Comment 6 Daniel Tröder univentionstaff 2016-12-02 10:06:11 CET
Something's wrong with that test. Maybe the UMC did something because the expiration date was "today"? Please try like this:

### 1st import -> creates users w/o expiration date
# udm users/user list --filter uid=v.studberg > v.studberg_1

### 2nd import -> user has an expiration date now
# udm users/user list --filter uid=v.studberg > v.studberg_2
# diff v.studberg_1 v.studberg_2
41c41
<   userexpiry: None
---
>   userexpiry: 2016-12-07

### change date
# /etc/init.d/ntp stop
# date -s 2016-12-04

### 3rd import -> users expiration date did not change
# diff v.studberg_2 v.studberg_3
Comment 7 Florian Best univentionstaff 2016-12-02 10:40:02 CET
The package yesterday was not build:
Vorbereitung zum Ersetzen von ucs-school-import 14.0.16-37.329.201611161513 (durch .../ucs-school-import_14.0.16-39.330.201612021010_all.deb)
Comment 8 Florian Best univentionstaff 2016-12-02 12:27:14 CET
OK: with the new package and above snipped it works
OK: YAML (adjusted in r74930)
Comment 9 Sönke Schwardt-Krummrich univentionstaff 2016-12-12 13:10:21 CET
UCS@school 4.1 R2 v9 has been released.

http://docs.software-univention.de/changelog-ucsschool-4.1R2v9-de.html