featur eflags
This commit is contained in:
1 parent
bab99059c5
commit
986e8b926a
7 files changed
+88
-30
No files matched your search
@@ -10,35 +10,63 @@ import {
|
|||||||
LifeBuoy,
|
LifeBuoy,
|
||||||
MessageSquare,
|
MessageSquare,
|
||||||
FileText,
|
FileText,
|
||||||
ScrollText
|
ScrollText,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import type { IUser } from "@/types/user";
|
||||||
|
|
||||||
export const getMenu = (t: Function) => [
|
export const getMenu = (t: Function, user: IUser) => {
|
||||||
{ name: t("menu.uptime"), path: "uptime", icon: <Monitor size={20} strokeWidth={1.5} /> },
|
const userOrgPermissions = user?.org?.permissions || [];
|
||||||
{ name: t("menu.pagespeed"), path: "pagespeed", icon: <Gauge size={20} strokeWidth={1.5} /> },
|
const hasDiagnostics = userOrgPermissions.includes("master");
|
||||||
|
|
||||||
{
|
return [
|
||||||
name: t("menu.infrastructure"),
|
{
|
||||||
path: "infrastructure",
|
name: t("menu.uptime"),
|
||||||
icon: <Server size={20} strokeWidth={1.5} />,
|
path: "uptime",
|
||||||
},
|
icon: <Monitor size={20} strokeWidth={1.5} />,
|
||||||
{
|
},
|
||||||
name: t("menu.notifications"),
|
{
|
||||||
path: "notification-channels",
|
name: t("menu.pagespeed"),
|
||||||
icon: <Bell size={20} strokeWidth={1.5} />,
|
path: "pagespeed",
|
||||||
},
|
icon: <Gauge size={20} strokeWidth={1.5} />,
|
||||||
{ name: t("menu.incidents"), path: "incidents", icon: <AlertTriangle size={20} strokeWidth={1.5} /> },
|
},
|
||||||
|
|
||||||
{ name: t("menu.statusPages"), path: "status-pages", icon: <LayoutList size={20} strokeWidth={1.5} /> },
|
{
|
||||||
{ name: t("menu.maintenance"), path: "maintenance", icon: <Wrench size={20} strokeWidth={1.5} /> },
|
name: t("menu.infrastructure"),
|
||||||
{ name: t("menu.diagnostics"), path: "diagnostics", icon: <Activity size={20} strokeWidth={1.5} /> },
|
path: "infrastructure",
|
||||||
|
icon: <Server size={20} strokeWidth={1.5} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: t("menu.notifications"),
|
||||||
|
path: "notification-channels",
|
||||||
|
icon: <Bell size={20} strokeWidth={1.5} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: t("menu.incidents"),
|
||||||
|
path: "incidents",
|
||||||
|
icon: <AlertTriangle size={20} strokeWidth={1.5} />,
|
||||||
|
},
|
||||||
|
|
||||||
// {
|
{
|
||||||
// name: t("menu.settings"),
|
name: t("menu.statusPages"),
|
||||||
// icon: <Settings />,
|
path: "status-pages",
|
||||||
// path: "settings",
|
icon: <LayoutList size={20} strokeWidth={1.5} />,
|
||||||
// },
|
},
|
||||||
];
|
{
|
||||||
|
name: t("menu.maintenance"),
|
||||||
|
path: "maintenance",
|
||||||
|
icon: <Wrench size={20} strokeWidth={1.5} />,
|
||||||
|
},
|
||||||
|
...(hasDiagnostics
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
name: t("menu.diagnostics"),
|
||||||
|
path: "diagnostics",
|
||||||
|
icon: <Activity size={20} strokeWidth={1.5} />,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
export const getBottomMenu = (t: Function) => [
|
export const getBottomMenu = (t: Function) => [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ export const SideBar = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const sideBarOpen = useAppSelector((state) => state.ui.sidebarOpen);
|
const sideBarOpen = useAppSelector((state) => state.ui.sidebarOpen);
|
||||||
|
const user = useAppSelector((state) => state.auth.user);
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const menu = getMenu(t);
|
const menu = getMenu(t, user);
|
||||||
const bottomMenu = getBottomMenu(t);
|
const bottomMenu = getBottomMenu(t);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import type { DeploymentMode } from "@/utils/FeatureFlags.js";
|
||||||
|
|
||||||
export interface IEnvConfig {
|
export interface IEnvConfig {
|
||||||
NODE_ENV: string;
|
NODE_ENV: string;
|
||||||
|
DEPLOYMENT_MODE: DeploymentMode;
|
||||||
LOG_LEVEL: string;
|
LOG_LEVEL: string;
|
||||||
ORIGIN: string;
|
ORIGIN: string;
|
||||||
JWT_SECRET: string;
|
JWT_SECRET: string;
|
||||||
@@ -17,6 +19,8 @@ dotenv.config();
|
|||||||
|
|
||||||
export const config: IEnvConfig = {
|
export const config: IEnvConfig = {
|
||||||
NODE_ENV: process.env.NODE_ENV || "development",
|
NODE_ENV: process.env.NODE_ENV || "development",
|
||||||
|
DEPLOYMENT_MODE: (process.env.DEPLOYMENT_MODE ||
|
||||||
|
"self_hosted") as DeploymentMode,
|
||||||
LOG_LEVEL: process.env.LOG_LEVEL || "info",
|
LOG_LEVEL: process.env.LOG_LEVEL || "info",
|
||||||
ORIGIN: process.env.ORIGIN || "http://localhost:5173",
|
ORIGIN: process.env.ORIGIN || "http://localhost:5173",
|
||||||
JWT_SECRET: process.env.JWT_SECRET || "your_jwt_secret",
|
JWT_SECRET: process.env.JWT_SECRET || "your_jwt_secret",
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
import ApiError from "@/utils/ApiError.js";
|
import ApiError from "@/utils/ApiError.js";
|
||||||
import { TeamMembership } from "@/db/models/index.js";
|
import { PERMISSIONS } from "@/services/business/AuthService.js";
|
||||||
import type { IRole } from "@/db/models/index.js";
|
|
||||||
export const hasPermission = (
|
export const hasPermission = (
|
||||||
permissions: string[],
|
permissions: string[],
|
||||||
requiredPermissions: string[]
|
requiredPermissions: string[]
|
||||||
) => {
|
) => {
|
||||||
|
if (requiredPermissions.includes(PERMISSIONS.master)) {
|
||||||
|
return permissions.includes(PERMISSIONS.master);
|
||||||
|
}
|
||||||
|
|
||||||
if (permissions.includes("*")) return true;
|
if (permissions.includes("*")) return true;
|
||||||
|
|
||||||
const matches = (requiredPermission: string, userPermission: string) => {
|
const matches = (requiredPermission: string, userPermission: string) => {
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import { DiagnosticController } from "@/controllers/index.js";
|
|||||||
import { verifyToken } from "@/middleware/VerifyToken.js";
|
import { verifyToken } from "@/middleware/VerifyToken.js";
|
||||||
import { verifyOrgPermission } from "@/middleware/VerifyPermission.js";
|
import { verifyOrgPermission } from "@/middleware/VerifyPermission.js";
|
||||||
import { addUserContext } from "@/middleware/AddUserContext.js";
|
import { addUserContext } from "@/middleware/AddUserContext.js";
|
||||||
|
import { FeatureFlags } from "@/utils/FeatureFlags.js";
|
||||||
import { PERMISSIONS } from "@/services/business/AuthService.js";
|
import { PERMISSIONS } from "@/services/business/AuthService.js";
|
||||||
|
|
||||||
class DiagnosticRoutes {
|
class DiagnosticRoutes {
|
||||||
private router;
|
private router;
|
||||||
private controller;
|
private controller;
|
||||||
@@ -18,14 +20,14 @@ class DiagnosticRoutes {
|
|||||||
"/logs",
|
"/logs",
|
||||||
verifyToken,
|
verifyToken,
|
||||||
addUserContext,
|
addUserContext,
|
||||||
verifyOrgPermission([PERMISSIONS.diagnostic.read]),
|
verifyOrgPermission([PERMISSIONS.master]),
|
||||||
this.controller.getLogs
|
this.controller.getLogs
|
||||||
);
|
);
|
||||||
this.router.get(
|
this.router.get(
|
||||||
"/jobs",
|
"/jobs",
|
||||||
verifyToken,
|
verifyToken,
|
||||||
addUserContext,
|
addUserContext,
|
||||||
verifyOrgPermission([PERMISSIONS.diagnostic.read]),
|
verifyOrgPermission([PERMISSIONS.master]),
|
||||||
this.controller.getJobs
|
this.controller.getJobs
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ import { hashPassword } from "@/utils/JWTUtils.js";
|
|||||||
const SERVICE_NAME = "AuthService";
|
const SERVICE_NAME = "AuthService";
|
||||||
|
|
||||||
export const PERMISSIONS = {
|
export const PERMISSIONS = {
|
||||||
|
master: "master",
|
||||||
users: {
|
users: {
|
||||||
all: "users.*",
|
all: "users.*",
|
||||||
write: "users.write",
|
write: "users.write",
|
||||||
read: "users.read",
|
read: "users.read",
|
||||||
delete: "users.delete",
|
delete: "users.delete",
|
||||||
},
|
},
|
||||||
|
|
||||||
monitors: {
|
monitors: {
|
||||||
all: "monitors.*",
|
all: "monitors.*",
|
||||||
write: "monitors.write",
|
write: "monitors.write",
|
||||||
|
|||||||
@@ -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 };
|
||||||
Reference in new issue
Block a user