feat(perm): update api flow template permission
This commit is contained in:
parent
fa95fe46a5
commit
6d44d2979b
1 changed files with 23 additions and 3 deletions
|
|
@ -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 },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue