feaet: protect by roles
This commit is contained in:
parent
2c99b92aa5
commit
c97a8e5f66
1 changed files with 19 additions and 3 deletions
|
|
@ -157,6 +157,22 @@ type QuotationUpdate = {
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MANAGE_ROLES = [
|
||||||
|
"system",
|
||||||
|
"head_of_admin",
|
||||||
|
"admin",
|
||||||
|
"branch_admin",
|
||||||
|
"branch_manager",
|
||||||
|
"accountant",
|
||||||
|
"branch_accountant",
|
||||||
|
];
|
||||||
|
|
||||||
|
function globalAllow(roles?: string[]) {
|
||||||
|
return ["system", "head_of_admin", "admin", "branch_admin", "branch_manager", "accountant"].some(
|
||||||
|
(v) => roles?.includes(v),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Route("/api/v1/quotation")
|
@Route("/api/v1/quotation")
|
||||||
@Tags("Quotation")
|
@Tags("Quotation")
|
||||||
export class QuotationController extends Controller {
|
export class QuotationController extends Controller {
|
||||||
|
|
@ -219,7 +235,7 @@ export class QuotationController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async createQuotation(@Request() req: RequestWithUser, @Body() body: QuotationCreate) {
|
async createQuotation(@Request() req: RequestWithUser, @Body() body: QuotationCreate) {
|
||||||
const existingEmployee = body.worker.filter((v) => typeof v === "string");
|
const existingEmployee = body.worker.filter((v) => typeof v === "string");
|
||||||
const serviceIdList = body.service.map((v) => v.id);
|
const serviceIdList = body.service.map((v) => v.id);
|
||||||
|
|
@ -479,7 +495,7 @@ export class QuotationController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{quotationId}")
|
@Put("{quotationId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async editQuotation(
|
async editQuotation(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Path() quotationId: string,
|
@Path() quotationId: string,
|
||||||
|
|
@ -776,7 +792,7 @@ export class QuotationController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{quotationId}")
|
@Delete("{quotationId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak", MANAGE_ROLES)
|
||||||
async deleteQuotationById(@Request() req: RequestWithUser, @Path() quotationId: string) {
|
async deleteQuotationById(@Request() req: RequestWithUser, @Path() quotationId: string) {
|
||||||
const record = await prisma.quotation.findUnique({
|
const record = await prisma.quotation.findUnique({
|
||||||
where: { id: quotationId },
|
where: { id: quotationId },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue