X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a672dd5efb4c8ef394f61a7e7a5e513f80bf1427..2a7fd99c212c33a1ec9911f8529fa5afc59a7bb2:/src/models/user.ts diff --git a/src/models/user.ts b/src/models/user.ts index 9b3d97d848..87a2e8c13d 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Resource, ResourceKind } from 'models/resource'; +import { Resource, ResourceKind, RESOURCE_UUID_REGEX } from 'models/resource'; export type UserPrefs = { profile?: { @@ -44,6 +44,21 @@ export const getUserDisplayName = (user: User, withEmail = false, withUuid = fal return parts.join(' '); }; +export const getUserDetailsString = (user: User) => { + let parts: string[] = []; + const userCluster = getUserClusterID(user); + user.username.length && parts.push(user.username); + user.email.length && parts.push(`<${user.email}>`); + userCluster && userCluster.length && parts.push(`(${userCluster})`); + return parts.join(' '); +}; + +export const getUserClusterID = (user: User): string | undefined => { + const match = RESOURCE_UUID_REGEX.exec(user.uuid); + const parts = match ? match[0].split('-') : []; + return parts.length === 3 ? parts[0] : undefined; +}; + export interface UserResource extends Resource, User { kind: ResourceKind.USER; defaultOwnerUuid: string;