featur eflags
This commit is contained in:
1 parent
bab99059c5
commit
986e8b926a
7 files changed
+88
-30
No files matched your search
@@ -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