[ARVADOS-WORKBENCH2] created: 1.2.1-1016-g9c22ff4

Git user git at public.curoverse.com
Thu Nov 29 05:53:12 EST 2018


        at  9c22ff485ae2e065ae705fd5066fda6d508cf236 (commit)


commit 9c22ff485ae2e065ae705fd5066fda6d508cf236
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date:   Thu Nov 29 11:52:54 2018 +0100

    add-isAdmin-to-store
    
    Feature #14498
    
    Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>

diff --git a/package.json b/package.json
index 8945804..c99aa1a 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,7 @@
   "scripts": {
     "start": "react-scripts-ts start",
     "build": "REACT_APP_BUILD_NUMBER=$BUILD_NUMBER REACT_APP_GIT_COMMIT=$GIT_COMMIT react-scripts-ts build",
-    "test": "CI=true react-scripts-ts test --env=jsdom",
+    "test": "react-scripts-ts test --env=jsdom",
     "eject": "react-scripts-ts eject",
     "lint": "tslint src/** -t verbose",
     "build-css": "node-sass-chokidar src/ -o src/",
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..247869e 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 = 'userIsAdmin';
 
 export interface UserDetailsResponse {
     email: string;
@@ -56,9 +57,10 @@ export class AuthService {
         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 = Boolean(localStorage.getItem(USER_IS_ADMIN));
 
-        return email && firstName && lastName && uuid && ownerUuid
-            ? { email, firstName, lastName, uuid, ownerUuid }
+        return email && firstName && lastName && uuid && ownerUuid && isAdmin
+            ? { email, firstName, lastName, uuid, ownerUuid, isAdmin }
             : undefined;
     }
 
@@ -68,6 +70,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() {
@@ -100,7 +103,8 @@ export class AuthService {
                     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-actions.test.ts b/src/store/auth/auth-actions.test.ts
index 231c37b..4f1b3cf 100644
--- a/src/store/auth/auth-actions.test.ts
+++ b/src/store/auth/auth-actions.test.ts
@@ -10,7 +10,8 @@ import {
     USER_FIRST_NAME_KEY,
     USER_LAST_NAME_KEY,
     USER_OWNER_UUID_KEY,
-    USER_UUID_KEY
+    USER_UUID_KEY,
+    USER_IS_ADMIN
 } from "~/services/auth-service/auth-service";
 
 import 'jest-localstorage-mock';
@@ -42,6 +43,7 @@ describe('auth-actions', () => {
         localStorage.setItem(USER_LAST_NAME_KEY, "Doe");
         localStorage.setItem(USER_UUID_KEY, "uuid");
         localStorage.setItem(USER_OWNER_UUID_KEY, "ownerUuid");
+        localStorage.setItem(USER_IS_ADMIN, "isAdmin");
 
         store.dispatch(initAuth());
 
@@ -53,7 +55,8 @@ describe('auth-actions', () => {
                 firstName: "John",
                 lastName: "Doe",
                 uuid: "uuid",
-                ownerUuid: "ownerUuid"
+                ownerUuid: "ownerUuid",
+                isAdmin: true
             }
         });
     });
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
             }
         });
     });
diff --git a/src/store/virtual-machines/virtual-machines-actions.ts b/src/store/virtual-machines/virtual-machines-actions.ts
index 9bd7988..ae75356 100644
--- a/src/store/virtual-machines/virtual-machines-actions.ts
+++ b/src/store/virtual-machines/virtual-machines-actions.ts
@@ -35,7 +35,6 @@ const loadRequestedDate = () =>
         dispatch(virtualMachinesActions.SET_REQUESTED_DATE(date));
     };
 
-
 export const loadVirtualMachinesData = () =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch<any>(loadRequestedDate());
diff --git a/src/views/virtual-machine-panel/virtual-machine-panel.tsx b/src/views/virtual-machine-panel/virtual-machine-panel.tsx
index c94c3a7..5eb9b19 100644
--- a/src/views/virtual-machine-panel/virtual-machine-panel.tsx
+++ b/src/views/virtual-machine-panel/virtual-machine-panel.tsx
@@ -9,7 +9,7 @@ import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/st
 import { ArvadosTheme } from '~/common/custom-theme';
 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
 import { Link } from 'react-router-dom';
-import { Dispatch, compose } from 'redux';
+import { compose } from 'redux';
 import { saveRequestedDate, loadVirtualMachinesData } from '~/store/virtual-machines/virtual-machines-actions';
 import { RootState } from '~/store/store';
 import { ListResults } from '~/services/common-service/common-resource-service';
@@ -58,9 +58,10 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
-const mapStateToProps = ({ virtualMachines }: RootState) => {
+const mapStateToProps = ({ virtualMachines, auth }: RootState) => {
     return {
         requestedDate: virtualMachines.date,
+        isAdmin: auth.user!.isAdmin,
         ...virtualMachines
     };
 };
@@ -75,6 +76,7 @@ interface VirtualMachinesPanelDataProps {
     virtualMachines: ListResults<any>;
     logins: VirtualMachinesLoginsResource[];
     links: ListResults<any>;
+    isAdmin: string;
 }
 
 interface VirtualMachinesPanelActionProps {
@@ -91,12 +93,12 @@ export const VirtualMachinePanel = compose(
             componentDidMount() {
                 this.props.loadVirtualMachinesData();
             }
-
+            
             render() {
-                const { virtualMachines, links } = this.props;
+                const { virtualMachines, links, isAdmin } = this.props;
                 return (
                     <Grid container spacing={16}>
-                        {virtualMachines.itemsAvailable === 0 && <CardContentWithNoVirtualMachines {...this.props} />}
+                        {isAdmin && <CardContentWithNoVirtualMachines {...this.props} />}
                         {virtualMachines.itemsAvailable > 0 && links.itemsAvailable > 0 && <CardContentWithVirtualMachines {...this.props} />}
                         {<CardSSHSection {...this.props} />}
                     </Grid>

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list