toggle clients with feature flag

This commit is contained in:
miloschwartz 2025-06-26 15:09:16 -04:00
parent 7bf9cccbf6
commit 8f1cfd8037
No known key found for this signature in database
9 changed files with 87 additions and 42 deletions

View file

@ -95,6 +95,10 @@ export class Config {
? "true"
: "false";
process.env.FLAGS_ENABLE_CLIENTS = parsedConfig.flags?.disable_clients
? "true"
: "false";
this.rawConfig = parsedConfig;
}

View file

@ -225,7 +225,8 @@ export const configSchema = z
enable_redis: z.boolean().optional(),
disable_local_sites: z.boolean().optional(),
disable_basic_wireguard_sites: z.boolean().optional(),
disable_config_managed_domains: z.boolean().optional()
disable_config_managed_domains: z.boolean().optional(),
enable_clients: z.boolean().optional()
})
.optional()
})

View file

@ -0,0 +1,29 @@
import { Request, Response, NextFunction } from "express";
import createHttpError from "http-errors";
import HttpCode from "@server/types/HttpCode";
import config from "@server/lib/config";
export async function verifyClientsEnabled(
req: Request,
res: Response,
next: NextFunction
) {
try {
if (!config.getRawConfig().flags?.enable_redis) {
return next(
createHttpError(
HttpCode.NOT_IMPLEMENTED,
"Clients are not enabled on this server."
)
);
}
return next();
} catch (error) {
return next(
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"Failed to check if clients are enabled"
)
);
}
}

View file

@ -41,6 +41,7 @@ import { createNewt, getNewtToken } from "./newt";
import { getOlmToken } from "./olm";
import rateLimit from "express-rate-limit";
import createHttpError from "http-errors";
import { verifyClientsEnabled } from "@server/middlewares/verifyClientsEnabled";
// Root routes
export const unauthenticated = Router();
@ -116,6 +117,7 @@ authenticated.get(
authenticated.get(
"/org/:orgId/pick-client-defaults",
verifyClientsEnabled,
verifyOrgAccess,
verifyUserHasAction(ActionsEnum.createClient),
client.pickClientDefaults
@ -123,6 +125,7 @@ authenticated.get(
authenticated.get(
"/org/:orgId/clients",
verifyClientsEnabled,
verifyOrgAccess,
verifyUserHasAction(ActionsEnum.listClients),
client.listClients
@ -130,6 +133,7 @@ authenticated.get(
authenticated.get(
"/org/:orgId/client/:clientId",
verifyClientsEnabled,
verifyOrgAccess,
verifyUserHasAction(ActionsEnum.getClient),
client.getClient
@ -137,6 +141,7 @@ authenticated.get(
authenticated.put(
"/org/:orgId/client",
verifyClientsEnabled,
verifyOrgAccess,
verifyUserHasAction(ActionsEnum.createClient),
client.createClient
@ -144,6 +149,7 @@ authenticated.put(
authenticated.delete(
"/client/:clientId",
verifyClientsEnabled,
verifyClientAccess,
verifyUserHasAction(ActionsEnum.deleteClient),
client.deleteClient
@ -151,6 +157,7 @@ authenticated.delete(
authenticated.post(
"/client/:clientId",
verifyClientsEnabled,
verifyClientAccess, // this will check if the user has access to the client
verifyUserHasAction(ActionsEnum.updateClient), // this will check if the user has permission to update the client
client.updateClient