fix: permission condition
This commit is contained in:
parent
4036a36236
commit
ea72b1a1bb
1 changed files with 3 additions and 10 deletions
|
|
@ -12,6 +12,7 @@ export function branchRelationPermInclude(user: RequestWithUser["user"]) {
|
|||
user: { where: { userId: user.sub } },
|
||||
},
|
||||
},
|
||||
branch: { where: { user: { some: { userId: user.sub } } } },
|
||||
user: { where: { userId: user.sub } },
|
||||
};
|
||||
}
|
||||
|
|
@ -43,15 +44,7 @@ export function createPermCondition(globalAllow: (user: RequestWithUser["user"])
|
|||
|
||||
export async function getBranchPermissionCheck(user: RequestWithUser["user"], branchId: string) {
|
||||
return await prisma.branch.findUnique({
|
||||
include: {
|
||||
headOffice: {
|
||||
include: {
|
||||
branch: { where: { user: { some: { userId: user.sub } } } },
|
||||
user: { where: { userId: user.sub } },
|
||||
},
|
||||
},
|
||||
user: { where: { userId: user.sub } },
|
||||
},
|
||||
include: branchRelationPermInclude(user),
|
||||
where: { id: branchId },
|
||||
});
|
||||
}
|
||||
|
|
@ -78,7 +71,7 @@ export function createPermCheck(globalAllow: (user: RequestWithUser["user"]) =>
|
|||
);
|
||||
} else {
|
||||
if (
|
||||
(branch.user.length === 0 && !branch.headOffice) ||
|
||||
(branch.user.length === 0 && branch.branch.length === 0 && !branch.headOffice) ||
|
||||
(branch.headOffice &&
|
||||
branch.headOffice.user.length === 0 &&
|
||||
branch.headOffice.branch.length === 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue