Skip to content

Commit 4f2d510

Browse files
authored
EQMS-1614 Add separate check method for inverted permissions (#9623)
Signed-off-by: Alexander Onnikov <[email protected]>
1 parent 3f2606b commit 4f2d510

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/core/src/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,27 @@ export async function checkPermission (
568568
const arePermissionsDisabled = getMetadata(core.metadata.DisablePermissions) ?? false
569569
if (arePermissionsDisabled) return true
570570

571+
return await hasPermission(client, _id, _space, space)
572+
}
573+
574+
export async function checkForbiddenPermission (
575+
client: TxOperations,
576+
_id: Ref<Permission>,
577+
_space: Ref<TypedSpace>,
578+
space?: TypedSpace
579+
): Promise<boolean> {
580+
const arePermissionsDisabled = getMetadata(core.metadata.DisablePermissions) ?? false
581+
if (arePermissionsDisabled) return false
582+
583+
return await hasPermission(client, _id, _space, space)
584+
}
585+
586+
async function hasPermission (
587+
client: TxOperations,
588+
_id: Ref<Permission>,
589+
_space: Ref<TypedSpace>,
590+
space?: TypedSpace
591+
): Promise<boolean> {
571592
space = space ?? (await client.findOne(core.class.TypedSpace, { _id: _space }))
572593
const type = await client
573594
.getModel()

plugins/view-resources/src/visibilityTester.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import core, {
1717
checkPermission,
18+
checkForbiddenPermission,
1819
getCurrentAccount,
1920
toIdMap,
2021
AccountRole,
@@ -50,7 +51,7 @@ export async function canDeleteObject (doc?: Doc | Doc[]): Promise<boolean> {
5051
return !(
5152
await Promise.all(
5253
Array.from(targetSpaces.entries()).map(
53-
async (s) => await checkPermission(client, core.permission.ForbidDeleteObject, s[0], s[1])
54+
async (s) => await checkForbiddenPermission(client, core.permission.ForbidDeleteObject, s[0], s[1])
5455
)
5556
)
5657
).some((r) => r)

0 commit comments

Comments
 (0)