Bug 57599 - can't change workgroups when modifying users through the csv import
can't change workgroups when modifying users through the csv import
Status: NEEDMOREINFO
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 5.0
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS@school maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2024-09-13 10:45 CEST by Jannik Ahlers
Modified: 2024-09-17 08:57 CEST (History)
1 user (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?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 4: A User would return the product
User Pain: 0.046
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 Jannik Ahlers univentionstaff 2024-09-13 10:45:22 CEST
Bug #54891 completely removed the ability to change a user's workgroups when modifying them using the csv import, as the workgroup attribute will always get overwritten by the old value:

--- ucs-school-import/modules/ucsschool/importer/models/import_user.py
+++ ucs-school-import/modules/ucsschool/importer/models/import_user.py
@@ -1092,10 +1092,14 @@ class ImportUser(User):
 
     def modify_without_hooks(self, lo, validate=True, move_if_necessary=None):
         # type: (LoType, Optional[bool], Optional[bool]) -> bool
+        # preserve workgroups during import
+        # always getting the UDM object shouldn't have a big impact on performance since it will be retrieved anyway
+        # and it is cached
+        udm_obj = self.get_udm_object(lo)
+        self.workgroups = self.get_workgroups(udm_obj, self)
Comment 1 Jan-Luca Kiok univentionstaff 2024-09-13 13:02:26 CEST
Thanks for your report! Can you explain a bit more what you mean with "the ability to change a user's workgroups" - Via a hook or something else?

If you mean via a hook it would be great to state what you have tried so far: Was this limited to the pre_{create,modify} stages or also during post_{create,modify}?
Comment 2 Jannik Ahlers univentionstaff 2024-09-17 08:57:25 CEST
Well actually, I'm trying to read user's workgroups from the import CSV file and set them using a custom CSVReader class (so technically no hook).
I'd assume that the modify_without_hooks function gets used by the csv reader and all hook stages which modify (not create) users, though I haven't tested that.