[ARVADOS-WORKBENCH2] created: 1.2.1-1015-gc4882a6

Git user git at public.curoverse.com
Thu Nov 29 05:58:54 EST 2018


        at  c4882a6046934f1beea8dc1cc741e690cec357af (commit)


commit c4882a6046934f1beea8dc1cc741e690cec357af
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Thu Nov 29 11:58:40 2018 +0100

    add property isAdmin to the user interface
    
    Feature #14503_keep_services
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/models/user.ts b/src/models/user.ts
index c2f21e5..9f9c534 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -10,6 +10,7 @@ export interface User {
     lastName: string;
     uuid: string;
     ownerUuid: string;
+    isAdmin: boolean;
 }
 
 export const getUserFullname = (user?: User) => {
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 50760bb..dd63de0 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 interface UserDetailsResponse {
     email: string;
@@ -50,15 +51,20 @@ 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 isAdmin = this.getIsAdmin();
 
         return email && firstName && lastName && uuid && ownerUuid
-            ? { email, firstName, lastName, uuid, ownerUuid }
+            ? { email, firstName, lastName, uuid, ownerUuid, isAdmin }
             : undefined;
     }
 
@@ -68,6 +74,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));
     }
 
     public removeUser() {
@@ -76,6 +83,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);
     }
 
     public login() {
@@ -95,12 +103,14 @@ export class AuthService {
             .get<UserDetailsResponse>('/users/current')
             .then(resp => {
                 this.actions.progressFn(reqId, false);
+                console.log('user:', resp.data);
                 return {
                     email: resp.data.email,
                     firstName: resp.data.first_name,
                     lastName: resp.data.last_name,
                     uuid: resp.data.uuid,
-                    ownerUuid: resp.data.owner_uuid
+                    ownerUuid: resp.data.owner_uuid,
+                    isAdmin: resp.data.is_admin
                 };
             })
             .catch(e => {
diff --git a/src/store/auth/auth-reducer.test.ts b/src/store/auth/auth-reducer.test.ts
index 8cde324..3dd486b 100644
--- a/src/store/auth/auth-reducer.test.ts
+++ b/src/store/auth/auth-reducer.test.ts
@@ -29,7 +29,8 @@ describe('auth-reducer', () => {
             firstName: "John",
             lastName: "Doe",
             uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            ownerUuid: "ownerUuid",
+            isAdmin: true
         };
         const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
         expect(state).toEqual({
@@ -58,7 +59,8 @@ describe('auth-reducer', () => {
             firstName: "John",
             lastName: "Doe",
             uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            ownerUuid: "ownerUuid",
+            isAdmin: true
         };
 
         const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
@@ -71,6 +73,7 @@ describe('auth-reducer', () => {
                 lastName: "Doe",
                 uuid: "uuid",
                 ownerUuid: "ownerUuid",
+                isAdmin: true
             }
         });
     });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list