Skip to content

Commit cc3fdf8

Browse files
authored
Merge pull request nextcloud#52776 from nextcloud/fix/52590/available-account-groups
2 parents 080473c + 97c7d93 commit cc3fdf8

File tree

9 files changed

+63
-36
lines changed

9 files changed

+63
-36
lines changed

apps/settings/src/components/AppNavigationGroupList.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<NcAppNavigationList class="account-management__group-list"
4343
aria-describedby="group-list-desc"
4444
data-cy-users-settings-navigation-groups="custom">
45-
<GroupListItem v-for="group in userGroups"
45+
<GroupListItem v-for="group in filteredGroups"
4646
:id="group.id"
4747
ref="groupListItems"
4848
:key="group.id"
@@ -96,7 +96,11 @@ const selectedGroup = computed(() => route.params?.selectedGroup)
9696
/** Current active group - URL decoded */
9797
const selectedGroupDecoded = computed(() => selectedGroup.value ? decodeURIComponent(selectedGroup.value) : null)
9898
/** All available groups */
99-
const groups = computed(() => store.getters.getSortedGroups)
99+
const groups = computed(() => {
100+
return isAdminOrDelegatedAdmin.value
101+
? store.getters.getSortedGroups
102+
: store.getters.getSubAdminGroups
103+
})
100104
/** User groups */
101105
const { userGroups } = useFormatGroups(groups)
102106
/** Server settings for current user */
@@ -119,6 +123,14 @@ const loadingGroups = ref(false)
119123
const offset = ref(0)
120124
/** Search query for groups */
121125
const groupsSearchQuery = ref('')
126+
const filteredGroups = computed(() => {
127+
if (isAdminOrDelegatedAdmin.value) {
128+
return userGroups.value
129+
}
130+
131+
const substring = groupsSearchQuery.value.toLowerCase()
132+
return userGroups.value.filter(group => group.id.toLowerCase().search(substring) !== -1 || group.title.toLowerCase().search(substring) !== -1)
133+
})
122134
123135
const groupListItems = ref([])
124136
const lastGroupListItem = computed(() => {

apps/settings/src/components/Users/NewUserDialog.vue

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
:input-label="t('settings', 'Admin of the following groups')"
8787
:placeholder="t('settings', 'Set account as admin for …')"
8888
:disabled="loading.groups || loading.all"
89-
:options="subAdminsGroups"
89+
:options="availableGroups"
9090
:close-on-select="false"
9191
:multiple="true"
9292
label="name"
@@ -179,7 +179,6 @@ export default {
179179
180180
data() {
181181
return {
182-
availableGroups: [],
183182
possibleManagers: [],
184183
// TRANSLATORS This string describes a manager in the context of an organization
185184
managerInputLabel: t('settings', 'Manager'),
@@ -210,9 +209,12 @@ export default {
210209
return this.$store.getters.getPasswordPolicyMinLength
211210
},
212211
213-
subAdminsGroups() {
214-
// data provided php side
215-
return this.availableGroups.filter(group => group.id !== 'admin' && group.id !== '__nc_internal_recent' && group.id !== 'disabled')
212+
availableGroups() {
213+
const groups = (this.settings.isAdmin || this.settings.isDelegatedAdmin)
214+
? this.$store.getters.getSortedGroups
215+
: this.$store.getters.getSubAdminGroups
216+
217+
return groups.filter(group => group.id !== '__nc_internal_recent' && group.id !== 'disabled')
216218
},
217219
218220
languages() {
@@ -236,13 +238,6 @@ export default {
236238
},
237239
238240
mounted() {
239-
// admins also can assign the system groups
240-
if (this.isAdmin || this.isDelegatedAdmin) {
241-
this.availableGroups = this.$store.getters.getSortedGroups.filter(group => group.id !== '__nc_internal_recent' && group.id !== 'disabled')
242-
} else {
243-
this.availableGroups = [...this.$store.getters.getSubAdminGroups]
244-
}
245-
246241
this.$refs.username?.focus?.()
247242
},
248243
@@ -281,7 +276,7 @@ export default {
281276
},
282277
283278
async searchGroups(query, toggleLoading) {
284-
if (!this.isAdmin && !this.isDelegatedAdmin) {
279+
if (!this.settings.isAdmin && !this.settings.isDelegatedAdmin) {
285280
// managers cannot search for groups
286281
return
287282
}
@@ -297,7 +292,10 @@ export default {
297292
limit: 25,
298293
})
299294
const groups = await this.promise
300-
this.availableGroups = groups
295+
// Populate store from server request
296+
for (const group of groups) {
297+
this.$store.commit('addGroup', group)
298+
}
301299
} catch (error) {
302300
logger.error(t('settings', 'Failed to search groups'), { error })
303301
}
@@ -315,7 +313,6 @@ export default {
315313
this.loading.groups = true
316314
try {
317315
await this.$store.dispatch('addGroup', gid)
318-
this.availableGroups.push({ id: gid, name: gid })
319316
this.newUser.groups.push({ id: gid, name: gid })
320317
} catch (error) {
321318
logger.error(t('settings', 'Failed to create group'), { error })

apps/settings/src/components/Users/UserRow.vue

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,18 @@ export default {
411411
return encodeURIComponent(this.user.id + this.rand)
412412
},
413413
414+
availableGroups() {
415+
const groups = (this.settings.isAdmin || this.settings.isDelegatedAdmin)
416+
? this.$store.getters.getSortedGroups
417+
: this.$store.getters.getSubAdminGroups
418+
419+
return groups.filter(group => group.id !== '__nc_internal_recent' && group.id !== 'disabled')
420+
},
421+
422+
availableSubAdminGroups() {
423+
return this.availableGroups.filter(group => group.id !== 'admin')
424+
},
425+
414426
userGroupsLabels() {
415427
return this.userGroups
416428
.map(group => group.name ?? group.id)
@@ -559,7 +571,11 @@ export default {
559571
this.loading.groupsDetails = true
560572
try {
561573
const groups = await loadUserGroups({ userId: this.user.id })
562-
this.availableGroups = this.availableGroups.map(availableGroup => groups.find(group => group.id === availableGroup.id) ?? availableGroup)
574+
// Populate store from server request
575+
for (const group of groups) {
576+
this.$store.commit('addGroup', group)
577+
}
578+
this.selectedGroups = this.selectedGroups.map(selectedGroup => groups.find(group => group.id === selectedGroup.id) ?? selectedGroup)
563579
} catch (error) {
564580
logger.error(t('settings', 'Failed to load groups with details'), { error })
565581
}
@@ -572,7 +588,11 @@ export default {
572588
this.loading.subAdminGroupsDetails = true
573589
try {
574590
const groups = await loadUserSubAdminGroups({ userId: this.user.id })
575-
this.availableSubAdminGroups = this.availableSubAdminGroups.map(availableGroup => groups.find(group => group.id === availableGroup.id) ?? availableGroup)
591+
// Populate store from server request
592+
for (const group of groups) {
593+
this.$store.commit('addGroup', group)
594+
}
595+
this.selectedSubAdminGroups = this.selectedSubAdminGroups.map(selectedGroup => groups.find(group => group.id === selectedGroup.id) ?? selectedGroup)
576596
} catch (error) {
577597
logger.error(t('settings', 'Failed to load sub admin groups with details'), { error })
578598
}
@@ -595,8 +615,10 @@ export default {
595615
limit: 25,
596616
})
597617
const groups = await this.promise
598-
this.availableGroups = groups
599-
this.availableSubAdminGroups = groups.filter(group => group.id !== 'admin')
618+
// Populate store from server request
619+
for (const group of groups) {
620+
this.$store.commit('addGroup', group)
621+
}
600622
} catch (error) {
601623
logger.error(t('settings', 'Failed to search groups'), { error })
602624
}
@@ -757,8 +779,6 @@ export default {
757779
this.loading.groups = true
758780
try {
759781
await this.$store.dispatch('addGroup', gid)
760-
this.availableGroups.push({ id: gid, name: gid })
761-
this.availableSubAdminGroups.push({ id: gid, name: gid })
762782
const userid = this.user.id
763783
await this.$store.dispatch('addUserGroup', { userid, gid })
764784
this.userGroups.push({ id: gid, name: gid })

apps/settings/src/composables/useGroupsNavigation.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ function formatGroupMenu(group?: IGroup) {
1717
return null
1818
}
1919

20-
const item = {
20+
return {
2121
id: group.id,
2222
title: group.name,
23-
usercount: group.usercount,
24-
count: Math.max(0, group.usercount - group.disabled),
23+
usercount: group.usercount ?? 0,
24+
count: Math.max(0, (group.usercount ?? 0) - (group.disabled ?? 0)),
2525
}
26-
27-
return item
2826
}
2927

3028
export const useFormatGroups = (groups: Ref<IGroup[]>|ComputedRef<IGroup[]>) => {

apps/settings/src/mixins/UserRowMixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export default {
4343
},
4444
data() {
4545
return {
46-
availableGroups: this.user.groups.map(id => ({ id, name: id })),
47-
availableSubAdminGroups: this.user.subadmin.map(id => ({ id, name: id })),
46+
selectedGroups: this.user.groups.map(id => ({ id, name: id })),
47+
selectedSubAdminGroups: this.user.subadmin.map(id => ({ id, name: id })),
4848
userGroups: this.user.groups.map(id => ({ id, name: id })),
4949
userSubAdminGroups: this.user.subadmin.map(id => ({ id, name: id })),
5050
}

dist/settings-users-3239.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-users-3239.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-apps-users-management.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-apps-users-management.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)