fix(settings): Fix duplicated group options in new account dialog

Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
Christopher Ng 2025-03-25 14:31:45 -07:00
parent d32b76b9d4
commit eb60f6a7ba

View file

@ -71,10 +71,10 @@
:multiple="true"
:taggable="true"
:required="!settings.isAdmin && !settings.isDelegatedAdmin"
:create-option="(value) => ({ name: value })"
@input="handleGroupInput"
:create-option="(value) => ({ id: value, name: value, isCreating: true })"
@search="searchGroups"
@option:created="createGroup" />
@option:created="createGroup"
@option:selected="options => addGroup(options.at(-1))" />
<!-- If user is not admin, they are a subadmin.
Subadmins can't create users outside their groups
Therefore, empty select is forbidden -->
@ -272,15 +272,6 @@ export default {
}
},
handleGroupInput(groups) {
/**
* Filter out groups with no id to prevent duplicate selected options
*
* Created groups are added programmatically by `createGroup()`
*/
this.newUser.groups = groups.filter(group => Boolean(group.id))
},
async searchGroups(query, toggleLoading) {
if (this.promise) {
this.promise.cancel()
@ -319,6 +310,21 @@ export default {
this.loading.groups = false
},
/**
* Add user to group
*
* @param {object} group Group object
*/
async addGroup(group) {
if (group.isCreating) {
return
}
if (group.canAdd === false) {
return
}
this.newUser.groups.push(group)
},
/**
* Validate quota string to make sure it's a valid human file size
*