Merge pull request #735 from bluewave-labs/feat/fe/role-restrictions
Feat/fe/role restrictions, resolves #723
This commit is contained in:
6 files changed
+110
-63
No files matched your search
+7
-3
@@ -21,6 +21,7 @@ import ProtectedRoute from "./Components/ProtectedRoute";
|
|||||||
import Details from "./Pages/Monitors/Details";
|
import Details from "./Pages/Monitors/Details";
|
||||||
import Maintenance from "./Pages/Maintenance";
|
import Maintenance from "./Pages/Maintenance";
|
||||||
import withAdminCheck from "./HOC/withAdminCheck";
|
import withAdminCheck from "./HOC/withAdminCheck";
|
||||||
|
import withAdminProp from "./HOC/withAdminProp";
|
||||||
import Configure from "./Pages/Monitors/Configure";
|
import Configure from "./Pages/Monitors/Configure";
|
||||||
import PageSpeed from "./Pages/PageSpeed";
|
import PageSpeed from "./Pages/PageSpeed";
|
||||||
import CreatePageSpeed from "./Pages/PageSpeed/CreatePageSpeed";
|
import CreatePageSpeed from "./Pages/PageSpeed/CreatePageSpeed";
|
||||||
@@ -30,6 +31,9 @@ import PageSpeedConfigure from "./Pages/PageSpeed/Configure";
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const AdminCheckedRegister = withAdminCheck(Register);
|
const AdminCheckedRegister = withAdminCheck(Register);
|
||||||
|
const MonitorsWithAdminProp = withAdminProp(Monitors);
|
||||||
|
const DetailsWithAdminProp = withAdminProp(Details);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Routes>
|
<Routes>
|
||||||
@@ -37,11 +41,11 @@ function App() {
|
|||||||
<Route
|
<Route
|
||||||
exact
|
exact
|
||||||
path="/"
|
path="/"
|
||||||
element={<ProtectedRoute Component={Monitors} />}
|
element={<ProtectedRoute Component={MonitorsWithAdminProp} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors"
|
path="/monitors"
|
||||||
element={<ProtectedRoute Component={Monitors} />}
|
element={<ProtectedRoute Component={MonitorsWithAdminProp} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/create"
|
path="/monitors/create"
|
||||||
@@ -49,7 +53,7 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/:monitorId/"
|
path="/monitors/:monitorId/"
|
||||||
element={<ProtectedRoute Component={Details} />}
|
element={<ProtectedRoute Component={DetailsWithAdminProp} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/monitors/configure/:monitorId/"
|
path="/monitors/configure/:monitorId/"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import "./index.css";
|
|||||||
* @returns {JSX.Element} The rendered fallback UI.
|
* @returns {JSX.Element} The rendered fallback UI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Fallback = ({ title, checks, link = "/" }) => {
|
const Fallback = ({ title, checks, link = "/", isAdmin }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ const Fallback = ({ title, checks, link = "/" }) => {
|
|||||||
/>
|
/>
|
||||||
<Stack gap={theme.gap.small} maxWidth={"275px"} zIndex={1}>
|
<Stack gap={theme.gap.small} maxWidth={"275px"} zIndex={1}>
|
||||||
<Typography component="h1" marginY={theme.gap.medium}>
|
<Typography component="h1" marginY={theme.gap.medium}>
|
||||||
A {title} is used to:
|
A {title} monitor is used to:
|
||||||
</Typography>
|
</Typography>
|
||||||
{checks.map((check, index) => (
|
{checks.map((check, index) => (
|
||||||
<Check
|
<Check
|
||||||
@@ -46,12 +46,14 @@ const Fallback = ({ title, checks, link = "/" }) => {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Button
|
{isAdmin && (
|
||||||
level="primary"
|
<Button
|
||||||
label={`Let's create your ${title}`}
|
level="primary"
|
||||||
sx={{ alignSelf: "center" }}
|
label={`Let's create your ${title}`}
|
||||||
onClick={() => navigate(link)}
|
sx={{ alignSelf: "center" }}
|
||||||
/>
|
onClick={() => navigate(link)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -60,6 +62,7 @@ Fallback.propTypes = {
|
|||||||
title: PropTypes.string.isRequired,
|
title: PropTypes.string.isRequired,
|
||||||
checks: PropTypes.arrayOf(PropTypes.string).isRequired,
|
checks: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
link: PropTypes.string,
|
link: PropTypes.string,
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Fallback;
|
export default Fallback;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
const withAdminProp = (WrappedComponent) => {
|
||||||
|
const WithAdminProp = (props) => {
|
||||||
|
const { user } = useSelector((state) => state.auth);
|
||||||
|
const isAdmin =
|
||||||
|
(user?.role?.includes("admin") ?? false) ||
|
||||||
|
(user?.role?.includes("superadmin") ?? false);
|
||||||
|
|
||||||
|
return <WrappedComponent {...props} isAdmin={isAdmin} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrappedComponentName =
|
||||||
|
WrappedComponent.displayName || WrappedComponent.name || "Component";
|
||||||
|
WithAdminProp.displayName = `WithAdminProp(${wrappedComponentName})`;
|
||||||
|
|
||||||
|
return WithAdminProp;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withAdminProp;
|
||||||
@@ -110,7 +110,7 @@ const SkeletonLayout = () => {
|
|||||||
* Details page component displaying monitor details and related information.
|
* Details page component displaying monitor details and related information.
|
||||||
* @component
|
* @component
|
||||||
*/
|
*/
|
||||||
const DetailsPage = () => {
|
const DetailsPage = ({ isAdmin }) => {
|
||||||
const [monitor, setMonitor] = useState({});
|
const [monitor, setMonitor] = useState({});
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
@@ -196,29 +196,31 @@ const DetailsPage = () => {
|
|||||||
Checking every {formatDurationRounded(monitor?.interval)}.
|
Checking every {formatDurationRounded(monitor?.interval)}.
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Button
|
{isAdmin && (
|
||||||
level="tertiary"
|
<Button
|
||||||
label="Configure"
|
level="tertiary"
|
||||||
animate="rotate90"
|
label="Configure"
|
||||||
img={
|
animate="rotate90"
|
||||||
<SettingsIcon
|
img={
|
||||||
style={{
|
<SettingsIcon
|
||||||
minWidth: theme.gap.mlplus,
|
style={{
|
||||||
minHeight: theme.gap.mlplus,
|
minWidth: theme.gap.mlplus,
|
||||||
}}
|
minHeight: theme.gap.mlplus,
|
||||||
/>
|
}}
|
||||||
}
|
/>
|
||||||
onClick={() => navigate(`/monitors/configure/${monitorId}`)}
|
}
|
||||||
sx={{
|
onClick={() => navigate(`/monitors/configure/${monitorId}`)}
|
||||||
ml: "auto",
|
sx={{
|
||||||
alignSelf: "flex-end",
|
ml: "auto",
|
||||||
backgroundColor: "#f4f4f4",
|
alignSelf: "flex-end",
|
||||||
px: theme.gap.medium,
|
backgroundColor: "#f4f4f4",
|
||||||
"& svg": {
|
px: theme.gap.medium,
|
||||||
mr: "6px",
|
"& svg": {
|
||||||
},
|
mr: "6px",
|
||||||
}}
|
},
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -339,4 +341,7 @@ const DetailsPage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DetailsPage.propTypes = {
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
|
};
|
||||||
export default DetailsPage;
|
export default DetailsPage;
|
||||||
@@ -30,13 +30,14 @@ import Arrow from "../../assets/icons/top-right-arrow.svg?react";
|
|||||||
import ClockSnooze from "../../assets/icons/clock-snooze.svg?react";
|
import ClockSnooze from "../../assets/icons/clock-snooze.svg?react";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const ActionsMenu = ({ monitor }) => {
|
const ActionsMenu = ({ monitor, isAdmin }) => {
|
||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
const [actions, setActions] = useState({});
|
const [actions, setActions] = useState({});
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -121,23 +122,27 @@ const ActionsMenu = ({ monitor }) => {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
{/* TODO - pass monitor id to Incidents page */}
|
{/* TODO - pass monitor id to Incidents page */}
|
||||||
<MenuItem disabled>Incidents</MenuItem>
|
<MenuItem disabled>Incidents</MenuItem>
|
||||||
<MenuItem
|
{isAdmin && (
|
||||||
onClick={(e) => {
|
<MenuItem
|
||||||
e.stopPropagation();
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
navigate(`/monitors/configure/${actions.id}`);
|
navigate(`/monitors/configure/${actions.id}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Configure
|
Configure
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem
|
)}
|
||||||
onClick={(e) => {
|
{isAdmin && (
|
||||||
e.stopPropagation();
|
<MenuItem
|
||||||
openRemove(e);
|
onClick={(e) => {
|
||||||
}}
|
e.stopPropagation();
|
||||||
>
|
openRemove(e);
|
||||||
Remove
|
}}
|
||||||
</MenuItem>
|
>
|
||||||
|
Remove
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
<Modal
|
<Modal
|
||||||
aria-labelledby="modal-delete-monitor"
|
aria-labelledby="modal-delete-monitor"
|
||||||
@@ -205,6 +210,7 @@ ActionsMenu.propTypes = {
|
|||||||
url: PropTypes.string,
|
url: PropTypes.string,
|
||||||
type: PropTypes.string,
|
type: PropTypes.string,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,7 +409,7 @@ const SkeletonLayout = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Monitors = () => {
|
const Monitors = ({ isAdmin }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = useSelector((state) => state.uptimeMonitors);
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
||||||
@@ -483,7 +489,7 @@ const Monitors = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: idx + 4,
|
id: idx + 4,
|
||||||
data: <ActionsMenu monitor={monitor} />,
|
data: <ActionsMenu monitor={monitor} isAdmin={isAdmin} />,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -572,14 +578,16 @@ const Monitors = () => {
|
|||||||
<Typography>
|
<Typography>
|
||||||
It looks like you don’t have any monitors set up yet.
|
It looks like you don’t have any monitors set up yet.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button
|
{isAdmin && (
|
||||||
level="primary"
|
<Button
|
||||||
label="Create your first monitor"
|
level="primary"
|
||||||
onClick={() => {
|
label="Create your first monitor"
|
||||||
navigate("/monitors/create");
|
onClick={() => {
|
||||||
}}
|
navigate("/monitors/create");
|
||||||
sx={{ mt: theme.gap.large }}
|
}}
|
||||||
/>
|
sx={{ mt: theme.gap.large }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@@ -622,4 +630,7 @@ const Monitors = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Monitors.propTypes = {
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
|
};
|
||||||
export default Monitors;
|
export default Monitors;
|
||||||
@@ -123,7 +123,7 @@ const SkeletonLayout = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PageSpeed = () => {
|
const PageSpeed = ({ isAdmin }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -178,10 +178,14 @@ const PageSpeed = () => {
|
|||||||
"Give suggestions on how the page can be improved",
|
"Give suggestions on how the page can be improved",
|
||||||
]}
|
]}
|
||||||
link="/pagespeed/create"
|
link="/pagespeed/create"
|
||||||
|
isAdmin={isAdmin}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
PageSpeed.propTypes = {
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
export default PageSpeed;
|
export default PageSpeed;
|
||||||
Reference in new issue
Block a user