X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/6e4ce0e45818dac7d6abc6456e85d49798d16458..8e2f0bc7db026f646c3c08bc10fe4897bda7bdd8:/src/models/user.ts diff --git a/src/models/user.ts b/src/models/user.ts index 514402d8..9b3d97d8 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -2,8 +2,50 @@ // // SPDX-License-Identifier: AGPL-3.0 +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; - apiToken: string; - apiHost: string; + firstName: string; + lastName: string; + uuid: string; + ownerUuid: string; + username: string; + prefs: UserPrefs; + isAdmin: boolean; + isActive: boolean; +} + +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 interface UserResource extends Resource, User { + kind: ResourceKind.USER; + defaultOwnerUuid: string; + writableBy: string[]; }