fix issue with isAdmin for user and modify keep services actions
authorJanicki Artur <artur.janicki@contractors.roche.com>
Mon, 3 Dec 2018 11:06:06 +0000 (12:06 +0100)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Mon, 3 Dec 2018 11:06:06 +0000 (12:06 +0100)
Feature #14503_keep_services_panel

Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki@contractors.roche.com>

src/services/auth-service/auth-service.ts
src/store/keep-services/keep-services-actions.ts
src/store/keep-services/keep-services-reducer.ts

index edc6e24fce752b628a7573899f21af2e6063073b..69e3a79d6a3ffc26db9a10214a3da89ea020f57e 100644 (file)
@@ -52,7 +52,7 @@ export class AuthService {
     }
 
     public getIsAdmin(): boolean {
-        return !!localStorage.getItem(USER_IS_ADMIN);
+        return localStorage.getItem(USER_IS_ADMIN) === 'true';
     }
 
     public getUser(): User | undefined {
index bf7c45ec1c0a2accce7bf7eb134c68f09e559f59..1de6802e7e37c1e8257305e8220289cc02614acc 100644 (file)
@@ -10,11 +10,11 @@ import { ServiceRepository } from "~/services/services";
 import { KeepServiceResource } from '~/models/keep-services';
 import { dialogActions } from '~/store/dialog/dialog-actions';
 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { navigateToRootProject } from '~/store/navigation/navigation-action';
 
 export const keepServicesActions = unionize({
     SET_KEEP_SERVICES: ofType<KeepServiceResource[]>(),
-    REMOVE_KEEP_SERVICE: ofType<string>(),
-    RESET_KEEP_SERVICES: ofType<{}>()
+    REMOVE_KEEP_SERVICE: ofType<string>()
 });
 
 export type KeepServicesActions = UnionOf<typeof keepServicesActions>;
@@ -22,15 +22,20 @@ export type KeepServicesActions = UnionOf<typeof keepServicesActions>;
 export const KEEP_SERVICE_REMOVE_DIALOG = 'keepServiceRemoveDialog';
 export const KEEP_SERVICE_ATTRIBUTES_DIALOG = 'keepServiceAttributesDialog';
 
-// ToDo: access denied for loading keepService and reset data and redirect
 export const loadKeepServicesPanel = () =>
     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        try {
-            dispatch(setBreadcrumbs([{ label: 'Keep Services' }]));
-            const response = await services.keepService.list();
-            dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items));
-        } catch (e) {
-            return;
+        const user = getState().auth.user;
+        if(user && user.isAdmin) {
+            try {
+                dispatch(setBreadcrumbs([{ label: 'Keep Services' }]));
+                const response = await services.keepService.list();
+                dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items));
+            } catch (e) {
+                return;
+            }
+        } else {
+            dispatch(navigateToRootProject);
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000 }));
         }
     };
 
@@ -53,7 +58,6 @@ export const openKeepServiceRemoveDialog = (uuid: string) =>
         }));
     };
 
-// ToDo: access denied for removing keepService and reset data and redirect
 export const removeKeepService = (uuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
index 53ef678d56320b8061731a975d2af3feb495c1de..043c010ab450b7483858dcf53c7d8778b2c74000 100644 (file)
@@ -13,6 +13,5 @@ export const keepServicesReducer = (state: KeepSericesState = initialState, acti
     keepServicesActions.match(action, {
         SET_KEEP_SERVICES: items => items,
         REMOVE_KEEP_SERVICE: (uuid: string) => state.filter((keepService) => keepService.uuid !== uuid),
-        RESET_KEEP_SERVICES: () => [],
         default: () => state
     });
\ No newline at end of file