diff --git a/client/src/components/layouts/sidebar/Menu.tsx b/client/src/components/layouts/sidebar/Menu.tsx
index 37677efaf..f8378faf1 100644
--- a/client/src/components/layouts/sidebar/Menu.tsx
+++ b/client/src/components/layouts/sidebar/Menu.tsx
@@ -10,35 +10,63 @@ import {
LifeBuoy,
MessageSquare,
FileText,
- ScrollText
+ ScrollText,
} from "lucide-react";
+import type { IUser } from "@/types/user";
-export const getMenu = (t: Function) => [
- { name: t("menu.uptime"), path: "uptime", icon: },
- { name: t("menu.pagespeed"), path: "pagespeed", icon: },
+export const getMenu = (t: Function, user: IUser) => {
+ const userOrgPermissions = user?.org?.permissions || [];
+ const hasDiagnostics = userOrgPermissions.includes("master");
- {
- name: t("menu.infrastructure"),
- path: "infrastructure",
- icon: ,
- },
- {
- name: t("menu.notifications"),
- path: "notification-channels",
- icon: ,
- },
- { name: t("menu.incidents"), path: "incidents", icon: },
+ return [
+ {
+ name: t("menu.uptime"),
+ path: "uptime",
+ icon: ,
+ },
+ {
+ name: t("menu.pagespeed"),
+ path: "pagespeed",
+ icon: ,
+ },
- { name: t("menu.statusPages"), path: "status-pages", icon: },
- { name: t("menu.maintenance"), path: "maintenance", icon: },
- { name: t("menu.diagnostics"), path: "diagnostics", icon: },
+ {
+ name: t("menu.infrastructure"),
+ path: "infrastructure",
+ icon: ,
+ },
+ {
+ name: t("menu.notifications"),
+ path: "notification-channels",
+ icon: ,
+ },
+ {
+ name: t("menu.incidents"),
+ path: "incidents",
+ icon: ,
+ },
- // {
- // name: t("menu.settings"),
- // icon: ,
- // path: "settings",
- // },
-];
+ {
+ name: t("menu.statusPages"),
+ path: "status-pages",
+ icon: ,
+ },
+ {
+ name: t("menu.maintenance"),
+ path: "maintenance",
+ icon: ,
+ },
+ ...(hasDiagnostics
+ ? [
+ {
+ name: t("menu.diagnostics"),
+ path: "diagnostics",
+ icon: ,
+ },
+ ]
+ : []),
+ ];
+};
export const getBottomMenu = (t: Function) => [
{
diff --git a/client/src/components/layouts/sidebar/index.tsx b/client/src/components/layouts/sidebar/index.tsx
index 784d703a7..34030d000 100644
--- a/client/src/components/layouts/sidebar/index.tsx
+++ b/client/src/components/layouts/sidebar/index.tsx
@@ -22,10 +22,12 @@ export const SideBar = () => {
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
const sideBarOpen = useAppSelector((state) => state.ui.sidebarOpen);
+ const user = useAppSelector((state) => state.auth.user);
+
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
- const menu = getMenu(t);
+ const menu = getMenu(t, user);
const bottomMenu = getBottomMenu(t);
const dispatch = useAppDispatch();
useEffect(() => {
diff --git a/server/src/config/index.ts b/server/src/config/index.ts
index 18cb52fca..1ffaa95aa 100644
--- a/server/src/config/index.ts
+++ b/server/src/config/index.ts
@@ -1,7 +1,9 @@
import dotenv from "dotenv";
+import type { DeploymentMode } from "@/utils/FeatureFlags.js";
export interface IEnvConfig {
NODE_ENV: string;
+ DEPLOYMENT_MODE: DeploymentMode;
LOG_LEVEL: string;
ORIGIN: string;
JWT_SECRET: string;
@@ -17,6 +19,8 @@ dotenv.config();
export const config: IEnvConfig = {
NODE_ENV: process.env.NODE_ENV || "development",
+ DEPLOYMENT_MODE: (process.env.DEPLOYMENT_MODE ||
+ "self_hosted") as DeploymentMode,
LOG_LEVEL: process.env.LOG_LEVEL || "info",
ORIGIN: process.env.ORIGIN || "http://localhost:5173",
JWT_SECRET: process.env.JWT_SECRET || "your_jwt_secret",
diff --git a/server/src/middleware/VerifyPermission.ts b/server/src/middleware/VerifyPermission.ts
index 657c93024..a44dd10d0 100644
--- a/server/src/middleware/VerifyPermission.ts
+++ b/server/src/middleware/VerifyPermission.ts
@@ -1,11 +1,14 @@
import { Request, Response, NextFunction } from "express";
import ApiError from "@/utils/ApiError.js";
-import { TeamMembership } from "@/db/models/index.js";
-import type { IRole } from "@/db/models/index.js";
+import { PERMISSIONS } from "@/services/business/AuthService.js";
export const hasPermission = (
permissions: string[],
requiredPermissions: string[]
) => {
+ if (requiredPermissions.includes(PERMISSIONS.master)) {
+ return permissions.includes(PERMISSIONS.master);
+ }
+
if (permissions.includes("*")) return true;
const matches = (requiredPermission: string, userPermission: string) => {
diff --git a/server/src/routes/diagnostic.ts b/server/src/routes/diagnostic.ts
index 976d129b5..09203455a 100644
--- a/server/src/routes/diagnostic.ts
+++ b/server/src/routes/diagnostic.ts
@@ -3,7 +3,9 @@ import { DiagnosticController } from "@/controllers/index.js";
import { verifyToken } from "@/middleware/VerifyToken.js";
import { verifyOrgPermission } from "@/middleware/VerifyPermission.js";
import { addUserContext } from "@/middleware/AddUserContext.js";
+import { FeatureFlags } from "@/utils/FeatureFlags.js";
import { PERMISSIONS } from "@/services/business/AuthService.js";
+
class DiagnosticRoutes {
private router;
private controller;
@@ -18,14 +20,14 @@ class DiagnosticRoutes {
"/logs",
verifyToken,
addUserContext,
- verifyOrgPermission([PERMISSIONS.diagnostic.read]),
+ verifyOrgPermission([PERMISSIONS.master]),
this.controller.getLogs
);
this.router.get(
"/jobs",
verifyToken,
addUserContext,
- verifyOrgPermission([PERMISSIONS.diagnostic.read]),
+ verifyOrgPermission([PERMISSIONS.master]),
this.controller.getJobs
);
};
diff --git a/server/src/services/business/AuthService.ts b/server/src/services/business/AuthService.ts
index 6f3a9d27d..34f9b614a 100644
--- a/server/src/services/business/AuthService.ts
+++ b/server/src/services/business/AuthService.ts
@@ -24,13 +24,13 @@ import { hashPassword } from "@/utils/JWTUtils.js";
const SERVICE_NAME = "AuthService";
export const PERMISSIONS = {
+ master: "master",
users: {
all: "users.*",
write: "users.write",
read: "users.read",
delete: "users.delete",
},
-
monitors: {
all: "monitors.*",
write: "monitors.write",
diff --git a/server/src/utils/FeatureFlags.ts b/server/src/utils/FeatureFlags.ts
new file mode 100644
index 000000000..28ce2533c
--- /dev/null
+++ b/server/src/utils/FeatureFlags.ts
@@ -0,0 +1,19 @@
+import { config } from "@/config/index.js";
+import { PERMISSIONS } from "@/services/business/AuthService.js";
+export type DeploymentMode = "saas" | "self_hosted";
+
+const CURRENT_MODE = config.DEPLOYMENT_MODE;
+
+const isSaaS = () => CURRENT_MODE === "saas";
+const isSelfHosted = () => CURRENT_MODE === "self_hosted";
+
+const FeatureFlags = {
+ mode: CURRENT_MODE,
+ isSaaS,
+ isSelfHosted,
+ getDiagnosticPermission(): string {
+ return isSaaS() ? PERMISSIONS.master : PERMISSIONS.diagnostic.read;
+ },
+};
+
+export { FeatureFlags };