]> git.arvados.org - arvados.git/blob - services/workbench2/src/models/group.ts
23063: combined property chip generation to eliminate duplicate code
[arvados.git] / services / workbench2 / src / models / group.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import {
6     Resource,
7     ResourceKind,
8     ResourceWithProperties,
9     RESOURCE_UUID_REGEX,
10     ResourceObjectType,
11     TrashableResource
12 } from "./resource";
13
14 export interface GroupResource extends TrashableResource, ResourceWithProperties {
15     kind: ResourceKind.GROUP;
16     name: string;
17     groupClass: GroupClass | null;
18     description: string;
19     ensure_unique_name: boolean;
20     canWrite: boolean;
21     canManage: boolean;
22     // Optional local-only field, undefined for not loaded, null for failed to load
23     memberCount?: number | null;
24 }
25
26 export enum GroupClass {
27     PROJECT = 'project',
28     FILTER = 'filter',
29     ROLE = 'role',
30 }
31
32 export enum BuiltinGroups {
33     ALL = 'fffffffffffffff',
34     ANON = 'anonymouspublic',
35     SYSTEM = '000000000000000',
36 }
37
38 export const getBuiltinGroupUuid = (cluster: string, groupName: BuiltinGroups): string => {
39     return cluster ? `${cluster}-${ResourceObjectType.GROUP}-${groupName}` : "";
40 };
41
42 export const isBuiltinGroup = (uuid: string) => {
43     const match = RESOURCE_UUID_REGEX.exec(uuid);
44     const parts = match ? match[0].split('-') : [];
45     return parts.length === 3 && parts[1] === ResourceObjectType.GROUP && Object.values<string>(BuiltinGroups).includes(parts[2]);
46 };
47
48 export const isUserGroup = (resource: any): resource is GroupResource => {
49     return resource && resource.kind === ResourceKind.GROUP && resource.groupClass === GroupClass.ROLE;
50 };
51
52 export const isGroupResource = (resource: Resource): resource is GroupResource => {
53     return resource && resource.kind === ResourceKind.GROUP;
54 };
55
56 export const selectedFieldsOfGroup = [
57     "uuid",
58     "name",
59     "group_class",
60     "description",
61     "properties",
62     "can_write",
63     "can_manage",
64     "trash_at",
65     "delete_at",
66     "is_trashed",
67     "frozen_by_uuid"
68 ];