Merge branch 'feat/permission' into develop
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
This commit is contained in:
commit
d6212e9ba4
23 changed files with 224 additions and 111 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 = {
|
||||||
|
|
@ -147,7 +151,7 @@ type BranchUpdate = {
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const permissionCond = createPermCondition(globalAllowView);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
|
|
||||||
@Route("api/v1/branch")
|
@Route("api/v1/branch")
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,17 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
throw Error("Require MinIO bucket.");
|
throw Error("Require MinIO bucket.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const listAllowed = ["system", "head_of_admin"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive"];
|
||||||
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
"sale",
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomerBranchCitizenPayload = {
|
type CustomerBranchCitizenPayload = {
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
"sale",
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -42,15 +42,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
"sale",
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeeCheckupPayload = {
|
type EmployeeCheckupPayload = {
|
||||||
|
|
|
||||||
|
|
@ -51,14 +51,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCond = createPermCondition(globalAllow);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeeOtherInfoPayload = {
|
type EmployeeOtherInfoPayload = {
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeePassportPayload = {
|
type EmployeePassportPayload = {
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeeVisaPayload = {
|
type EmployeeVisaPayload = {
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeeWorkPayload = {
|
type EmployeeWorkPayload = {
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,30 @@ type WorkflowPayload = {
|
||||||
status?: Status;
|
status?: Status;
|
||||||
};
|
};
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const MANAGE_ROLES = [
|
||||||
const permissionCheckCompany = createPermCheck((_) => true);
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"accountant",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
|
];
|
||||||
|
|
||||||
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const permissionCondCompany = createPermCondition(globalAllow);
|
||||||
|
const permissionCheckCompany = createPermCheck(globalAllow);
|
||||||
|
|
||||||
@Route("api/v1/workflow-template")
|
@Route("api/v1/workflow-template")
|
||||||
@Tags("Workflow")
|
@Tags("Workflow")
|
||||||
@Security("keycloak")
|
|
||||||
export class FlowTemplateController extends Controller {
|
export class FlowTemplateController extends Controller {
|
||||||
@Get()
|
@Get()
|
||||||
|
@Security("keycloak")
|
||||||
async getFlowTemplate(
|
async getFlowTemplate(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
|
|
@ -118,6 +134,7 @@ export class FlowTemplateController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{templateId}")
|
@Get("{templateId}")
|
||||||
|
@Security("keycloak")
|
||||||
async getFlowTemplateById(@Request() _req: RequestWithUser, @Path() templateId: string) {
|
async getFlowTemplateById(@Request() _req: RequestWithUser, @Path() templateId: string) {
|
||||||
const record = await prisma.workflowTemplate.findFirst({
|
const record = await prisma.workflowTemplate.findFirst({
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -150,6 +167,7 @@ export class FlowTemplateController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async createFlowTemplate(@Request() req: RequestWithUser, @Body() body: WorkflowPayload) {
|
async createFlowTemplate(@Request() req: RequestWithUser, @Body() body: WorkflowPayload) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: [
|
OR: [
|
||||||
|
|
@ -230,6 +248,7 @@ export class FlowTemplateController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{templateId}")
|
@Put("{templateId}")
|
||||||
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async updateFlowTemplate(
|
async updateFlowTemplate(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() templateId: string,
|
@Path() templateId: string,
|
||||||
|
|
@ -315,6 +334,7 @@ export class FlowTemplateController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{templateId}")
|
@Delete("{templateId}")
|
||||||
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async deleteFlowTemplateById(@Request() req: RequestWithUser, @Path() templateId: string) {
|
async deleteFlowTemplateById(@Request() req: RequestWithUser, @Path() templateId: string) {
|
||||||
const record = await prisma.workflowTemplate.findUnique({
|
const record = await prisma.workflowTemplate.findUnique({
|
||||||
where: { id: templateId },
|
where: { id: templateId },
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,17 @@ type InstitutionUpdatePayload = {
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"accountant",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
|
];
|
||||||
|
|
||||||
@Route("api/v1/institution")
|
@Route("api/v1/institution")
|
||||||
@Tags("Institution")
|
@Tags("Institution")
|
||||||
export class InstitutionController extends Controller {
|
export class InstitutionController extends Controller {
|
||||||
|
|
@ -185,7 +196,7 @@ export class InstitutionController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
@OperationId("createInstitution")
|
@OperationId("createInstitution")
|
||||||
async createInstitution(
|
async createInstitution(
|
||||||
@Body()
|
@Body()
|
||||||
|
|
@ -229,7 +240,7 @@ export class InstitutionController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{institutionId}")
|
@Put("{institutionId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
@OperationId("updateInstitution")
|
@OperationId("updateInstitution")
|
||||||
async updateInstitution(
|
async updateInstitution(
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -278,7 +289,7 @@ export class InstitutionController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{institutionId}")
|
@Delete("{institutionId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
@OperationId("deleteInstitution")
|
@OperationId("deleteInstitution")
|
||||||
async deleteInstitution(@Path() institutionId: string) {
|
async deleteInstitution(@Path() institutionId: string) {
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
|
|
@ -350,7 +361,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("image/{name}")
|
@Put("image/{name}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async putImage(
|
async putImage(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -364,7 +375,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("image/{name}")
|
@Delete("image/{name}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async delImage(
|
async delImage(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -394,7 +405,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("attachment/{name}")
|
@Put("attachment/{name}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async putAttachment(
|
async putAttachment(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -405,7 +416,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("attachment/{name}")
|
@Delete("attachment/{name}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async delAttachment(
|
async delAttachment(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -436,7 +447,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("bank-qr/{bankId}")
|
@Put("bank-qr/{bankId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async putBankImage(
|
async putBankImage(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
@ -450,7 +461,7 @@ export class InstitutionFileController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("bank-qr/{bankId}")
|
@Delete("bank-qr/{bankId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async delBankImage(
|
async delBankImage(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() institutionId: string,
|
@Path() institutionId: string,
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,23 @@ type InvoicePayload = {
|
||||||
installmentNo: number[];
|
installmentNo: number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "head_of_accountant", "accountant"];
|
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 allowList = ["system", "head_of_admin", "head_of_accountant"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition(globalAllow);
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
|
|
||||||
@Route("/api/v1/invoice")
|
@Route("/api/v1/invoice")
|
||||||
|
|
@ -229,7 +238,7 @@ export class InvoiceController extends Controller {
|
||||||
title: "ใบแจ้งหนี้ใหม่ / New Invoice",
|
title: "ใบแจ้งหนี้ใหม่ / New Invoice",
|
||||||
detail: "รหัส / code : " + record.code,
|
detail: "รหัส / code : " + record.code,
|
||||||
registeredBranchId: record.registeredBranchId,
|
registeredBranchId: record.registeredBranchId,
|
||||||
groupReceiver: { create: { name: "accountant" } },
|
groupReceiver: { create: { name: "branch_accountant" } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ type ProductGroupCreate = {
|
||||||
remark: string;
|
remark: string;
|
||||||
status?: Status;
|
status?: Status;
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
registeredBranchId: string;
|
registeredBranchId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProductGroupUpdate = {
|
type ProductGroupUpdate = {
|
||||||
|
|
@ -51,14 +51,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCond = createPermCondition((_) => true);
|
const permissionCond = createPermCondition((_) => true);
|
||||||
|
|
@ -157,7 +159,23 @@ export class ProductGroup extends Controller {
|
||||||
@Post()
|
@Post()
|
||||||
@Security("keycloak", MANAGE_ROLES)
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async createProductGroup(@Request() req: RequestWithUser, @Body() body: ProductGroupCreate) {
|
async createProductGroup(@Request() req: RequestWithUser, @Body() body: ProductGroupCreate) {
|
||||||
let company = await permissionCheck(req.user, body.registeredBranchId).then(
|
const userAffiliatedBranch = await prisma.branch.findFirst({
|
||||||
|
include: branchRelationPermInclude(req.user),
|
||||||
|
where: body.registeredBranchId
|
||||||
|
? { id: body.registeredBranchId }
|
||||||
|
: {
|
||||||
|
user: { some: { userId: req.user.sub } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!userAffiliatedBranch) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"You must be affilated with at least one branch or specify branch to be registered (System permission required).",
|
||||||
|
"reqMinAffilatedBranch",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let company = await permissionCheck(req.user, userAffiliatedBranch).then(
|
||||||
(v) => (v.headOffice || v).code,
|
(v) => (v.headOffice || v).code,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -181,6 +199,7 @@ export class ProductGroup extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
registeredBranchId: userAffiliatedBranch.id,
|
||||||
statusOrder: +(body.status === "INACTIVE"),
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `G${last.value.toString().padStart(2, "0")}`,
|
code: `G${last.value.toString().padStart(2, "0")}`,
|
||||||
createdByUserId: req.user.sub,
|
createdByUserId: req.user.sub,
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,16 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,20 @@ import flowAccount from "../services/flowaccount";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "head_of_accountant", "accountant"];
|
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 allowList = ["system", "head_of_admin", "head_of_accountant"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -150,14 +150,14 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
|
||||||
"accountant",
|
"accountant",
|
||||||
|
"branch_accountant",
|
||||||
"head_of_sale",
|
"head_of_sale",
|
||||||
"sale",
|
"sale",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const allowList = ["system", "head_of_admin", "accountant", "head_of_sale"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return allowList.some((v) => user.roles?.includes(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,21 @@ import {
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "document_checker"];
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"executive",
|
||||||
|
"accountant",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
|
"data_entry",
|
||||||
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
|
||||||
|
|
@ -42,22 +42,20 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
"sale",
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: permission condition/check in requestWork -> requestData -> quotation -> registeredBranch
|
|
||||||
const permissionCond = createPermCondition(globalAllow);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
const permissionCheckCompany = createPermCheck((_) => true);
|
|
||||||
|
|
||||||
type CreditNoteCreate = {
|
type CreditNoteCreate = {
|
||||||
requestWorkId: string[];
|
requestWorkId: string[];
|
||||||
|
|
@ -94,7 +92,7 @@ export class CreditNoteController extends Controller {
|
||||||
request: {
|
request: {
|
||||||
quotationId,
|
quotationId,
|
||||||
quotation: {
|
quotation: {
|
||||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -200,7 +198,7 @@ export class CreditNoteController extends Controller {
|
||||||
request: {
|
request: {
|
||||||
quotationId,
|
quotationId,
|
||||||
quotation: {
|
quotation: {
|
||||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -243,7 +241,7 @@ export class CreditNoteController extends Controller {
|
||||||
some: {
|
some: {
|
||||||
request: {
|
request: {
|
||||||
quotation: {
|
quotation: {
|
||||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -44,22 +44,20 @@ const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
"head_of_admin",
|
"head_of_admin",
|
||||||
"admin",
|
"admin",
|
||||||
"head_of_accountant",
|
"executive",
|
||||||
"accountant",
|
"accountant",
|
||||||
"head_of_sale",
|
"branch_admin",
|
||||||
"sale",
|
"branch_manager",
|
||||||
|
"branch_accountant",
|
||||||
];
|
];
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
function globalAllow(user: RequestWithUser["user"]) {
|
||||||
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
|
const listAllowed = ["system", "head_of_admin", "admin", "executive", "accountant"];
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
return user.roles?.some((v) => listAllowed.includes(v)) || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: permission condition/check in registeredBranch
|
|
||||||
const permissionCond = createPermCondition(globalAllow);
|
const permissionCond = createPermCondition(globalAllow);
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
|
||||||
const permissionCheck = createPermCheck(globalAllow);
|
const permissionCheck = createPermCheck(globalAllow);
|
||||||
const permissionCheckCompany = createPermCheck((_) => true);
|
|
||||||
|
|
||||||
type DebitNoteCreate = {
|
type DebitNoteCreate = {
|
||||||
quotationId: string;
|
quotationId: string;
|
||||||
|
|
@ -605,7 +603,7 @@ export class DebitNoteController extends Controller {
|
||||||
|
|
||||||
if (!record) throw notFoundError("Debit Note");
|
if (!record) throw notFoundError("Debit Note");
|
||||||
|
|
||||||
await permissionCheckCompany(req.user, record.registeredBranch);
|
await permissionCheck(req.user, record.registeredBranch);
|
||||||
|
|
||||||
const { productServiceList: _productServiceList, ...rest } = body;
|
const { productServiceList: _productServiceList, ...rest } = body;
|
||||||
const ids = {
|
const ids = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue