Share roles returned in a wrong locale
Describe the bug
I changed my locale in the web UI from english to german and then back to english and even though the Accept-Language header is correctly set to en, the permissions endpoint returns share roles in german...
Steps to reproduce
- Change locale in web UI into german
- Change locale back into english
- Go to files list and try to share a file
Expected behavior
Roles are in english
Actual behavior
Roles are in german
Setup
Additional context
This is the request:
curl $'https://host.docker.internal:9200/graph/v1beta1/drives/d757b907-73a5-4847-8e2f-a80dad47e72b%24b1ec0786-e329-404e-9378-38d4a2396f4f/items/d757b907-73a5-4847-8e2f-a80dad47e72b%24b1ec0786-e329-404e-9378-38d4a2396f4f\u00212434ee18-205c-4fcd-be4d-0b08e18786fa/permissions' \
-H 'accept: application/json, text/plain, */*' \
-H 'accept-language: en' \
-H 'authorization: Bearer eyJhbGciOiJQUzI1NiIsImtpZCI6InByaXZhdGUta2V5IiwidHlwIjoiSldUIn0.eyJhdWQiOiJ3ZWIiLCJleHAiOjE3Mzk4NzU2OTAsImlhdCI6MTczOTg3NTM5MCwiaXNzIjoiaHR0cHM6Ly9ob3N0LmRvY2tlci5pbnRlcm5hbDo5MjAwIiwianRpIjoidzQ3Q0NtSFVYNDVKREdBWmVnQ3o1VjF5Zk9yX2MxMnQiLCJsZy5pIjp7ImRuIjoiQWRtaW4iLCJpZCI6Im93bkNsb3VkVVVJRD1iMWVjMDc4Ni1lMzI5LTQwNGUtOTM3OC0zOGQ0YTIzOTZmNGYiLCJ1biI6ImFkbWluIn0sImxnLnAiOiJpZGVudGlmaWVyLWxkYXAiLCJsZy50IjoiMSIsInNjcCI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwic3ViIjoiSUlzWUR3Z0tmMHVvVUpqV0BJLTJVR2J5M2ZpWTYtWGlKaFo1bXRrNVNEbWgtNXlleVJjQ21PMTJqUk9Qd203cnBsSE9LcFQtcWdzQUpxUW80VkpuRm5nIn0.COeTKb9mel_SK9eVLDFFn6Z2_w7_sadedsZC7sg8NlhnMdUbgBDETCPMxIPoKK3VK5J_CJHepWKFC10X3XHapycQkzGZJ-u4tf_3IqULqnwB_sTvtzlJOPjOAOPdw1t0tB5es3prlnR2KP19FbNV4iBwxaIVJkE-UjtEmEWFzT7DNxzk_jJYqAbg6_3bLobIdmOMLhPHBCjHjYH5jDXzuQiNl_SfsJFy4Gag9peq0Wqv9ewnC5KVoy1IRzKeqBF-_OSRQIZHSwYeu0DVrMj6cq_GN7UKUGOrtPnrjRhkpuhV8VUD1aKHCgJ3U1GPwtlB9Iwel7iJ8icKwe3a2bEGNrf-uYafA5G9SUSnyvjcwSMsf0RqeWJv1ptXM_90PFcV3owelF75W8GmQ5Cs2ktf3XOtQpMDRpPRXj5u1im7vXNXkX6-FxqtHKAh6QhcXC3WXkYwojkEOhfxqmkxtrbCP0Z-fhA9ghC2ufPd16fn4u1QGedqOiWbTf19r-nETrE-k9ErIXTF56hfH9NVZ-nIfnb3oUDpYaRqpMhlBhYGq0Llqo85_cX-HM8kIkwvjLpU_odU3guFdd1ebNaNVRpdexutG9FZT97usZmMIgDqTXwoePoI1-TOTIrSCydxg-hLj995ofFZmzY6tTivBo7ucZmaDt0oo4Y9RaKpnzlGU-8' \
-H 'cache-control: no-cache' \
-H 'initiator-id: 40a2c918-63c3-43f1-95f1-39719292648b' \
-H 'origin: https://host.docker.internal:9201' \
-H 'pragma: no-cache' \
-H 'priority: u=1, i' \
-H 'referer: https://host.docker.internal:9201/' \
-H 'sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36' \
-H 'x-request-id: e316598f-9d32-4827-b960-f674a6de82ef' \
-H 'x-requested-with: XMLHttpRequest'
The only way I can get the roles translated again in english is to restart the oCIS server.
Can't reproduce.
I can confirm.
I tested this now as well again with latest master and can still reproduce by the steps in the description.
Just noticed that it is not only issue with going back to English. Anytime I switch to any locale, then the share roles are stuck in that locale.
Reproduction steps:
- start oCIS server
- login with user with EN locale set
- set locale to ES
- open sharing dialog and see roles correctly translated into ES
- set locale to DE
- open sharing dialog and see roles still translated into ES
My current hunch is that when the translations happen here https://github.com/owncloud/ocis/blob/master/services/graph/pkg/service/v0/api_driveitem_permissions.go#L805 the roles definition maybe gets overwritten from translatable string to the translated string and that's why next time it's not translated?
Yep, seems to be the case with overwriting the source string https://github.com/owncloud/ocis/blob/7947c99930db3dde5de401abb0dd74129f85c724/ocis-pkg/l10n/l10n.go#L321
SetString sets v's underlying value to x.
I just did one extra test to see whether the translatable strings are really being overwritten.
- sign in with
admin - see roles in
EN - change locale to
DE - see roles in
DE - sign out
- sign in with
einstein - even though
einsteinhas locale set toEN, see roles inDE
https://github.com/user-attachments/assets/2c0ccb75-4976-4e7c-8372-924169c58628
This seems to confirm my hunch and also shows that the issue is a bit bigger as a single user changing his locale affects all other users...
@LukasHirt I updated the pr.
Ocis used the global slice buildInRoles of roles and tried to clone the slice each time. But theslices.Clone function doesn't work properly, that why the transaction overwrites roles globally.
https://github.com/owncloud/ocis/blob/20f32d4f2a7f9b095cf075a07e66dd8b67f4c887/services/graph/pkg/unifiedrole/roles.go#L204
https://github.com/owncloud/ocis/blob/20f32d4f2a7f9b095cf075a07e66dd8b67f4c887/services/graph/pkg/unifiedrole/filter.go#L39