allowed_groups fetched from db JSONified - fixes #526 #546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR
Problem
cloud/groups/details
), a JSON object is returned, of the formThis is also how the groups are represented in the initial Vue state, both for the variables
groups
andallowedGroups
.When a group selection is saved, only the
id
is saved in the database. If we selectgroup1
andgroup2
, the database entry for the keyallowed_groups
will be["group1","group2"]
.Upon loading the page with a non-empty
allowed_groups
database entry, theloadState
function loads["group1","group2"]
in the Vue variableallowedGroups
.The UI however expects the richer JSON object structure as above (see in particular the sorting function called on
mounted
and, crucially,saveChanges()
).This leads to a broken UI and potentially a broken database state (e.g.
[null,null,....]
).Proposed solution
For backwards compatibility, we need to work assuming that the database only contains the ids of the allowed groups. Changing how these groups are saved in the database is a nonstarter.
In order to keep changes minimal, I propose to transform the group ids into structured JSON objects (as above) directly when the state is initially loaded:
I also changed the order of assignment of the values:
allowedGroups
is now populated first (before it wasgroups
), it seems the more logical choice sinceloadState
loads theallowed_groups
data.When the Vue component is mounted, the selectable groups are initially set to the allowedGroups, until the server query is completed and all the selectable groups are available (other places in the web interface behave exactly like that).
TODO
As mentioned in my previous pull request, the
NcMultiselect
component has been deprecated and should be replaced byNcSelect
. The nextcloud-vue module should also be bumped to 8.x.x in order to keep the UI consistent with Nextcloud 28 and above.