X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c0411a76d1ae1e076dac049267a54366df1c8517..bac1986d6e2506f35283c5ba1c9f19c39ac5dd79:/src/models/user.ts diff --git a/src/models/user.ts b/src/models/user.ts index 9f9c5347..6d66d9d3 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -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,23 +20,40 @@ 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, withUuid = false) => { + const displayName = getUserFullname(user) || user.email || user.username || user.uuid; + let parts: string[] = [displayName]; + if (withEmail && user.email && displayName !== user.email) { + parts.push(`<${user.email}>`); + } + if (withUuid) { + parts.push(`(${user.uuid})`); + } + return parts.join(' '); +}; + +export const getUserDetailsString = (user: User) => { + let parts: string[] = []; + user.username.length && parts.push(user.username); + user.email.length && parts.push(`<${user.email}>`); + user.uuid.length && parts.push(`(${user.uuid})`); + return parts.join(' '); }; -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: string; defaultOwnerUuid: string; - isActive: boolean; writableBy: string[]; -} \ No newline at end of file +}