fix uploading and more RBAC refinements for auto deploy
This commit is contained in:
@@ -2250,6 +2250,7 @@ export type AutoDeploy = {
|
||||
hideWindow: boolean;
|
||||
enabled: boolean;
|
||||
osFilter: string[];
|
||||
createdByUserId: number | null;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
};
|
||||
@@ -2272,6 +2273,7 @@ function mapAutoDeployRow(row: any): AutoDeploy {
|
||||
hideWindow: row.hide_window === 1,
|
||||
enabled: row.enabled === 1,
|
||||
osFilter,
|
||||
createdByUserId: row.created_by_user_id == null ? null : Number(row.created_by_user_id),
|
||||
createdAt: Number(row.created_at) || 0,
|
||||
updatedAt: Number(row.updated_at) || 0,
|
||||
};
|
||||
@@ -2282,6 +2284,14 @@ export function listAutoDeploys(): AutoDeploy[] {
|
||||
return rows.map(mapAutoDeployRow);
|
||||
}
|
||||
|
||||
export function listAutoDeploysForUser(userId: number, role: string): AutoDeploy[] {
|
||||
if (role === "admin") return listAutoDeploys();
|
||||
const rows = db
|
||||
.query<any>(`SELECT * FROM auto_deploys WHERE created_by_user_id=? ORDER BY created_at DESC`)
|
||||
.all(userId);
|
||||
return rows.map(mapAutoDeployRow);
|
||||
}
|
||||
|
||||
export function getAutoDeploysByTrigger(trigger: AutoDeployTrigger): AutoDeploy[] {
|
||||
const rows = db
|
||||
.query<any>(
|
||||
@@ -2296,6 +2306,14 @@ export function getAutoDeploy(id: string): AutoDeploy | null {
|
||||
return row ? mapAutoDeployRow(row) : null;
|
||||
}
|
||||
|
||||
export function canUserManageAutoDeploy(userId: number, role: string, deployId: string): boolean {
|
||||
if (role === "admin") return true;
|
||||
const row = db
|
||||
.query<{ created_by_user_id: number | null }>(`SELECT created_by_user_id FROM auto_deploys WHERE id=?`)
|
||||
.get(deployId);
|
||||
return row?.created_by_user_id != null && Number(row.created_by_user_id) === userId;
|
||||
}
|
||||
|
||||
export function createAutoDeploy(input: {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -2308,11 +2326,12 @@ export function createAutoDeploy(input: {
|
||||
hideWindow: boolean;
|
||||
enabled: boolean;
|
||||
osFilter: string[];
|
||||
createdByUserId: number;
|
||||
}): AutoDeploy {
|
||||
const now = Date.now();
|
||||
db.run(
|
||||
`INSERT INTO auto_deploys (id, name, trigger, file_path, file_name, file_size, file_os, args, hide_window, enabled, os_filter, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
`INSERT INTO auto_deploys (id, name, trigger, file_path, file_name, file_size, file_os, args, hide_window, enabled, os_filter, created_by_user_id, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
input.id,
|
||||
input.name,
|
||||
input.trigger,
|
||||
@@ -2324,6 +2343,7 @@ export function createAutoDeploy(input: {
|
||||
input.hideWindow ? 1 : 0,
|
||||
input.enabled ? 1 : 0,
|
||||
JSON.stringify(input.osFilter ?? []),
|
||||
input.createdByUserId,
|
||||
now,
|
||||
now,
|
||||
);
|
||||
|
||||
@@ -446,6 +446,7 @@ db.run(`
|
||||
hide_window INTEGER NOT NULL DEFAULT 1,
|
||||
enabled INTEGER NOT NULL,
|
||||
os_filter TEXT NOT NULL DEFAULT '[]',
|
||||
created_by_user_id INTEGER,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
@@ -453,6 +454,15 @@ db.run(`
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_auto_deploys_trigger ON auto_deploys(trigger, enabled);`,
|
||||
);
|
||||
try {
|
||||
const columns = db.query<{ name: string }>(`PRAGMA table_info(auto_deploys)`).all();
|
||||
if (!columns.some((column) => column.name === "created_by_user_id")) {
|
||||
db.run(`ALTER TABLE auto_deploys ADD COLUMN created_by_user_id INTEGER`);
|
||||
}
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_auto_deploys_created_by_user_id ON auto_deploys(created_by_user_id);`,
|
||||
);
|
||||
} catch { /* legacy migration will retry on next startup */ }
|
||||
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS auto_deploy_runs (
|
||||
|
||||
Reference in New Issue
Block a user