Bug 55446 - Support translations for password already used message
Support translations for password already used message
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-2-errata
Assigned To: Florian Best
Peter Stoll
https://git.knut.univention.de/univen...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2022-11-22 10:48 CET by Carlos García-Mauriño
Modified: 2022-12-21 20:23 CET (History)
3 users (show)

See Also:
What kind of report is it?: ---
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 Carlos García-Mauriño univentionstaff 2022-11-22 10:48:11 CET
For some reason the UDM ModifyError message for already used passwords is not translated (other password errors are).

Example (run twice to get the error, the user demo_student should exist and the IP and LDAP base should be adapted):
```
import asyncio
from udm_rest_client import UDM

async def test_password_save(mod_name, dn, new_password):
   async with UDM(
           "Administrator",
           "univention",
           "http://10.207.218.171/univention/udm",
           ssl_ca_cert='/usr/local/share/ca-certificates/ucs.crt',
           language="en"
   ) as udm:
       mod = udm.get("users/user")
       udm_obj = await mod.get(dn)
       udm_obj.props.password = new_password
       udm_obj.props.overridePWHistory = False
       udm_obj.props.overridePWLength = False
       await udm_obj.save()
       return udm_obj


obj = asyncio.run(test_password_save("users/user", "uid=demo_student,cn=schueler,cn=users,ou=DEMOSCHOOL,dc=school,dc=test", "univentionunivention"))
assert obj.props.password == "univentionunivention"
```

Result:

```
udm_rest_client.exceptions.ModifyError: 1 Fehler aufgetreten:Request-Argument "password" Password has been used before. Please choose a different one.
```
Comment 2 Florian Best univentionstaff 2022-11-22 11:02:48 CET
management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py
> 329 class pwalreadyused(base):
> 330 »   message = _('Password has been used before. Please choose a different one.')

The translation is translated during import-time.
The problem here is, that univention.admin is importing univention.admin.uexceptions and univention.admin.rest.__main__ imports univention.admin before it is able to set the process locale.
Comment 3 Florian Best univentionstaff 2022-12-14 12:24:15 CET
Reproducer:
udm users/user create --set username=foo12345 --set lastname=univention --set password=univention --position="cn=users,$(ucr get ldap/base)"
curl -s -H 'Accept: application/json' "https://Administrator:univention@localhost/univention/udm/users/user/uid=foo12345,cn=users,$(ucr get ldap/base)" -X PATCH -H 'Content-Type: application/json' -H 'Accept-Language: de_DE' -d '{"properties": {"password": "univention"}}' | python -m json.tool

MR: https://git.knut.univention.de/univention/ucs/-/merge_requests/590
Comment 4 Florian Best univentionstaff 2022-12-20 19:12:54 CET
The uexceptions exceptions now translate the string again during str() evaluation, so that if the translation happened during import time the correct language is used when the locale is set after the import.

univention-management-console-module-udm.yaml
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

univention-management-console-module-udm (10.0.2-5)
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

univention-directory-manager-rest.yaml
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

univention-directory-manager-rest (10.0.4-11)
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

univention-directory-manager-modules.yaml
64a70cc26c11 | chore(univention-directory-manager-modules): update advisory
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

univention-directory-manager-modules (15.0.13-27)
3e8d0bb300a7 | refactor: enhance use of exceptions
3e7f6654317c | fix(udm): translate error messages again during exception evaluation

ucs-test-tools (9.0.0-2)
3e8d0bb300a7 | refactor: enhance use of exceptions

ucs-test (10.0.7-30)
f86d176769f2 | test(udm-rest): allow faster re-execution of test
3e8d0bb300a7 | refactor: enhance use of exceptions
3e7f6654317c | fix(udm): translate error messages again during exception evaluation
Comment 5 Peter Stoll univentionstaff 2022-12-21 14:26:34 CET
Checked:

* Code review
* Package build
* Tested password already used message to appear in German.
* Changelog and YAML advisory