Bug 54131 - NotSupportedError during user deletion if "username" instead of "name" is used in the mapping
NotSupportedError during user deletion if "username" instead of "name" is use...
Status: NEW
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS@school maintainers
:
Depends on: 53649
Blocks:
  Show dependency treegraph
 
Reported: 2021-11-24 12:11 CET by Jürn Brodersen
Modified: 2021-11-24 15:26 CET (History)
2 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 4: Minor Usability: Impairs usability in secondary scenarios
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.091
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2021111621000406
Bug group (optional): Usability, Workaround is available
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jürn Brodersen univentionstaff 2021-11-24 12:11:27 CET
NotSupportedError during user deletion if "username" instead of "name" is used in the mapping

username and mailPrimaryAddress are detected as udm_properties. For user creation and modification these are removed from udm_properties in their respective make_username, make_email function.

The make_* functions are not called during user deletion. The user is read as is from ldap.

Since username (and/or mailPrimaryAddress) was never removed from udm_properties in case the user should be deleted, a error will be thrown [1].

username and mailPrimaryAddress need to be removed from udm_properties, for users that should be deleted, as well.

This is a regression from bug 53649, which add udm_prperties to users which should be deleted.

[1]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 491, in delete_users
    success = self.do_delete(user)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 625, in do_delete
    success = user.modify(lo=self.connection, validate=False)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1057, in modify
    res = super(ImportUser, self).modify(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/base.py", line 674, in modify
    success = self.modify_without_hooks(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1093, in modify_without_hooks
    return super(ImportUser, self).modify_without_hooks(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/base.py", line 701, in modify_without_hooks
    self.do_modify(udm_obj, lo)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/user.py", line 330, in do_modify
    return super(User, self).do_modify(udm_obj, lo)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/base.py", line 735, in do_modify
    self._alter_udm_obj(udm_obj)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 501, in _alter_udm_obj
    self._prevent_mapped_attributes_in_udm_properties()
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1591, in _prevent_mapped_attributes_in_udm_properties
    "udm_properties).".format("', '".join(bad_props), self.__class__.__name__)
NotSupportedError: UDM properties 'username' must be set as attributes of the ImportStudent object (not in udm_properties).
Comment 1 Jürn Brodersen univentionstaff 2021-11-24 12:12:27 CET
Workaround:
use "name" instead of "username" in the mapping.
use "email" instead of "mailPrimaryAddress" in the mapping.
Comment 2 Daniel Tröder univentionstaff 2021-11-24 15:24:46 CET
IMHO this is a user error, not a software error.
That is why a NotSupportedError is raised with an explanation, how the user can fix it.

_prevent_mapped_attributes_in_udm_properties() is only called when a create() or modify() operation is done. In the delete() case a modify() happens, when a user get actually _deactivated_, instead of immediately deleted.

But nevertheless we want to stop the import as early as possible in the case of errors. So the check for udm_properties that should be ucsschool.lib user attributes should be done in a ConfigurationCheck. This will not prevent problems created by hooks, but the case in this bug could have been prevented.

So I suggest to add a "test_mapped_attributes_not_in_udm_properties()" to ucs-school-import/usr/share/ucs-school-import/checks/defaults.py that does basically the same as "ImportUser._prevent_mapped_attributes_in_udm_properties()".