diff --git a/packages/service/support/permission/controller.ts b/packages/service/support/permission/controller.ts index bb5a048a6ad8..3924f909ac9f 100644 --- a/packages/service/support/permission/controller.ts +++ b/packages/service/support/permission/controller.ts @@ -47,10 +47,10 @@ export const getResourcePermission = async ({ const tmbPer = ( await MongoResourcePermission.findOne( { - tmbId, - teamId, resourceType, - resourceId + teamId, + resourceId, + tmbId }, 'permission' ).lean() @@ -109,9 +109,9 @@ export async function getResourceAllClbs({ )): Promise { return MongoResourcePermission.find( { - resourceId, resourceType: resourceType, teamId: teamId, + resourceId, groupId: { $exists: false } @@ -131,8 +131,8 @@ export const delResourcePermission = ({ ...props }: { resourceType: PerResourceTypeEnum; - resourceId: string; teamId: string; + resourceId: string; tmbId: string; session?: ClientSession; }) => { diff --git a/packages/service/support/permission/schema.ts b/packages/service/support/permission/schema.ts index e381ba2ea608..c2cf90a5adfd 100644 --- a/packages/service/support/permission/schema.ts +++ b/packages/service/support/permission/schema.ts @@ -44,12 +44,33 @@ try { { resourceType: 1, teamId: 1, - tmbId: 1, resourceId: 1, groupId: 1 }, { - unique: true + unique: true, + partialFilterExpression: { + groupId: { + $exists: true + } + } + } + ); + + ResourcePermissionSchema.index( + { + resourceType: 1, + teamId: 1, + resourceId: 1, + tmbId: 1 + }, + { + unique: true, + partialFilterExpression: { + tmbId: { + $exists: true + } + } } );