Univention Bugzilla – Bug 55224
UDM REST API: error messages not localized
Last modified: 2022-10-12 17:49:33 CEST
The UDM REST API does not return localized error messages (or any other strings for that matter). For a new UI (RAM project), that (indirectly) uses the UDM REST API for reading and writing LDAP, the error messages for create and update operations are required to be in the end users chosen language (English or German). --------------------------------------------------------------------------- root@master203:~# curl -X PATCH "http://Administrator:univention@localhost/univention/udm/users/user/uid=Administrator,cn=users,dc=autotest203,dc=local" \ -H "accept: application/json" \ -H "Accept-Language: de-DE" \ -H "Content-Type: application/json" \ -d "{\"properties\":{\"firstname\":true}}" | python -m json.tool --------------------------------------------------------------------------- { ... "error": { "code": 422, "error": { "firstname": "The property firstname has an invalid value: Value must be of type string not bool." }, "message": "1 error(s) occurred:\nRequest argument \"firstname\" The property firstname has an invalid value: Value must be of type string not bool.\n", "title": "Unprocessable Entity", "traceback": null } } --------------------------------------------------------------------------- The UDM REST API is executed with processes for German: --------------------------------------------------------------------------- root@master203:~# ps ax | grep rest 709 ? Ss 1:13 /usr/bin/python3 -m univention.admin.rest.server 1697 ? Sl 0:17 /usr/bin/python3 -m univention.admin.rest.server # multiprocessing manager 1711 ? Sl 1:06 /usr/bin/python3 -m univention.admin.rest -l en_US.UTF-8 -c 1 -s /var/run/univention-directory-manager-rest-en-us.socket 1714 ? Sl 0:03 /usr/bin/python3 -m univention.admin.rest -l de_DE.UTF-8 -c 1 -s /var/run/univention-directory-manager-rest-de-de.socket 1849 ? Sl 0:17 /usr/bin/python3 -m univention.admin.rest -l de_DE.UTF-8 -c 1 -s /var/run/univention-directory-manager-rest-de-de.socket # multiprocessing manager 1923 ? Sl 0:18 /usr/bin/python3 -m univention.admin.rest -l en_US.UTF-8 -c 1 -s /var/run/univention-directory-manager-rest-en-us.socket # multiprocessing manager --------------------------------------------------------------------------- Modify the UDM REST API to return error messages in German if "Accept-Language" is "de" or "de-*".
Patch: https://git.knut.univention.de/univention/ucs/-/merge_requests/517 The problem is that univention.admin.rest is imported which already imports e.g. univention.admin.syntax and that has already initialized univention.l10n.Translation instances which cannot be changed anymore. A test which covers translations both from univention.admin.syntax and univention.admin.rest.* is this: curl -X PATCH "http://Administrator:univention@localhost/univention/udm/users/user/uid=Administrator,cn=users,$(ucr get ldap/base)" -H "accept: application/json" -H "Accept-Language: de-DE" -H "Content-Type: application/json" -d "{\"properties\":{\"gecos\":\"foobär\"}}" | python -m json.tool
Translation.set_all_languages() has been introduced which sets the language of all already instantiated objects. univention-lib.yaml 72a5393deaa7 | YAML Bug #55224 univention-lib (9.0.12-2) 278549c0c2dc | Bug #55224: fix translation of UDM REST API univention-directory-manager-rest.yaml 72a5393deaa7 | YAML Bug #55224 univention-directory-manager-rest (10.0.4-4) baf1159af97c | Bug #55224: add test case for different languages 278549c0c2dc | Bug #55224: fix translation of UDM REST API ucs-test (10.0.7-26) baf1159af97c | Bug #55224: add test case for different languages
Verified: * All in Comment 3 * Advisory * ucs-test-udm-rest * curl operation of Comment 2
<https://errata.software-univention.de/#/?erratum=5.0x457> <https://errata.software-univention.de/#/?erratum=5.0x458>