From eb8e311d3de7b103bbdb2e6fa633e2ece4a15a29 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 12 Dec 2024 10:15:22 +0700 Subject: [PATCH] fix: regression perm not work as expected after activeOnly opts --- src/services/permission.ts | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/services/permission.ts b/src/services/permission.ts index 8df8f99..941b08e 100644 --- a/src/services/permission.ts +++ b/src/services/permission.ts @@ -40,37 +40,38 @@ export function createPermCondition( ? undefined : [ { - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, - user: { some: { userId: user.sub } }, - }, - { - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, - branch: - opts?.alwaysIncludeHead || globalAllow(user) - ? { - some: { user: { some: { userId: user.sub } } }, - } - : undefined, - }, - { - headOffice: globalAllow(user) - ? { - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, - branch: { - some: { user: { some: { userId: user.sub } } }, - }, - } - : undefined, - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, - }, - { - headOffice: globalAllow(user) - ? { - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, - user: { some: { userId: user.sub } }, - } - : undefined, - status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, + AND: opts?.activeOnly ? { status: { not: Status.INACTIVE } } : undefined, + OR: [ + { + user: { some: { userId: user.sub } }, + }, + { + branch: + opts?.alwaysIncludeHead || globalAllow(user) + ? { + some: { user: { some: { userId: user.sub } } }, + } + : undefined, + }, + { + headOffice: globalAllow(user) + ? { + status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, + branch: { + some: { user: { some: { userId: user.sub } } }, + }, + } + : undefined, + }, + { + headOffice: globalAllow(user) + ? { + status: opts?.activeOnly ? { not: Status.INACTIVE } : undefined, + user: { some: { userId: user.sub } }, + } + : undefined, + }, + ], }, ]; }