Bug 55224 - UDM REST API: error messages not localized
UDM REST API: error messages not localized
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
Iván.Delgado
https://git.knut.univention.de/univen...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2022-09-26 15:24 CEST by Daniel Tröder
Modified: 2022-10-12 17:49 CEST (History)
1 user (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?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.171
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 Daniel Tröder univentionstaff 2022-09-26 15:24:20 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-*".
Comment 2 Florian Best univentionstaff 2022-09-26 16:54:53 CEST
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
Comment 3 Florian Best univentionstaff 2022-10-11 17:45:46 CEST
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
Comment 4 Iván.Delgado univentionstaff 2022-10-12 10:10:03 CEST
Verified:
 * All in Comment 3
 * Advisory
 * ucs-test-udm-rest
 * curl operation of Comment 2