Bug 52920 - ASM: Inconsistent data if LDAP filters are used
ASM: Inconsistent data if LDAP filters are used
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Apple School Manager
UCS@school 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: Tobias Wenzel
Daniel Tröder
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-16 12:17 CET by Sönke Schwardt-Krummrich
Modified: 2021-05-05 17:11 CEST (History)
7 users (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?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.143
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support: Yes
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 Sönke Schwardt-Krummrich univentionstaff 2021-03-16 12:17:09 CET
In the file classes.py the classes.csv is created, which contains a list of all classes and workgroups including their teachers. Each teacher is listed in a separate CSV column (max. 15).

But there is currently no check, if a teacher is not excluded by one of the LDAP filters configured via UCR.

So if a teacher is referenced in a class that does not appear in the staff.csv file due to LDAP filter exclusion, the ASM will have a problem.

Instead of simply taking the list of teachers from the "SchoolClass" object, this should actually be filtered once against the output of the "get_staff()" method, which handles the LDAP filters.
Comment 2 Tobias Wenzel univentionstaff 2021-04-09 13:46:38 CEST
Implemented changes in 

[twenzel/asm/52920_inconsistent_ldap_filters] e134702 Bug #52920: filter out excluded staff

I moved the functionality of get_staff to a class method in AsmStaff 
to use the code in csv_file.py & classes.py.

I split the 11_ldap_filters test to make it more readable (you will see what I mean in the code).
There is also a test for (!(uid=user_name)) to prove this bug is fixed.
Comment 3 Ole Schwiegert univentionstaff 2021-04-12 11:26:16 CEST
The general idea looks good. I have the following proposals for improvement:

- remove spaces from your commit
- split into different test cases
- dont refetch User objects in classes.py, use already existing Users from get_filtered_staff function
Comment 4 Tobias Wenzel univentionstaff 2021-04-12 12:37:26 CEST
Thanks for the QA!

I implemented the requested changes in 

[twenzel/asm/52920_inconsistent_ldap_filters] 0ed35bd fixup! Bug #52920: filter out excluded staff

As discussed, 
- I also added the `.py` for all tests in asm
- added a test for get_filtered_staff

tested in single + muli-server env

asm version 

2.2.4	apple-school-manager_20210412123152

has been created/ prepared.
Comment 5 Tobias Wenzel univentionstaff 2021-04-13 14:41:35 CEST
As discussed, changes are pushed to 4.4

[4.4] ac8e5c1 Bug #52920: add changelog
[4.4] a58b5e4 Bug #52920: filter out excluded staff
Comment 6 Tobias Wenzel univentionstaff 2021-04-15 16:05:34 CEST
The solution was already tested & works but is not very efficient.

In 

[twenzel/asm/52920_inconsistent_ldap_filters] 9b6c497 Bug #52920: cache teachers in school

I implemented a suggestion, but I'm not 100% sure :)
Comment 7 Tobias Wenzel univentionstaff 2021-04-19 14:33:51 CEST
Fixed import 

[twenzel/asm/52920_inconsistent_ldap_filters] 9b6c497 Bug #52920: cache teachers in school

The solution seems to be ok, I tested this as follows:

created 500 teachers for DEMOSCHOOL & unset the ucr-vs
→ this way all teachers are loaded

timed the refactored function

teachers = get_filtered_staff(lo, logger, "DEMOSCHOOL")

Before the fix it takes 1-1.3 s to load the teachers
after the fix it takes around 1.3 s the first time the function is executed.
Comment 8 Daniel Tröder univentionstaff 2021-04-27 14:23:31 CEST
* _teachers_in_school in classes.py is unused
* revert indent of config_files-value in csv_file.py:210
* Please fix those old errors:
./modules/univention/asm/csv/zip_file.py:51:2: F401 'typing.List' imported but unused
./modules/univention/asm/csv/csv_file.py:241:3: F841 local variable 'exc' is assigned to but never used
./modules/univention/asm/models/base.py:129:3: F821 undefined name 'ucsschool'
./modules/univention/asm/models/classes.py:42:1: F401 'ucsschool.lib.models.User' imported but unused
./93_apple-school-manager/10_csv_file.py:26:2: F401 'typing.List' imported but unused
./93_apple-school-manager/20_zip_file.py:26:2: F401 'typing.List' imported but unused
./93_apple-school-manager/02_model_course.py:12:1: F401 'univention.config_registry.ConfigRegistry' imported but unused
* Code looks good, but I cannot test this. Please rebase the branch twenzel/asm/52920_inconsistent_ldap_filters upon 4.4. The package in the branch is 3 version behind 4.4! I don't know what to QA.
Comment 9 Tobias Wenzel univentionstaff 2021-04-27 17:08:27 CEST
Thanks for the QA so far!
Sorry for this mess, I implemented your remarks and rebased on 4.4

[twenzel/asm/52920_inconsistent_ldap_filters] 6e2b0ef Bug #52920: qa remarks
[twenzel/asm/52920_inconsistent_ldap_filters] 3c689bc Bug #52920: cache teachers in school
Comment 10 Daniel Tröder univentionstaff 2021-04-28 13:56:54 CEST
The package "python-backports.functools-lru-cache" is in unmaintained. Please upload it into the apps repository.
Comment 11 Daniel Tröder univentionstaff 2021-04-29 14:45:59 CEST
The package "python-backports.functools-lru-cache" has been moved to maintained and will be released next Wednesday as UCS 4.4-8 errata.
Comment 12 Tobias Wenzel univentionstaff 2021-04-29 16:16:50 CEST
python-backports.functools-lru-cache has been added to maintained.
It will be available with the next errata

[4.4-8] cf916db415  Bug #52920: add package to maintaned for apple-school-manager


teachers are now cached to speed up the process.

[4.4] b2fed4c Bug #52920: add changelog
[4.4] 59081d6 Bug #52920: cache teachers in school


Package: univention-apple-school-manager-connector
Version: 2.0.0-10A~4.4.0.202104291544
Branch: ucs_4.4-0
Scope: univention-asm

app has been uploaded to test appcenter (2.2.4)
Comment 13 Daniel Tröder univentionstaff 2021-04-30 09:52:03 CEST
OK: automatic tests
OK: changelog
OK: test-appcenter
OK: manual test:

root@m20:~# univention-ldapsearch -LLL ucsschoolRole=teacher:school:Gym21 | egrep 'dn:|objectClass: ucsschool'
dn: uid=gymadmin,cn=lehrer,cn=users,ou=Gym21,dc=uni,dc=dtr
objectClass: ucsschoolAdministrator
objectClass: ucsschoolTeacher
objectClass: ucsschoolType
dn: uid=Lehr21,cn=lehrer,cn=users,ou=Gym21,dc=uni,dc=dtr
objectClass: ucsschoolTeacher
objectClass: ucsschoolType

root@m20:~# ucr set 'asm/ldap_filter/staff=(!(objectClass=ucsschoolAdministrator))'
root@m20:~# ucr set asm/username=foo asm/store_zip=true
root@m20:~# echo univention > /etc/asm.secret 

root@m20:~# asm-upload
Creating ZIP file in /var/lib/asm/asm_2021-04-30T09:48:52.627799.zip...
Creating CSV files...
Writing 3 objects to students.csv...
Writing 12 objects to locations.csv...
Writing 2 objects to staff.csv...
No handlers could be found for logger "ucsschool.lib.models.group"
Writing 3 objects to rosters.csv...
Writing 26 objects to classes.csv...
Writing 26 objects to courses.csv...
Finished creating CSV files.
Finished creating ZIP file.
Uploading ZIP file to upload.appleschoolcontent.com...
SFTP upload failed: Authentication failed.

root@m20:~# cd /tmp/
root@m20:/tmp# unzip /var/lib/asm/asm_2021-04-30T09\:48\:52.627799.zip 

root@m20:/tmp# grep gymadmin *.csv || echo "no gymadmin in csv"
no gymadmin in csv
Comment 14 Daniel Tröder univentionstaff 2021-05-03 16:13:48 CEST
(In reply to Tobias Wenzel from comment #12)
> python-backports.functools-lru-cache has been added to maintained.
> It will be available with the next errata

Activating the errata test scope shows it ready for release:

root@m20:~# apt-cache policy python-backports.functools-lru-cache
python-backports.functools-lru-cache:
  Installiert:           1.3-1
  Installationskandidat: 1.3-1
  Versionstabelle:
 *** 1.3-1 500
        500 http://updates-test.software-univention.de/4.3/unmaintained 4.3-0/all/ Packages
        500 http://updates-test.software-univention.de/4.4/unmaintained/component 4.4-8-errata-test/all/ Packages
        100 /var/lib/dpkg/status
Comment 15 Erik Damrose univentionstaff 2021-05-03 16:22:11 CEST
(In reply to Daniel Tröder from comment #14)

> Activating the errata test scope shows it ready for release:
> 
> http://updates-test.software-univention.de/4.4/unmaintained/component
> 4.4-8-errata-test/all/ Packages

No it is not, the package is shown in unmaintained!
Comment 16 Erik Damrose univentionstaff 2021-05-05 09:46:29 CEST
python-backports.functools-lru-cache is going to be force-announced to maintained
-> back to resolved
Comment 17 Daniel Tröder univentionstaff 2021-05-05 16:36:29 CEST
OK: package will be released:
-------------------------------------------------------------------------------
root@m20:~# apt update
[..]
root@m20:~# apt-cache policy python-backports.functools-lru-cache
python-backports.functools-lru-cache:
  Installiert:           1.3-1
  Installationskandidat: 1.3-1
  Versionstabelle:
 *** 1.3-1 500
        500 http://updates-test.software-univention.de/4.3/unmaintained 4.3-0/all/ Packages
        500 http://updates-test.software-univention.de/4.4/maintained/component 4.4-8-errata-test/all/ Packages
        100 /var/lib/dpkg/status