feat: filter view by role
This commit is contained in:
parent
36975fd8de
commit
4de3c2409f
1 changed files with 9 additions and 3 deletions
|
|
@ -27,6 +27,10 @@ if (!process.env.MINIO_BUCKET) {
|
|||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||
const MANAGE_ROLES = ["system", "head_of_admin"];
|
||||
|
||||
function isSystem(user: RequestWithUser["user"]) {
|
||||
return user.roles.includes("system");
|
||||
}
|
||||
|
||||
function globalAllow(user: RequestWithUser["user"]) {
|
||||
return MANAGE_ROLES.some((v) => user.roles?.includes(v));
|
||||
}
|
||||
|
|
@ -196,12 +200,14 @@ export class BranchController extends Controller {
|
|||
zipCode,
|
||||
headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined),
|
||||
NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined },
|
||||
OR: globalAllow(req.user)
|
||||
OR: isSystem(req.user)
|
||||
? undefined
|
||||
: [
|
||||
{ user: !globalAllow(req.user) ? { some: { userId: req.user.sub } } : undefined },
|
||||
{
|
||||
headOffice: !globalAllow(req.user)
|
||||
user: { some: { userId: req.user.sub } },
|
||||
},
|
||||
{
|
||||
headOffice: globalAllow(req.user)
|
||||
? { user: { some: { userId: req.user.sub } } }
|
||||
: undefined,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue