Bug 8122 - Presented data in Web Admin is not sorted on locale
Summary: Presented data in Web Admin is not sorted on locale
Status: CLOSED FIXED
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Other (show other bugs)
Version: trunk
Hardware: PC Unknown
: P2 Normal
Target Milestone: 4.15.0
Assignee: Linn
URL:
Keywords: frifl_tester, prosaic
Depends on:
Blocks:
 
Reported: 2023-03-21 12:48 CET by Linn
Modified: 2023-04-24 12:48 CEST (History)
2 users (show)

See Also:
Acceptance Criteria:
* Tables on the following pages should be sorted alphabetically based on the server's locale: - Status -> Sessions - Status -> Load (Both subclusters and the agents within a subcluster) - VSM -> Subclusters - Profiles -> Introduction texts - Locations -> Locations - Locations -> Terminals - Desktop Customizer pages: - Application Groups - Applications (Manual) - Applications (System) - Menu Structure * On page Profile -> Profile List: - Active profiles should keep their independent ordering - Inactive profiles should be sorted based on locale * All sorted tables and lists should be sorted in the same way


Attachments

Description Linn cendio 2023-03-21 12:48:56 CET
In tlctl's 'session list' and Web Admin's /status/sessions, we sort the sessions based on username and display number. However, the sorting does not take the locale into account, so non-ascii characters might be sorted wrong based on the user's expectation, e.g. 'ö' not coming after 'o' for German locale.

We have done locale based sorting for subclusternames in tlctl/load using the following:
> sorted(..., key=locale.strxfrm)
Comment 2 Linn cendio 2023-03-24 16:09:22 CET
Tested with server on RHEL 8 with German locale (de_DE), which has alphabet order: 
  a, ä, ..., o, ö, ..., z

Before fix:
> Username Display Agent 	Status 	        Age
> aser 	 10 	127.0.0.1 	connected 	49 min
> zser 	 11 	127.0.0.1 	connected 	49 min
> äser 	 12 	127.0.0.1 	connected 	49 min
After fix:
> Username Display Agent 	Status 	        Age
> aser 	 10 	127.0.0.1 	connected 	51 min
> äser 	 12 	127.0.0.1 	connected 	51 min
> zser 	 11 	127.0.0.1 	connected 	51 min
The order of the usernames now matches the alphabetical order, marking as resolved.

* Tips for tester
Note that changes to locale is not updated immediately, I restarted my machine to trigger it.
Comment 3 Linn cendio 2023-03-30 08:54:55 CEST
A few more things remain for this bug to be done:

* When calculating the age of the session, we should not directly import get_age() from tlctl. It is not clear that the function also affects web admin when it is defined in tlctl-specific code. 
One solution is to split the function out to a shared util file, but it is more likely that we just end up duplicating the function in web admin for now.

* Sessions is not the only page that should have locale aware sorting. I've skimmed through webadmin and it seems at least these pages should also have this kind of sorting:
  - VSM -> Subclusters
  - Profiles -> Introduction texts
  - All pages under Desktop Customizer:
    - Application groups
    - Applications (Manual)
    - Applications (System)
    - Menu structure
Comment 4 Linn cendio 2023-03-30 14:56:34 CEST
This is the complete list of pages that needs locale based sorting:

  - VSM -> Subclusters
  - Profiles -> Introduction texts
  - All pages under Desktop Customizer:
    - Application groups
    - Applications (Manual)
    - Applications (System)
    - Menu structure
  - Locations -> Locations
  - Locations -> Terminals
  - Profile -> Profile List, only for _Inactive profiles_

Note that _Active profiles_ in Profile -> Profile List should not be sorted, as the order of that table determines the order for which the profiles are presented to a user.
Comment 9 Linn cendio 2023-04-05 09:15:36 CEST
Before this bug, the table under /desktop/appgroups was sorted on case-insensitive appgroup names.

