20452: don't set path if currentItemUuid is not a collection
[arvados-workbench2.git] / src / models / user.ts
index 2857bce6bf14d2f71ad5d5f21bc0dacb9af9e2ad..87a2e8c13d472200bfdd97ebf333ed6defe8f57f 100644 (file)
@@ -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?: {
@@ -32,12 +32,31 @@ export const getUserFullname = (user: User) => {
         : "";
 };
 
-export const getUserDisplayName = (user: User, withEmail = false) => {
+export const getUserDisplayName = (user: User, withEmail = false, withUuid = false) => {
     const displayName = getUserFullname(user) || user.email || user.username || user.uuid;
+    let parts: string[] = [displayName];
     if (withEmail && user.email && displayName !== user.email) {
-        return `${displayName} <<${user.email}>>`;
+        parts.push(`<${user.email}>`);
     }
-    return displayName;
+    if (withUuid) {
+        parts.push(`(${user.uuid})`);
+    }
+    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 {