Filter build list by user: non-admins only see their own builds

This commit is contained in:
unknown
2026-03-16 13:42:13 +01:00
parent 4b8a459d04
commit c8c45fe565
4 changed files with 18 additions and 2 deletions
+1
View File
@@ -6,6 +6,7 @@ export type BuildStream = {
expiresAt: number; expiresAt: number;
files: { name: string; size: number; platform?: string }[]; files: { name: string; size: number; platform?: string }[];
updates?: any[]; updates?: any[];
userId?: number;
}; };
export type BuildConfig = { export type BuildConfig = {
+15 -1
View File
@@ -651,7 +651,21 @@ export function getBuildByTag(buildTag: string): BuildRecord | null {
}; };
} }
export function getAllBuilds(): BuildRecord[] { export function getAllBuilds(userId?: number, role?: string): BuildRecord[] {
if (role !== "admin" && userId != null) {
const rows = db
.query<any>(`SELECT * FROM builds WHERE built_by_user_id = ? ORDER BY start_time DESC`)
.all(userId);
return rows.map((row) => ({
id: row.id,
status: row.status,
startTime: row.start_time,
expiresAt: row.expires_at,
files: JSON.parse(row.files),
buildTag: row.build_tag || undefined,
builtByUserId: row.built_by_user_id || undefined,
}));
}
const rows = db const rows = db
.query<any>(`SELECT * FROM builds ORDER BY start_time DESC`) .query<any>(`SELECT * FROM builds ORDER BY start_time DESC`)
.all(); .all();
@@ -102,6 +102,7 @@ export async function startBuildProcess(
startTime: now, startTime: now,
expiresAt: now + SEVEN_DAYS_MS, expiresAt: now + SEVEN_DAYS_MS,
files: [], files: [],
userId: config.builtByUserId,
}; };
buildManager.addBuildStream(buildId, build); buildManager.addBuildStream(buildId, build);
@@ -141,7 +141,7 @@ export async function handleBuildRoutes(
if (req.method === "GET" && url.pathname === "/api/build/list") { if (req.method === "GET" && url.pathname === "/api/build/list") {
requirePermission(user, "clients:build"); requirePermission(user, "clients:build");
const builds = getAllBuilds(); const builds = getAllBuilds(user.userId, user.role);
return Response.json({ builds }); return Response.json({ builds });
} }