mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-07 13:08:03 +02:00
fix non admins cant see private resources details in launcher
This commit is contained in:
@@ -28,6 +28,7 @@ import m19 from "./scriptsPg/1.18.4";
|
||||
import m20 from "./scriptsPg/1.19.0";
|
||||
import m21 from "./scriptsPg/1.20.0";
|
||||
import m22 from "./scriptsPg/1.21.0";
|
||||
import m23 from "./scriptsPg/1.21.1";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -55,7 +56,8 @@ const migrations = [
|
||||
{ version: "1.18.4", run: m19 },
|
||||
{ version: "1.19.0", run: m20 },
|
||||
{ version: "1.20.0", run: m21 },
|
||||
{ version: "1.21.0", run: m22 }
|
||||
{ version: "1.21.0", run: m22 },
|
||||
{ version: "1.21.1", run: m23 }
|
||||
// Add new migrations here as they are created
|
||||
] as {
|
||||
version: string;
|
||||
|
||||
@@ -47,6 +47,7 @@ import m41 from "./scriptsSqlite/1.19.0";
|
||||
import m42 from "./scriptsSqlite/1.19.1";
|
||||
import m43 from "./scriptsSqlite/1.20.0";
|
||||
import m44 from "./scriptsSqlite/1.21.0";
|
||||
import m45 from "./scriptsSqlite/1.21.1";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -91,7 +92,8 @@ const migrations = [
|
||||
{ version: "1.19.0", run: m41 },
|
||||
{ version: "1.19.1", run: m42 },
|
||||
{ version: "1.20.0", run: m43 },
|
||||
{ version: "1.21.0", run: m44 }
|
||||
{ version: "1.21.0", run: m44 },
|
||||
{ version: "1.21.1", run: m45 }
|
||||
// Add new migrations here as they are created
|
||||
] as const;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { db } from "@server/db/pg/driver";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
const version = "1.21.1";
|
||||
|
||||
const actionsToGrant = ["getSiteResource", "listSiteResources"] as const;
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
try {
|
||||
await db.execute(sql`BEGIN`);
|
||||
|
||||
for (const actionId of actionsToGrant) {
|
||||
await db.execute(sql`
|
||||
INSERT INTO "roleActions" ("roleId", "actionId", "orgId")
|
||||
SELECT r."roleId", ${actionId}, r."orgId"
|
||||
FROM "roles" r
|
||||
WHERE COALESCE(r."isAdmin", false) = false
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "roleActions" ra
|
||||
WHERE ra."roleId" = r."roleId"
|
||||
AND ra."actionId" = ${actionId}
|
||||
AND ra."orgId" = r."orgId"
|
||||
);
|
||||
`);
|
||||
}
|
||||
|
||||
await db.execute(sql`COMMIT`);
|
||||
console.log(`Finished setup script ${version}`);
|
||||
} catch (e) {
|
||||
await db.execute(sql`ROLLBACK`);
|
||||
console.log("Unable to migrate database");
|
||||
console.log(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { APP_PATH } from "@server/lib/consts";
|
||||
import Database from "better-sqlite3";
|
||||
import path from "path";
|
||||
|
||||
const version = "1.21.1";
|
||||
|
||||
const actionsToGrant = ["getSiteResource", "listSiteResources"] as const;
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
try {
|
||||
db.transaction(() => {
|
||||
const insertRoleAction = db.prepare(`
|
||||
INSERT INTO 'roleActions' ("roleId", "actionId", "orgId")
|
||||
SELECT r."roleId", ?, r."orgId"
|
||||
FROM 'roles' r
|
||||
WHERE COALESCE(r."isAdmin", 0) = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM 'roleActions' ra
|
||||
WHERE ra."roleId" = r."roleId"
|
||||
AND ra."actionId" = ?
|
||||
AND ra."orgId" = r."orgId"
|
||||
);
|
||||
`);
|
||||
|
||||
for (const actionId of actionsToGrant) {
|
||||
insertRoleAction.run(actionId, actionId);
|
||||
}
|
||||
})();
|
||||
|
||||
console.log(`Finished setup script ${version}`);
|
||||
} catch (e) {
|
||||
console.log("Unable to migrate database");
|
||||
console.log(e);
|
||||
throw e;
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user