Extend tenant maintenance lock for imports
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 27s
Build and Push Docker Images / build-frontend (push) Successful in 1m11s
Build and Push Docker Images / build-website (push) Successful in 18s
Build and Push Docker Images / build-docs (push) Successful in 16s

This commit is contained in:
2026-07-14 11:40:48 +02:00
parent ee7d3d3afc
commit a945aaffe3
8 changed files with 253 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ import {
authRolePermissions,
authUsers,
m2mApiKeys,
tenants,
} from "../../db/schema"
import { eq, and, inArray } from "drizzle-orm"
@@ -23,6 +24,19 @@ export default fp(async (server: FastifyInstance) => {
url === "/api/mcp" ||
url.startsWith("/api/mcp/")
const isWriteMethod = (method: string) =>
["POST", "PUT", "PATCH", "DELETE"].includes(method)
const isTenantLockAllowedRoute = (urlPath: string) =>
urlPath === "/api/auth/me" ||
urlPath === "/auth/me" ||
urlPath === "/api/tenant/switch" ||
urlPath === "/tenant/switch" ||
urlPath.startsWith("/api/admin/") ||
urlPath.startsWith("/admin/") ||
urlPath.startsWith("/api/auth/") ||
urlPath.startsWith("/auth/")
const authenticateMcpApiKey = async (apiKey: string) => {
if (!apiKey.startsWith("fedeo_mcp_")) return false
@@ -150,6 +164,25 @@ export default fp(async (server: FastifyInstance) => {
const tenantId = req.user.tenant_id
const userId = req.user.user_id
if (isWriteMethod(req.method) && !isTenantLockAllowedRoute(urlPath)) {
const [tenant] = await server.db
.select({
locked: tenants.locked,
lockedByExportJobId: tenants.lockedByExportJobId,
})
.from(tenants)
.where(eq(tenants.id, tenantId))
.limit(1)
if (tenant?.locked === "maintenance_tenant") {
return reply.code(423).send({
error: "Tenant is locked for maintenance",
locked: tenant.locked,
lockedByExportJobId: tenant.lockedByExportJobId,
})
}
}
// --------------------------------------------------------
// 3⃣ Rollen des Nutzers im Tenant holen
// --------------------------------------------------------