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 {
31 export const getUserFullname = (user: User) => {
32 return user.firstName && user.lastName
33 ? `${user.firstName} ${user.lastName}`
37 export const getUserDisplayName = (user: User, withEmail = false, withUuid = false) => {
38 const displayName = getUserFullname(user) || user.email || user.username || user.uuid;
39 let parts: string[] = [displayName];
40 if (withEmail && user.email && displayName !== user.email) {
41 parts.push(`<${user.email}>`);
44 parts.push(`(${user.uuid})`);
46 return parts.join(' ');
49 export const getUserDetailsString = (user: User) => {
50 let parts: string[] = [];
51 const userCluster = getUserClusterID(user);
52 user.username.length && parts.push(user.username);
53 user.email.length && parts.push(`<${user.email}>`);
54 userCluster && userCluster.length && parts.push(`(${userCluster})`);
55 return parts.join(' ');
58 export const getUserClusterID = (user: User): string | undefined => {
59 const match = RESOURCE_UUID_REGEX.exec(user.uuid);
60 const parts = match ? match[0].split('-') : [];
61 return parts.length === 3 ? parts[0] : undefined;
64 export interface UserResource extends Resource, User {
65 kind: ResourceKind.USER;