1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Resource, ResourceKind, RESOURCE_UUID_REGEX } from 'models/resource';
7 export type UserPrefs = {
10 organization_email?: string,
17 export interface User {
29 export const getUserFullname = (user: User) => {
30 return user.firstName && user.lastName
31 ? `${user.firstName} ${user.lastName}`
35 export const getUserDisplayName = (user: User, withEmail = false, withUuid = false) => {
36 const displayName = getUserFullname(user) || user.email || user.username || user.uuid;
37 let parts: string[] = [displayName];
38 if (withEmail && user.email && displayName !== user.email) {
39 parts.push(`<${user.email}>`);
42 parts.push(`(${user.uuid})`);
44 return parts.join(' ');
47 export const getUserDetailsString = (user: User) => {
48 let parts: string[] = [];
49 const userCluster = getUserClusterID(user);
50 user.username.length && parts.push(user.username);
51 user.email.length && parts.push(`<${user.email}>`);
52 userCluster && userCluster.length && parts.push(`(${userCluster})`);
53 return parts.join(' ');
56 export const getUserClusterID = (user: User): string | undefined => {
57 const match = RESOURCE_UUID_REGEX.exec(user.uuid);
58 const parts = match ? match[0].split('-') : [];
59 return parts.length === 3 ? parts[0] : undefined;
62 export interface UserResource extends Resource, User {
63 kind: ResourceKind.USER;
64 defaultOwnerUuid: string;