mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-06 19:23:26 +02:00
chore: simplify policy rule update/delete lookups
This commit is contained in:
committed by
GitHub
parent
a7c99f336f
commit
0bde633c5f
@@ -74,13 +74,15 @@ export async function deleteResourceRule(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resource.resourcePolicyId !== null) {
|
if (resource.resourcePolicyId !== null) {
|
||||||
const policyId = resource.resourcePolicyId;
|
|
||||||
const [deletedRule] = await db
|
const [deletedRule] = await db
|
||||||
.delete(resourcePolicyRules)
|
.delete(resourcePolicyRules)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(resourcePolicyRules.ruleId, ruleId),
|
eq(resourcePolicyRules.ruleId, ruleId),
|
||||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
eq(
|
||||||
|
resourcePolicyRules.resourcePolicyId,
|
||||||
|
resource.resourcePolicyId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -151,16 +151,17 @@ export async function updateResourceRule(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const policyId = resource.resourcePolicyId;
|
if (resource.resourcePolicyId !== null) {
|
||||||
|
|
||||||
if (policyId !== null) {
|
|
||||||
const [existingRule] = await db
|
const [existingRule] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(resourcePolicyRules)
|
.from(resourcePolicyRules)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(resourcePolicyRules.ruleId, ruleId),
|
eq(resourcePolicyRules.ruleId, ruleId),
|
||||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
eq(
|
||||||
|
resourcePolicyRules.resourcePolicyId,
|
||||||
|
resource.resourcePolicyId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -195,7 +196,10 @@ export async function updateResourceRule(
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(resourcePolicyRules.ruleId, ruleId),
|
eq(resourcePolicyRules.ruleId, ruleId),
|
||||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
eq(
|
||||||
|
resourcePolicyRules.resourcePolicyId,
|
||||||
|
resource.resourcePolicyId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
Reference in New Issue
Block a user