feat(perm): update api branch perm
This commit is contained in:
parent
acd6bb35e9
commit
2756fcb655
2 changed files with 23 additions and 10 deletions
|
|
@ -47,16 +47,20 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
throw Error("Require MinIO bucket.");
|
throw Error("Require MinIO bucket.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin"];
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"accountant",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
return MANAGE_ROLES.some((v) => user.roles?.includes(v));
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
}
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
|
|
||||||
function globalAllowView(user: RequestWithUser["user"]) {
|
|
||||||
return MANAGE_ROLES.concat("head_of_accountant", "head_of_sale").some((v) =>
|
|
||||||
user.roles?.includes(v),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type BranchCreate = {
|
type BranchCreate = {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,19 @@ import { RequestWithUser } from "../interfaces/user";
|
||||||
import { branchRelationPermInclude, createPermCheck } from "../services/permission";
|
import { branchRelationPermInclude, createPermCheck } from "../services/permission";
|
||||||
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"accountant",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const listAllowed = ["system", "head_of_admin", "admin"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue