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,
|
||||
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: <Monitor size={20} strokeWidth={1.5} /> },
|
||||
{ name: t("menu.pagespeed"), path: "pagespeed", icon: <Gauge size={20} strokeWidth={1.5} /> },
|
||||
export const getMenu = (t: Function, user: IUser) => {
|
||||
const userOrgPermissions = user?.org?.permissions || [];
|
||||
const hasDiagnostics = userOrgPermissions.includes("master");
|
||||
|
||||
{
|
||||
name: t("menu.infrastructure"),
|
||||
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} /> },
|
||||
return [
|
||||
{
|
||||
name: t("menu.uptime"),
|
||||
path: "uptime",
|
||||
icon: <Monitor size={20} strokeWidth={1.5} />,
|
||||
},
|
||||
{
|
||||
name: t("menu.pagespeed"),
|
||||
path: "pagespeed",
|
||||
icon: <Gauge 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.diagnostics"), path: "diagnostics", icon: <Activity size={20} strokeWidth={1.5} /> },
|
||||
{
|
||||
name: t("menu.infrastructure"),
|
||||
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"),
|
||||
// icon: <Settings />,
|
||||
// path: "settings",
|
||||
// },
|
||||
];
|
||||
{
|
||||
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} />,
|
||||
},
|
||||
...(hasDiagnostics
|
||||
? [
|
||||
{
|
||||
name: t("menu.diagnostics"),
|
||||
path: "diagnostics",
|
||||
icon: <Activity size={20} strokeWidth={1.5} />,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
};
|
||||
|
||||
export const getBottomMenu = (t: Function) => [
|
||||
{
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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