ocis icon indicating copy to clipboard operation
ocis copied to clipboard

Share roles returned in a wrong locale

Open LukasHirt opened this issue 10 months ago • 2 comments

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

  1. Change locale in web UI into german
  2. Change locale back into english
  3. Go to files list and try to share a file

Expected behavior

Roles are in english

Actual behavior

Roles are in german

Setup

Image

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'

LukasHirt avatar Feb 18 '25 10:02 LukasHirt

The only way I can get the roles translated again in english is to restart the oCIS server.

LukasHirt avatar Feb 22 '25 17:02 LukasHirt

Can't reproduce.

2403905 avatar Mar 12 '25 11:03 2403905

I can confirm.

dj4oC avatar Apr 16 '25 05:04 dj4oC

I tested this now as well again with latest master and can still reproduce by the steps in the description.

LukasHirt avatar Apr 16 '25 09:04 LukasHirt

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:

  1. start oCIS server
  2. login with user with EN locale set
  3. set locale to ES
  4. open sharing dialog and see roles correctly translated into ES
  5. set locale to DE
  6. 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?

LukasHirt avatar Apr 16 '25 09:04 LukasHirt

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.

LukasHirt avatar Apr 16 '25 09:04 LukasHirt

I just did one extra test to see whether the translatable strings are really being overwritten.

  1. sign in with admin
  2. see roles in EN
  3. change locale to DE
  4. see roles in DE
  5. sign out
  6. sign in with einstein
  7. even though einstein has locale set to EN, see roles in DE

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 avatar Apr 16 '25 20:04 LukasHirt

@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

2403905 avatar Apr 16 '25 22:04 2403905