16583: Add "Intermediate" to collection type filters
[arvados-workbench2.git] / src / models / user.ts
index b0f004c31e2ad4d450628b3c96c59d7ff27d3545..2857bce6bf14d2f71ad5d5f21bc0dacb9af9e2ad 100644 (file)
@@ -2,7 +2,17 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { Resource, ResourceKind } from '~/models/resource';
+import { Resource, ResourceKind } from 'models/resource';
+
+export type UserPrefs = {
+    profile?: {
+        organization?: string,
+        organization_email?: string,
+        lab?: string,
+        website_url?: string,
+        role?: string
+    }
+};
 
 export interface User {
     email: string;
@@ -10,33 +20,28 @@ export interface User {
     lastName: string;
     uuid: string;
     ownerUuid: string;
+    username: string;
+    prefs: UserPrefs;
     isAdmin: boolean;
+    isActive: boolean;
 }
 
-export const getUserFullname = (user?: User) => {
-    return user ? `${user.firstName} ${user.lastName}` : "";
+export const getUserFullname = (user: User) => {
+    return user.firstName && user.lastName
+        ? `${user.firstName} ${user.lastName}`
+        : "";
+};
+
+export const getUserDisplayName = (user: User, withEmail = false) => {
+    const displayName = getUserFullname(user) || user.email || user.username || user.uuid;
+    if (withEmail && user.email && displayName !== user.email) {
+        return `${displayName} <<${user.email}>>`;
+    }
+    return displayName;
 };
 
-export interface UserResource extends Resource {
+export interface UserResource extends Resource, User {
     kind: ResourceKind.USER;
-    email: string;
-    username: string;
-    firstName: string;
-    lastName: string;
-    identityUrl: string;
-    isAdmin: boolean;
-    prefs: UserPrefs;
     defaultOwnerUuid: string;
-    isActive: boolean;
     writableBy: string[];
 }
-
-export interface UserPrefs {
-    profile: {
-        lab: string;
-        organization: string;
-        organizationEmail: string;
-        role: string;
-        websiteUrl: string;
-    };
-}
\ No newline at end of file