When using strxfrm(), the sorting is both locale aware and still keeps case-insensitive sorting. However, note that strxfrm only sorts as intended after `locale.setlocale(locale.LC_ALL, "")` has been called, see example for swedish locale below:
> >>> l = ["ce", "Ät", "aa", "Ce", "äe"]
> >>> sorted(l2, key=locale.strxfrm)
> ['Ce', 'aa', 'ce', 'Ät', 'äe']
> >>> locale.setlocale(locale.LC_ALL, "")
> >>> sorted(l2, key=locale.strxfrm)
> ['aa', 'ce', 'Ce', 'äe', 'Ät']
Comment 10 Linn cendio 2023-04-05 09:19:55 CEST
Checked the Web Admin pages with Swedish and German locale, and the sorting was different depending on which locale was active. Also checked that Profiles -> Profile List only sorts the inactive profiles.
Comment 11 Linn cendio 2023-04-05 09:40:18 CEST
There is one cleanup commit in the code for Profiles -> Introduction Texts that can be improved on, reopening.
Comment 13 Linn cendio 2023-04-05 16:03:05 CEST
Did a quick test on the Introduction Texts page, looks in order. Setting to Resolved again.
Comment 14 Frida Flodin cendio 2023-04-12 08:45:58 CEST
When editing an application group, the applications lists are not sorted on locale. 

The list of selected groups and users for the application group is not sorted at all, and has never been. I believe these lists are in the same order as they are written in the configuration file. We should probably consider sorting these as well. We have the same kind of lists on the VSM -> Master page, "Allowed Groups" and "Allowed Shadowers".
Comment 15 Frida Flodin cendio 2023-04-12 11:15:17 CEST
When editing a terminal, you choose a location from a dropdown list. This list is not sorted based on locale right now.
Comment 16 Frida Flodin cendio 2023-04-12 11:20:44 CEST
The dropdown when adding printers to locations and terminals is not locale sorted either.

Tips for adding fake printers:
> lpadmin -p åäö -E -v file:///dev/null
Comment 17 Frida Flodin cendio 2023-04-12 12:25:53 CEST
I have now tested all pages and aside from comment #14, #15 and #16 everything looks good and correctly sortred. I tested with locale set to cs_CZ.ISO-8859-2 and the strings "chrt" and "hrnec". In the Czech locale "hrnec" comes before "chrt".

Acceptance criteria:
> * Tables on the following pages should be sorted alphabetically based on the server's locale:
>   - Status -> Sessions
>   - Status -> Load (Both subclusters and the agents within a subcluster)
>   - VSM -> Subclusters
>   - Profiles -> Introduction texts
>   - Locations -> Locations
>   - Locations -> Terminals
>   - Desktop Customizer pages:
>     - Application Groups
>     - Applications (Manual)
>     - Applications (System)
>     - Menu Structure
They are!

> * On page Profile -> Profile List:
>   - Active profiles should keep their independent ordering
Yes
>   - Inactive profiles should be sorted based on locale
Yes

> * All sorted tables and lists should be sorted in the same way.
Yes, aside from comment #14, #15 and #16.
Comment 20 Tobias cendio 2023-04-18 09:28:42 CEST
Comment 14, 15, and 16 have been addressed now. The remaining data lists should be locale aware sorted now.

Setting as resolved.
Comment 22 Frida Flodin cendio 2023-04-18 16:17:23 CEST
I will reopen this. Comment #14 does not seem completely fixed? 
> We have the same kind of lists on the VSM ->
> Master page, "Allowed Groups" and "Allowed Shadowers".

I also had some comments on the code changes that should be fixed before closing this.
Comment 26 Tobias cendio 2023-04-21 16:13:07 CEST
Sorting of lists on the VSM/Master page was overlooked, as addressed in comment 22,
and has been fixed now. Furthermore, there was some double sorting occurring
on the Locations, Terminals, and Application Groups pages, which has been
addressed now.

This bug should be ready for testing once again.
Comment 27 Frida Flodin cendio 2023-04-24 12:48:59 CEST
Verified that everything is fixed, looks good. Nothing to comment on the code changes. Closing.

Note You need to log in before you can comment on or make changes to this bug.