Skip to content

Commit e6b8de4

Browse files
authored
Merge pull request #60483 from masskrdjn/fix-hiding-unselectable-groups-in-account-manager
feat: implement isSelectableGroup function to filter out unselectable groups
2 parents 70955fb + f8980da commit e6b8de4

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import NcSelect from '@nextcloud/vue/components/NcSelect'
4747
import logger from '../../logger.ts'
4848
import { searchGroups } from '../../service/groups.ts'
49+
import { isSelectableGroup } from './userFormUtils.ts'
4950
5051
export default {
5152
name: 'UserFormGroups',
@@ -73,7 +74,7 @@ export default {
7374
? this.$store.getters.getSortedGroups
7475
: this.$store.getters.getSubAdminGroups
7576
76-
return groups.filter(({ id }) => id !== '__nc_internal_recent' && id !== 'disabled')
77+
return groups.filter(isSelectableGroup)
7778
},
7879
7980
availableSubAdminGroups() {

apps/settings/src/components/Users/userFormUtils.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { describe, expect, it } from 'vitest'
7-
import { diffPayload, languageFilterBy, resolveLanguage, userToFormData, validateQuota } from './userFormUtils.ts'
7+
import { diffPayload, isSelectableGroup, languageFilterBy, resolveLanguage, userToFormData, validateQuota } from './userFormUtils.ts'
88

99
describe('resolveLanguage', () => {
1010
const serverLanguages = {
@@ -266,6 +266,18 @@ describe('diffPayload', () => {
266266
})
267267
})
268268

269+
describe('isSelectableGroup', () => {
270+
it('allows regular groups in the groups picker', () => {
271+
expect(isSelectableGroup({ id: 'devs', name: 'Developers' })).toBe(true)
272+
})
273+
274+
it('hides internal and guest-only groups from the groups picker', () => {
275+
expect(isSelectableGroup({ id: '__nc_internal_recent', name: 'Recently active' })).toBe(false)
276+
expect(isSelectableGroup({ id: 'disabled', name: 'Disabled accounts' })).toBe(false)
277+
expect(isSelectableGroup({ id: 'guest_app', name: 'Guests' })).toBe(false)
278+
})
279+
})
280+
269281
describe('validateQuota', () => {
270282
const fallback = { id: 'default', label: 'Default quota' }
271283

apps/settings/src/components/Users/userFormUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ interface FormData {
3030
manager: string | { id: string, displayname?: string }
3131
}
3232

33+
const UNSELECTABLE_GROUP_IDS = [
34+
'__nc_internal_recent',
35+
'disabled',
36+
'guest_app',
37+
]
38+
39+
/**
40+
* Whether a group can be offered as a selectable account group option.
41+
*
42+
* @param group Group option
43+
*/
44+
export function isSelectableGroup(group: IGroup): boolean {
45+
return !UNSELECTABLE_GROUP_IDS.includes(group.id)
46+
}
47+
3348
/**
3449
* Resolves the user's language code to a { code, name } object.
3550
*

0 commit comments

Comments
 (0)