blob: 6235088f9443ce4b24fe1abae6b5fd1f8d39f6f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ComputedRef, Ref } from 'vue'
import type { IGroup } from '../views/user-types'
import { computed } from 'vue'
/**
* Format a group to a menu entry
*
* @param group the group
*/
function formatGroupMenu(group?: IGroup) {
if (typeof group === 'undefined') {
return null
}
const item = {
id: group.id,
title: group.name,
usercount: group.usercount,
count: Math.max(0, group.usercount - group.disabled),
}
return item
}
export const useFormatGroups = (groups: Ref<IGroup[]>|ComputedRef<IGroup[]>) => {
/**
* All non-disabled non-admin groups
*/
const userGroups = computed(() => {
const formatted = groups.value
// filter out disabled and admin
.filter(group => group.id !== 'disabled' && group.id !== '__nc_internal_recent' && group.id !== 'admin')
// format group
.map(group => formatGroupMenu(group))
// remove invalid
.filter(group => group !== null)
return formatted as NonNullable<ReturnType<typeof formatGroupMenu>>[]
})
/**
* The admin group if found otherwise null
*/
const adminGroup = computed(() => formatGroupMenu(groups.value.find(group => group.id === 'admin')))
/**
* The group of disabled users
*/
const disabledGroup = computed(() => formatGroupMenu(groups.value.find(group => group.id === 'disabled')))
/**
* The group of recent users
*/
const recentGroup = computed(() => formatGroupMenu(groups.value.find(group => group.id === '__nc_internal_recent')))
return { adminGroup, recentGroup, disabledGroup, userGroups }
}
|