mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-05 23:28:44 +00:00
Add tcp and udp specific pages
This commit is contained in:
@@ -519,6 +519,46 @@ export default async function migration() {
|
||||
`);
|
||||
}
|
||||
|
||||
const existingRoleResources = await db.execute(sql`
|
||||
SELECT "roleId"
|
||||
FROM "roleResources"
|
||||
WHERE "resourceId" = ${resource.resourceId}
|
||||
`);
|
||||
for (const roleRow of existingRoleResources.rows as {
|
||||
roleId: number;
|
||||
}[]) {
|
||||
await db.execute(sql`
|
||||
INSERT INTO "rolePolicies" ("roleId", "resourcePolicyId")
|
||||
SELECT ${roleRow.roleId}, ${resourcePolicyId}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM "rolePolicies"
|
||||
WHERE "roleId" = ${roleRow.roleId}
|
||||
AND "resourcePolicyId" = ${resourcePolicyId}
|
||||
)
|
||||
`);
|
||||
}
|
||||
|
||||
const existingUserResources = await db.execute(sql`
|
||||
SELECT "userId"
|
||||
FROM "userResources"
|
||||
WHERE "resourceId" = ${resource.resourceId}
|
||||
`);
|
||||
for (const userRow of existingUserResources.rows as {
|
||||
userId: string;
|
||||
}[]) {
|
||||
await db.execute(sql`
|
||||
INSERT INTO "userPolicies" ("userId", "resourcePolicyId")
|
||||
SELECT ${userRow.userId}, ${resourcePolicyId}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM "userPolicies"
|
||||
WHERE "userId" = ${userRow.userId}
|
||||
AND "resourcePolicyId" = ${resourcePolicyId}
|
||||
)
|
||||
`);
|
||||
}
|
||||
|
||||
await db.execute(sql`
|
||||
DELETE FROM "resourcePincode"
|
||||
WHERE "resourceId" = ${resource.resourceId}
|
||||
|
||||
@@ -32,6 +32,8 @@ export function generateName(): string {
|
||||
return name.replace(/[^a-z0-9-]/g, "");
|
||||
}
|
||||
|
||||
await migration();
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
@@ -456,6 +458,42 @@ export default async function migration() {
|
||||
) VALUES (?, ?)`
|
||||
);
|
||||
|
||||
const selectRoleResources = db.prepare(
|
||||
`SELECT "roleId"
|
||||
FROM 'roleResources'
|
||||
WHERE "resourceId" = ?`
|
||||
);
|
||||
const rolePolicyExists = db.prepare(
|
||||
`SELECT 1
|
||||
FROM 'rolePolicies'
|
||||
WHERE "roleId" = ? AND "resourcePolicyId" = ?
|
||||
LIMIT 1`
|
||||
);
|
||||
const insertRolePolicy = db.prepare(
|
||||
`INSERT INTO 'rolePolicies' (
|
||||
"roleId",
|
||||
"resourcePolicyId"
|
||||
) VALUES (?, ?)`
|
||||
);
|
||||
|
||||
const selectUserResources = db.prepare(
|
||||
`SELECT "userId"
|
||||
FROM 'userResources'
|
||||
WHERE "resourceId" = ?`
|
||||
);
|
||||
const userPolicyExists = db.prepare(
|
||||
`SELECT 1
|
||||
FROM 'userPolicies'
|
||||
WHERE "userId" = ? AND "resourcePolicyId" = ?
|
||||
LIMIT 1`
|
||||
);
|
||||
const insertUserPolicy = db.prepare(
|
||||
`INSERT INTO 'userPolicies' (
|
||||
"userId",
|
||||
"resourcePolicyId"
|
||||
) VALUES (?, ?)`
|
||||
);
|
||||
|
||||
const deleteResourcePincodes = db.prepare(
|
||||
`DELETE FROM 'resourcePincode' WHERE "resourceId" = ?`
|
||||
);
|
||||
@@ -586,6 +624,32 @@ export default async function migration() {
|
||||
);
|
||||
}
|
||||
|
||||
const resourceRoles = selectRoleResources.all(
|
||||
resource.resourceId
|
||||
) as { roleId: number }[];
|
||||
for (const role of resourceRoles) {
|
||||
const exists = rolePolicyExists.get(
|
||||
role.roleId,
|
||||
policyId
|
||||
) as { 1: number } | undefined;
|
||||
if (!exists) {
|
||||
insertRolePolicy.run(role.roleId, policyId);
|
||||
}
|
||||
}
|
||||
|
||||
const resourceUsers = selectUserResources.all(
|
||||
resource.resourceId
|
||||
) as { userId: string }[];
|
||||
for (const user of resourceUsers) {
|
||||
const exists = userPolicyExists.get(
|
||||
user.userId,
|
||||
policyId
|
||||
) as { 1: number } | undefined;
|
||||
if (!exists) {
|
||||
insertUserPolicy.run(user.userId, policyId);
|
||||
}
|
||||
}
|
||||
|
||||
deleteResourcePincodes.run(resource.resourceId);
|
||||
deleteResourcePasswords.run(resource.resourceId);
|
||||
deleteResourceHeaderAuth.run(resource.resourceId);
|
||||
|
||||
Reference in New Issue
Block a user