fix(auth): preserve scoped grants on demotion
This commit is contained in:
parent
85d8db7ece
commit
cc5694449f
|
|
@ -144,19 +144,21 @@ describeEmbeddedPostgres("access routes permissions upgrade compatibility", () =
|
|||
.then((rows) => rows[0]!);
|
||||
const customScope = { projectIds: ["project-1"] };
|
||||
await db.insert(principalPermissionGrants).values([
|
||||
...grantsForHumanRole("admin").map((grant) => ({
|
||||
companyId: company.id,
|
||||
principalType: "user" as const,
|
||||
principalId: member.principalId,
|
||||
permissionKey: grant.permissionKey,
|
||||
scope: grant.scope,
|
||||
grantedByUserId: owner.principalId,
|
||||
})),
|
||||
...grantsForHumanRole("admin")
|
||||
.filter((grant) => grant.permissionKey !== "tools:use")
|
||||
.map((grant) => ({
|
||||
companyId: company.id,
|
||||
principalType: "user" as const,
|
||||
principalId: member.principalId,
|
||||
permissionKey: grant.permissionKey,
|
||||
scope: grant.scope,
|
||||
grantedByUserId: owner.principalId,
|
||||
})),
|
||||
{
|
||||
companyId: company.id,
|
||||
principalType: "user" as const,
|
||||
principalId: member.principalId,
|
||||
permissionKey: "tasks:assign_scope" as const,
|
||||
permissionKey: "tools:use" as const,
|
||||
scope: customScope,
|
||||
grantedByUserId: owner.principalId,
|
||||
},
|
||||
|
|
@ -193,7 +195,7 @@ describeEmbeddedPostgres("access routes permissions upgrade compatibility", () =
|
|||
scope: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
permissionKey: "tasks:assign_scope",
|
||||
permissionKey: "tools:use",
|
||||
scope: customScope,
|
||||
grantedByUserId: owner.principalId,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { and, eq, inArray, ne, notInArray, sql } from "drizzle-orm";
|
||||
import { and, eq, inArray, isNull, ne, notInArray, sql } from "drizzle-orm";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import {
|
||||
companyMemberships,
|
||||
|
|
@ -1137,6 +1137,7 @@ export function accessService(db: Db) {
|
|||
eq(principalPermissionGrants.principalType, "user"),
|
||||
eq(principalPermissionGrants.principalId, existing.principalId),
|
||||
inArray(principalPermissionGrants.permissionKey, retiredDefaultKeys),
|
||||
isNull(principalPermissionGrants.scope),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue