X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/92dd5d32b573b5c90f3ce72dc207f6d0e7f21178..4ea2ff188ec745966387ce8bbe14880bfeede863:/src/services/auth-service/auth-service.ts diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index d4e81e42..6faaf99e 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -13,6 +13,7 @@ export const USER_FIRST_NAME_KEY = 'userFirstName'; export const USER_LAST_NAME_KEY = 'userLastName'; export const USER_UUID_KEY = 'userUuid'; export const USER_OWNER_UUID_KEY = 'userOwnerUuid'; +export const USER_IS_ADMIN = 'isAdmin'; export const USER_IDENTITY_URL = 'identityUrl'; export const USER_PREFS = 'prefs'; @@ -54,16 +55,22 @@ export class AuthService { return localStorage.getItem(USER_OWNER_UUID_KEY) || undefined; } + public getIsAdmin(): boolean { + return !!localStorage.getItem(USER_IS_ADMIN); + } + public getUser(): User | undefined { const email = localStorage.getItem(USER_EMAIL_KEY); const firstName = localStorage.getItem(USER_FIRST_NAME_KEY); const lastName = localStorage.getItem(USER_LAST_NAME_KEY); - const uuid = localStorage.getItem(USER_UUID_KEY); - const ownerUuid = localStorage.getItem(USER_OWNER_UUID_KEY); + const uuid = this.getUuid(); + const ownerUuid = this.getOwnerUuid(); + const isAdmin = this.getIsAdmin(); const identityUrl = localStorage.getItem(USER_IDENTITY_URL); const prefs = JSON.parse(localStorage.getItem(USER_PREFS) || '{"profile": {}}'); + return email && firstName && lastName && uuid && ownerUuid && identityUrl && prefs - ? { email, firstName, lastName, uuid, ownerUuid, identityUrl, prefs } + ? { email, firstName, lastName, uuid, ownerUuid, isAdmin, identityUrl, prefs } : undefined; } @@ -73,6 +80,7 @@ export class AuthService { localStorage.setItem(USER_LAST_NAME_KEY, user.lastName); localStorage.setItem(USER_UUID_KEY, user.uuid); localStorage.setItem(USER_OWNER_UUID_KEY, user.ownerUuid); + localStorage.setItem(USER_IS_ADMIN, JSON.stringify(user.isAdmin)); localStorage.setItem(USER_IDENTITY_URL, user.identityUrl); localStorage.setItem(USER_PREFS, JSON.stringify(user.prefs)); } @@ -83,6 +91,7 @@ export class AuthService { localStorage.removeItem(USER_LAST_NAME_KEY); localStorage.removeItem(USER_UUID_KEY); localStorage.removeItem(USER_OWNER_UUID_KEY); + localStorage.removeItem(USER_IS_ADMIN); localStorage.removeItem(USER_IDENTITY_URL); localStorage.removeItem(USER_PREFS); } @@ -112,6 +121,7 @@ export class AuthService { lastName: resp.data.last_name, uuid: resp.data.uuid, ownerUuid: resp.data.owner_uuid, + isAdmin: resp.data.is_admin, identityUrl: resp.data.identity_url, prefs };