From 1e59f131e849b8f57f822b373e743eac0cd2037b Mon Sep 17 00:00:00 2001
From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
Date: Tue, 7 Dec 2021 13:38:36 -0800
Subject: [PATCH] Fix 1299: Tools menu not showing for Heal Only Policy (#1301)
* Fix 1299: Tools menu not showing for Heal Only Policy
* Fix caching issue
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
---
.../src/common/SecureComponent/permissions.ts | 3 +
portal-ui/src/icons/DiagnosticIcon.tsx | 44 -----------
portal-ui/src/icons/DiagnosticsIcon.tsx | 24 ++++--
portal-ui/src/icons/index.ts | 1 -
.../screens/Console/Common/IconsScreen.tsx | 5 --
portal-ui/src/screens/Console/Console.tsx | 3 +
portal-ui/src/screens/Console/Menu/Menu.tsx | 35 +++------
.../Console/Tools/ToolsPanel/ToolsList.tsx | 69 ++++++++++++++++-
portal-ui/src/screens/Console/Tools/utils.tsx | 75 -------------------
portal-ui/src/screens/Console/actions.ts | 14 +++-
portal-ui/src/screens/Console/reducer.ts | 7 +-
11 files changed, 121 insertions(+), 159 deletions(-)
delete mode 100644 portal-ui/src/icons/DiagnosticIcon.tsx
delete mode 100644 portal-ui/src/screens/Console/Tools/utils.tsx
diff --git a/portal-ui/src/common/SecureComponent/permissions.ts b/portal-ui/src/common/SecureComponent/permissions.ts
index 21e62b6d6..4b1950898 100644
--- a/portal-ui/src/common/SecureComponent/permissions.ts
+++ b/portal-ui/src/common/SecureComponent/permissions.ts
@@ -122,6 +122,9 @@ export const IAM_SCOPES = {
ADMIN_DELETE_POLICY: "admin:DeletePolicy",
ADMIN_ATTACH_USER_OR_GROUP_POLICY: "admin:AttachUserOrGroupPolicy",
ADMIN_HEAL_ACTION: "admin:Heal",
+ ADMIN_HEALTH_ACTION: "admin:OBDInfo",
+ ADMIN_CONSOLE_LOG_ACTION: "admin:ConsoleLog",
+ ADMIN_TRACE_ACTION: "admin:ServerTrace",
S3_ALL_ACTIONS: "s3:*",
ADMIN_ALL_ACTIONS: "admin:*",
};
diff --git a/portal-ui/src/icons/DiagnosticIcon.tsx b/portal-ui/src/icons/DiagnosticIcon.tsx
deleted file mode 100644
index 69a998be2..000000000
--- a/portal-ui/src/icons/DiagnosticIcon.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-// This file is part of MinIO Console Server
-// Copyright (c) 2021 MinIO, Inc.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-import * as React from "react";
-import { SVGProps } from "react";
-
-const DiagnosticIcon = (props: SVGProps) => (
-
-);
-
-export default DiagnosticIcon;
diff --git a/portal-ui/src/icons/DiagnosticsIcon.tsx b/portal-ui/src/icons/DiagnosticsIcon.tsx
index 25f130797..e7e776230 100644
--- a/portal-ui/src/icons/DiagnosticsIcon.tsx
+++ b/portal-ui/src/icons/DiagnosticsIcon.tsx
@@ -19,17 +19,25 @@ import React, { SVGProps } from "react";
const DiagnosticsIcon = (props: SVGProps) => {
return (
);
};
diff --git a/portal-ui/src/icons/index.ts b/portal-ui/src/icons/index.ts
index 1a1f58bb8..10aec8ca2 100644
--- a/portal-ui/src/icons/index.ts
+++ b/portal-ui/src/icons/index.ts
@@ -34,7 +34,6 @@ export { default as CopyIcon } from "./CopyIcon";
export { default as CreateIcon } from "./CreateIcon";
export { default as DashboardIcon } from "./DashboardIcon";
export { default as DeleteIcon } from "./DeleteIcon";
-export { default as DiagnosticIcon } from "./DiagnosticIcon";
export { default as DiagnosticsIcon } from "./DiagnosticsIcon";
export { default as DocumentationIcon } from "./DocumentationIcon";
export { default as DownloadIcon } from "./DownloadIcon";
diff --git a/portal-ui/src/screens/Console/Common/IconsScreen.tsx b/portal-ui/src/screens/Console/Common/IconsScreen.tsx
index f4294bbf2..e9c06127a 100644
--- a/portal-ui/src/screens/Console/Common/IconsScreen.tsx
+++ b/portal-ui/src/screens/Console/Common/IconsScreen.tsx
@@ -41,7 +41,6 @@ import {
CreateIcon,
DashboardIcon,
DeleteIcon,
- DiagnosticIcon,
DiagnosticsIcon,
DocumentationIcon,
DownloadIcon,
@@ -225,10 +224,6 @@ const IconsScreen = ({ classes }: IIconsScreenSimple) => {
DeleteIcon
-
-
- DiagnosticIcon
-
DiagnosticsIcon
diff --git a/portal-ui/src/screens/Console/Console.tsx b/portal-ui/src/screens/Console/Console.tsx
index 8f2002301..bc005078d 100644
--- a/portal-ui/src/screens/Console/Console.tsx
+++ b/portal-ui/src/screens/Console/Console.tsx
@@ -270,6 +270,9 @@ const Console = ({
const allowedPages = !session
? []
: session.pages.reduce((result: any, item: any, index: any) => {
+ if (item.startsWith("/tools")) {
+ result["/tools"] = true;
+ }
result[item] = true;
return result;
}, {});
diff --git a/portal-ui/src/screens/Console/Menu/Menu.tsx b/portal-ui/src/screens/Console/Menu/Menu.tsx
index fadc4e0e2..e74032acd 100644
--- a/portal-ui/src/screens/Console/Menu/Menu.tsx
+++ b/portal-ui/src/screens/Console/Menu/Menu.tsx
@@ -42,14 +42,12 @@ import api from "../../../common/api";
import MenuIcon from "@mui/icons-material/Menu";
import LogoutIcon from "../../../icons/LogoutIcon";
+import { resetSession } from "../actions";
const drawerWidth = 245;
const BucketsIcon = React.lazy(() => import("../../../icons/BucketsIcon"));
const DashboardIcon = React.lazy(() => import("../../../icons/DashboardIcon"));
-const DiagnosticsIcon = React.lazy(
- () => import("../../../icons/DiagnosticsIcon")
-);
const GroupsIcon = React.lazy(() => import("../../../icons/GroupsIcon"));
const IAMPoliciesIcon = React.lazy(
() => import("../../../icons/IAMPoliciesIcon")
@@ -61,7 +59,6 @@ const UsersIcon = React.lazy(() => import("../../../icons/UsersIcon"));
const VersionIcon = React.lazy(() => import("../../../icons/VersionIcon"));
const LicenseIcon = React.lazy(() => import("../../../icons/LicenseIcon"));
-const HealIcon = React.lazy(() => import("../../../icons/HealIcon"));
const AccountIcon = React.lazy(() => import("../../../icons/AccountIcon"));
const DocumentationIcon = React.lazy(
() => import("../../../icons/DocumentationIcon")
@@ -290,6 +287,7 @@ interface IMenuProps {
distributedSetup: boolean;
sidebarOpen: boolean;
setMenuOpen: typeof setMenuOpen;
+ resetSession: typeof resetSession;
}
const Menu = ({
@@ -300,13 +298,14 @@ const Menu = ({
distributedSetup,
sidebarOpen,
setMenuOpen,
+ resetSession,
}: IMenuProps) => {
const logout = () => {
const deleteSession = () => {
clearSession();
userLoggedIn(false);
localStorage.setItem("userLoggedIn", "");
-
+ resetSession();
history.push("/login");
};
api
@@ -402,23 +401,6 @@ const Menu = ({
name: "Tools",
icon: ToolsIcon,
},
- {
- group: "Tools",
- type: "item",
- component: NavLink,
- to: "/heal",
- name: "Heal",
- icon: HealIcon,
- fsHidden: distributedSetup,
- },
- {
- group: "Tools",
- type: "item",
- component: NavLink,
- to: "/health-info",
- name: "Diagnostic",
- icon: DiagnosticsIcon,
- },
{
group: "Operator",
type: "item",
@@ -438,6 +420,9 @@ const Menu = ({
];
const allowedPages = pages.reduce((result: any, item: any) => {
+ if (item.startsWith("/tools")) {
+ result["/tools"] = true;
+ }
result[item] = true;
return result;
}, {});
@@ -643,6 +628,10 @@ const mapState = (state: AppState) => ({
distributedSetup: state.system.distributedSetup,
});
-const connector = connect(mapState, { userLoggedIn, setMenuOpen });
+const connector = connect(mapState, {
+ userLoggedIn,
+ setMenuOpen,
+ resetSession,
+});
export default connector(withStyles(styles)(Menu));
diff --git a/portal-ui/src/screens/Console/Tools/ToolsPanel/ToolsList.tsx b/portal-ui/src/screens/Console/Tools/ToolsPanel/ToolsList.tsx
index b4d8a3069..e78a6a16c 100644
--- a/portal-ui/src/screens/Console/Tools/ToolsPanel/ToolsList.tsx
+++ b/portal-ui/src/screens/Console/Tools/ToolsPanel/ToolsList.tsx
@@ -20,7 +20,6 @@ import createStyles from "@mui/styles/createStyles";
import withStyles from "@mui/styles/withStyles";
import Grid from "@mui/material/Grid";
-import { configurationElements } from "../utils";
import {
actionsTray,
containerForHeader,
@@ -29,6 +28,21 @@ import {
import PageHeader from "../../Common/PageHeader/PageHeader";
import SettingsCard from "../../Common/SettingsCard/SettingsCard";
import PageLayout from "../../Common/Layout/PageLayout";
+import { IElement } from "../types";
+import {
+ DiagnosticsIcon,
+ HealIcon,
+ LogsIcon,
+ SearchIcon,
+ TraceIcon,
+ WatchIcon,
+} from "../../../../icons";
+import { hasPermission } from "../../../../common/SecureComponent/SecureComponent";
+import {
+ CONSOLE_UI_RESOURCE,
+ IAM_SCOPES,
+} from "../../../../common/SecureComponent/permissions";
+import SpeedtestIcon from "../../../../icons/SpeedtestIcon";
interface IConfigurationOptions {
classes: any;
@@ -76,6 +90,59 @@ const styles = (theme: Theme) =>
});
const ToolsList = ({ classes }: IConfigurationOptions) => {
+ const configurationElements: IElement[] = [
+ {
+ icon: ,
+ configuration_id: "logs",
+ configuration_label: "Logs",
+ disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
+ IAM_SCOPES.ADMIN_CONSOLE_LOG_ACTION,
+ ]),
+ },
+ {
+ icon: ,
+ configuration_id: "audit-logs",
+ configuration_label: "Audit Logs",
+ },
+ {
+ icon: ,
+ configuration_id: "watch",
+ configuration_label: "Watch",
+ },
+ {
+ icon: ,
+ configuration_id: "trace",
+ configuration_label: "trace",
+ disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
+ IAM_SCOPES.ADMIN_TRACE_ACTION,
+ ]),
+ },
+ {
+ icon: ,
+ configuration_id: "heal",
+ configuration_label: "heal",
+ disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
+ IAM_SCOPES.ADMIN_HEAL_ACTION,
+ ]),
+ },
+ {
+ icon: ,
+ configuration_id: "diagnostics",
+ configuration_label: "Diagnostics",
+ disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
+ IAM_SCOPES.ADMIN_HEALTH_ACTION,
+ ]),
+ },
+ {
+ icon: ,
+ configuration_id: "speedtest",
+ configuration_label: "Speedtest",
+ disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
+ IAM_SCOPES.ADMIN_HEAL_ACTION,
+ ]),
+ },
+ ];
+
return (
diff --git a/portal-ui/src/screens/Console/Tools/utils.tsx b/portal-ui/src/screens/Console/Tools/utils.tsx
deleted file mode 100644
index f38f11863..000000000
--- a/portal-ui/src/screens/Console/Tools/utils.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-// This file is part of MinIO Console Server
-// Copyright (c) 2021 MinIO, Inc.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-import React from "react";
-import { IElement } from "./types";
-import {
- DiagnosticsIcon,
- HealIcon,
- LogsIcon,
- SearchIcon,
- TraceIcon,
- WatchIcon,
-} from "../../../icons";
-import SpeedtestIcon from "../../../icons/SpeedtestIcon";
-import {
- CONSOLE_UI_RESOURCE,
- IAM_SCOPES,
-} from "../../../common/SecureComponent/permissions";
-import { hasPermission } from "../../../common/SecureComponent/SecureComponent";
-
-export const configurationElements: IElement[] = [
- {
- icon: ,
- configuration_id: "logs",
- configuration_label: "Logs",
- },
- {
- icon: ,
- configuration_id: "audit-logs",
- configuration_label: "Audit Logs",
- },
- {
- icon: ,
- configuration_id: "watch",
- configuration_label: "Watch",
- },
- {
- icon: ,
- configuration_id: "trace",
- configuration_label: "trace",
- },
- {
- icon: ,
- configuration_id: "heal",
- configuration_label: "heal",
- disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
- IAM_SCOPES.ADMIN_HEAL_ACTION,
- ]),
- },
- {
- icon: ,
- configuration_id: "diagnostics",
- configuration_label: "Diagnostics",
- },
- {
- icon: ,
- configuration_id: "speedtest",
- configuration_label: "Speedtest",
- disabled: !hasPermission(CONSOLE_UI_RESOURCE, [
- IAM_SCOPES.ADMIN_HEAL_ACTION,
- ]),
- },
-];
diff --git a/portal-ui/src/screens/Console/actions.ts b/portal-ui/src/screens/Console/actions.ts
index 216028838..cf79864d3 100644
--- a/portal-ui/src/screens/Console/actions.ts
+++ b/portal-ui/src/screens/Console/actions.ts
@@ -17,12 +17,18 @@
import { ISessionResponse } from "./types";
export const SESSION_RESPONSE = "SESSION_RESPONSE";
+export const RESET_SESSION = "RESET_SESSION";
interface SessionAction {
type: typeof SESSION_RESPONSE;
message: ISessionResponse;
}
-export type SessionActionTypes = SessionAction;
+
+interface ResetSessionAction {
+ type: typeof RESET_SESSION;
+}
+
+export type SessionActionTypes = SessionAction | ResetSessionAction;
export function saveSessionResponse(message: ISessionResponse) {
return {
@@ -30,3 +36,9 @@ export function saveSessionResponse(message: ISessionResponse) {
message: message,
};
}
+
+export function resetSession() {
+ return {
+ type: RESET_SESSION,
+ };
+}
diff --git a/portal-ui/src/screens/Console/reducer.ts b/portal-ui/src/screens/Console/reducer.ts
index 1af137ad5..e592e078e 100644
--- a/portal-ui/src/screens/Console/reducer.ts
+++ b/portal-ui/src/screens/Console/reducer.ts
@@ -15,7 +15,7 @@
// along with this program. If not, see .
import { ISessionResponse } from "./types";
-import { SessionActionTypes, SESSION_RESPONSE } from "./actions";
+import { RESET_SESSION, SESSION_RESPONSE, SessionActionTypes } from "./actions";
export interface ConsoleState {
session: ISessionResponse;
@@ -42,6 +42,11 @@ export function consoleReducer(
...state,
session: action.message,
};
+ case RESET_SESSION:
+ return {
+ ...state,
+ session: initialState.session,
+ };
default:
return state;
}