From 2c204e6e1c59a598a8c383c01145e424c6d342b5 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 11:10:08 -0700 Subject: [PATCH 1/7] Remove features from demo user --- Client/src/Components/Sidebar/index.jsx | 7 ++++ .../TabPanels/Account/ProfilePanel.jsx | 32 ++++++++++--------- Client/src/Pages/Account/index.jsx | 9 ++++-- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Client/src/Components/Sidebar/index.jsx b/Client/src/Components/Sidebar/index.jsx index c372f8c66..08943807a 100644 --- a/Client/src/Components/Sidebar/index.jsx +++ b/Client/src/Components/Sidebar/index.jsx @@ -90,6 +90,13 @@ function Sidebar() { const [open, setOpen] = useState({ Dashboard: false, Account: false }); const [anchorEl, setAnchorEl] = useState(null); const [popup, setPopup] = useState(); + const { user } = useSelector((state) => state.auth); + + if (!user.role.includes("superadmin")) { + menu[3].nested = menu[3].nested.filter((item) => { + return item.name !== "Password"; + }); + } const openPopup = (event, id) => { setAnchorEl(event.currentTarget); diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index 885c795b1..69c221142 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -331,22 +331,24 @@ const ProfilePanel = () => { borderColor: theme.palette.border.light, }} /> - - - Delete account - - Note that deleting your account will remove all data from our - system. This is permanent and non-recoverable. - + {user.role.includes("superadmin") && ( + + + Delete account + + Note that deleting your account will remove all data from our + system. This is permanent and non-recoverable. + + + - - + )} {/* TODO - Update ModalPopup Component with @mui for reusability */} { const handleTabChange = (event, newTab) => { navigate(`/account/${newTab}`); }; - - let tabList = ["Profile", "Password", "Team"]; const { user } = useSelector((state) => state.auth); + + let tabList = ["Profile", "Team"]; + if (user.role.includes("superadmin")) { + tabList.push("Password"); + } const requiredRoles = ["superadmin", "admin"]; const hideTeams = !requiredRoles.some((role) => user.role.includes(role)); if (hideTeams) { @@ -74,7 +77,7 @@ const Account = ({ open = "profile" }) => { - + {user.role.includes("superadmin") && } {!hideTeams && } From 7c81259e191394b27d154833f914d77b58add61e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 11:25:06 -0700 Subject: [PATCH 2/7] Prefill username and password --- Client/src/Pages/Auth/Login.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Auth/Login.jsx b/Client/src/Pages/Auth/Login.jsx index c8946b7fb..588708261 100644 --- a/Client/src/Pages/Auth/Login.jsx +++ b/Client/src/Pages/Auth/Login.jsx @@ -280,7 +280,7 @@ const StepTwo = ({ form, errors, onSubmit, onChange, onBack }) => { position: "absolute", top: "103%", left: "50%", - transform: "translateX(-50%)" + transform: "translateX(-50%)", }} > { }; const [form, setForm] = useState({ - email: "", - password: "", + email: "uptimedemo@demo.com", + password: "Demouser1!", }); const [errors, setErrors] = useState({}); const [step, setStep] = useState(0); From 63da8bd5718bf02d04783aaa189f95a59ae64c57 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 11:42:05 -0700 Subject: [PATCH 3/7] Add demo role --- Server/models/user.js | 2 +- Server/validation/joi.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/models/user.js b/Server/models/user.js index 829129b4d..888bfd7eb 100644 --- a/Server/models/user.js +++ b/Server/models/user.js @@ -38,7 +38,7 @@ const UserSchema = mongoose.Schema( role: { type: [String], default: "user", - enum: ["user", "admin", "superadmin"], + enum: ["user", "admin", "superadmin", "demo"], }, teamId: { type: mongoose.Schema.Types.ObjectId, diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 417965b95..918400c21 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -70,7 +70,7 @@ const registrationBodyValidation = joi.object({ profileImage: joi.any(), role: joi .array() - .items(joi.string().valid("superadmin", "admin", "user")) + .items(joi.string().valid("superadmin", "admin", "user", "demo")) .min(1) .required(), teamId: joi.string().allow("").required(), From 7f9950b9e56d4b8560ea383bec1363a91ab16b4c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 11:51:55 -0700 Subject: [PATCH 4/7] use demo role to show/hide features --- Client/src/Components/Sidebar/index.jsx | 3 ++- .../src/Components/TabPanels/Account/ProfilePanel.jsx | 2 +- Client/src/Pages/Account/index.jsx | 8 +++++--- Client/src/Pages/Auth/Login.jsx | 5 +++-- README.md | 11 +++++------ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Client/src/Components/Sidebar/index.jsx b/Client/src/Components/Sidebar/index.jsx index 08943807a..27fb35329 100644 --- a/Client/src/Components/Sidebar/index.jsx +++ b/Client/src/Components/Sidebar/index.jsx @@ -92,7 +92,8 @@ function Sidebar() { const [popup, setPopup] = useState(); const { user } = useSelector((state) => state.auth); - if (!user.role.includes("superadmin")) { + // Remove demo password if demo + if (user.role.includes("demo")) { menu[3].nested = menu[3].nested.filter((item) => { return item.name !== "Password"; }); diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index 69c221142..476f47293 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -331,7 +331,7 @@ const ProfilePanel = () => { borderColor: theme.palette.border.light, }} /> - {user.role.includes("superadmin") && ( + {!user.role.includes("demo") && ( Delete account diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index 85150bbd1..eda4d96d8 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -24,9 +24,11 @@ const Account = ({ open = "profile" }) => { }; const { user } = useSelector((state) => state.auth); - let tabList = ["Profile", "Team"]; - if (user.role.includes("superadmin")) { - tabList.push("Password"); + let tabList = ["Profile", "Team", "Password"]; + + // Remove passwrod for demo + if (user.role.includes("demo")) { + tabList = tabList.filter((tab) => tab !== "Password"); } const requiredRoles = ["superadmin", "admin"]; const hideTeams = !requiredRoles.some((role) => user.role.includes(role)); diff --git a/Client/src/Pages/Auth/Login.jsx b/Client/src/Pages/Auth/Login.jsx index 588708261..d3384c0de 100644 --- a/Client/src/Pages/Auth/Login.jsx +++ b/Client/src/Pages/Auth/Login.jsx @@ -15,6 +15,7 @@ import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import PropTypes from "prop-types"; import { logger } from "../../Utils/Logger"; import "./index.css"; +const DEMO = import.meta.env.VITE_APP_DEMO; /** * Displays the initial landing page. @@ -327,8 +328,8 @@ const Login = () => { }; const [form, setForm] = useState({ - email: "uptimedemo@demo.com", - password: "Demouser1!", + email: DEMO !== undefined ? "uptimedemo@demo.com" : "", + password: DEMO !== undefined ? "Demouser1!" : "", }); const [errors, setErrors] = useState({}); const [step, setStep] = useState(0); diff --git a/README.md b/README.md index e050b221e..d396ae397 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,9 @@

An open source server monitoring application

- ![Dashboard-dark](https://github.com/user-attachments/assets/db875138-164f-453c-a75e-889f88747578) (yes, we have a light theme as well, but this looks better on readme.md) - BlueWave Uptime is an open source server monitoring application used to track the operational status and performance of servers and websites. It regularly checks whether a server/website is accessible and performs optimally, providing real-time alerts and reports on the monitored services' availability, downtime, and response time. ## Features @@ -214,10 +212,11 @@ That's it, the application is ready to use on port 80. ##### Environmental Variables -| ENV Variable Name | Required/Optional | Type | Description | Accepted Values | -| --------------------- | ----------------- | -------- | ------------------ | ---------------------------------- | -| VITE_APP_API_BASE_URL | Required | `string` | Base URL of server | {host}/api/v1 | -| VITE_APP_LOG_LEVEL | Optional | `string` | Log level | `"none"`\|`"error"` \| `"warn"` \| | +| ENV Variable Name | Required/Optional | Type | Description | Accepted Values | +| --------------------- | ----------------- | --------- | ------------------ | ---------------------------------- | +| VITE_APP_API_BASE_URL | Required | `string` | Base URL of server | {host}/api/v1 | +| VITE_APP_LOG_LEVEL | Optional | `string` | Log level | `"none"`\|`"error"` \| `"warn"` \| | +| VITE_APP_DEMO | Optional | `boolean` | Demo server or not | `true`\|`false` \| |
From 6fc06ab9b60a3fe3e3d1c31a98754bc2f1133a41 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 11:53:58 -0700 Subject: [PATCH 5/7] Add demo user to role map --- Client/src/Components/TabPanels/Account/TeamPanel.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/src/Components/TabPanels/Account/TeamPanel.jsx b/Client/src/Components/TabPanels/Account/TeamPanel.jsx index 9809ac710..6a15cfeb9 100644 --- a/Client/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/Client/src/Components/TabPanels/Account/TeamPanel.jsx @@ -24,6 +24,7 @@ const TeamPanel = () => { superadmin: "Super admin", admin: "Admin", user: "Team member", + demo: "Demo User", }; const theme = useTheme(); From 00074e039e70b7b8f1d7262f6a1dcd5ac1d3026c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Sep 2024 12:01:58 -0700 Subject: [PATCH 6/7] Simplify tab check --- Client/src/Pages/Account/index.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index eda4d96d8..391d3adc9 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -24,18 +24,18 @@ const Account = ({ open = "profile" }) => { }; const { user } = useSelector((state) => state.auth); - let tabList = ["Profile", "Team", "Password"]; - - // Remove passwrod for demo - if (user.role.includes("demo")) { - tabList = tabList.filter((tab) => tab !== "Password"); - } const requiredRoles = ["superadmin", "admin"]; + let tabList = ["Profile", "Team", "Password"]; const hideTeams = !requiredRoles.some((role) => user.role.includes(role)); if (hideTeams) { tabList = ["Profile", "Password"]; } + // Remove passwrod for demo + if (user.role.includes("demo")) { + tabList = ["Profile"]; + } + return ( Date: Fri, 6 Sep 2024 22:06:48 -0700 Subject: [PATCH 7/7] Update index.jsx fix typo --- Client/src/Pages/Account/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index 391d3adc9..4f5b0c440 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -31,7 +31,7 @@ const Account = ({ open = "profile" }) => { tabList = ["Profile", "Password"]; } - // Remove passwrod for demo + // Remove password for demo if (user.role.includes("demo")) { tabList = ["Profile"]; }