From d34b1fba3620cdf0c434156cc01b4707a859acae Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Mon, 26 Aug 2024 22:13:18 +0800 Subject: [PATCH] feat(approval): v2 (#1476) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1476 Reviewed-by: sealday Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .../ApproverInterface.schema.tsx | 1 - .../todos/Dt.ApprovalFormBlock.tsx | 3 +- .../approval-columns/workflow.column.tsx | 11 +------- .../notice-columns/column.workflow.tsx | 11 +------- .../ApprovalCarbonCopy.instruction.ts | 2 +- .../features/approval/ApprovalInstruction.ts | 2 +- .../features/approval/ApprovalTrigger.ts | 2 +- .../approval/actions/approvalCarbonCopy.ts | 2 +- .../approval/actions/approvalRecords.ts | 28 +++++++++++++------ .../features/approval/actions/approvals.ts | 2 +- .../features/approval/constants/error-code.ts | 22 +++++++++++++++ .../{constants.ts => constants/status.ts} | 0 12 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/error-code.ts rename packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/{constants.ts => constants/status.ts} (100%) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/configuration/instruction-approval/approver-interface/ApproverInterface.schema.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/configuration/instruction-approval/approver-interface/ApproverInterface.schema.tsx index 518250dba..548ae3fc3 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/configuration/instruction-approval/approver-interface/ApproverInterface.schema.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/configuration/instruction-approval/approver-interface/ApproverInterface.schema.tsx @@ -66,7 +66,6 @@ export const ApproverInterfaceComponent = () => { value={{ ...context, refresh: () => setId(uid()), - designable: !workflow.executed, }} > diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/todos/Dt.ApprovalFormBlock.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/todos/Dt.ApprovalFormBlock.tsx index e76c0097f..c4c2a469c 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/todos/Dt.ApprovalFormBlock.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/todos/Dt.ApprovalFormBlock.tsx @@ -37,7 +37,8 @@ export function ApprovalFormBlockDecorator(props) { return createForm({ initialValues: omitApproval, pattern: - !workflow?.enabled || execution?.status || job?.status || omitApproval?.status == null + // NOTE: 为了让过期版本也能走完正常流程, 去除 !workflow?.enabled 条件 + execution?.status || job?.status || omitApproval?.status == null ? 'disabled' : omitApproval.status || data.data?.id !== omitApproval.userId ? 'readPretty' diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/approval-columns/workflow.column.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/approval-columns/workflow.column.tsx index 2ce1646ae..94cadb741 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/approval-columns/workflow.column.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/approval-columns/workflow.column.tsx @@ -13,16 +13,7 @@ export const WorkflowColumn = observer( if (value?.enabled) { return title; } else { - return ( - - {title} - - ); + return {`${title}*`}; } }, { displayName: 'WorkflowColumn' }, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/notice-columns/column.workflow.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/notice-columns/column.workflow.tsx index 9a2261dab..1c01117bb 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/notice-columns/column.workflow.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-common/notice-columns/column.workflow.tsx @@ -13,16 +13,7 @@ export const ColumnWorkflow = observer( if (value?.enabled) { return title; } else { - return ( - - {title} - - ); + return {`${title}*`}; } }, { displayName: 'ColumnWorkflow' }, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalCarbonCopy.instruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalCarbonCopy.instruction.ts index 9995c144e..b52cc3995 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalCarbonCopy.instruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalCarbonCopy.instruction.ts @@ -3,7 +3,7 @@ import { UiSchemaRepository } from '@tachybase/plugin-ui-schema-storage'; import { JOB_STATUS } from '../../constants'; import Instruction from '../../instructions'; import { COLLECTION_NAME_APPROVAL_CARBON_COPY } from '../common/constants'; -import { APPROVAL_STATUS } from './constants'; +import { APPROVAL_STATUS } from './constants/status'; import { parsePerson } from './tools'; export default class ApprovalCarbonCopyInstruction extends Instruction { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalInstruction.ts index 559f869e4..dbb576641 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalInstruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalInstruction.ts @@ -6,7 +6,7 @@ import { JOB_STATUS } from '../../constants'; import Instruction from '../../instructions'; import { toJSON } from '../../utils'; import ApprovalTrigger from './ApprovalTrigger'; -import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from './constants'; +import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from './constants/status'; const NEGOTIATION_MODE = { SINGLE: Symbol('single'), diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts index 3c285b895..803c4e779 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/ApprovalTrigger.ts @@ -8,7 +8,7 @@ import { BelongsTo, HasOne, Op } from 'sequelize'; import { EXECUTION_STATUS, JOB_STATUS } from '../../constants'; import Trigger from '../../triggers'; import { toJSON } from '../../utils'; -import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from './constants'; +import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from './constants/status'; import { getSummary } from './tools'; const ExecutionStatusMap = { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalCarbonCopy.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalCarbonCopy.ts index 545a746f0..4454778e4 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalCarbonCopy.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalCarbonCopy.ts @@ -2,7 +2,7 @@ import actions from '@tachybase/actions'; import { Op } from '@tachybase/database'; import { COLLECTION_WORKFLOWS_NAME } from '../../common/constants'; -import { APPROVAL_STATUS } from '../constants'; +import { APPROVAL_STATUS } from '../constants/status'; import { findUniqueObjects } from '../utils'; export const approvalCarbonCopy = { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalRecords.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalRecords.ts index 190dacea1..8e70a3f3b 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalRecords.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvalRecords.ts @@ -1,7 +1,8 @@ import actions, { utils } from '@tachybase/actions'; import { PluginWorkflow } from '../../..'; -import { APPROVAL_ACTION_STATUS } from '../constants'; +import { ERROR_CODE_MAP } from '../constants/error-code'; +import { APPROVAL_ACTION_STATUS } from '../constants/status'; export const approvalRecords = { async listCentralized(context, next) { @@ -38,15 +39,24 @@ export const approvalRecords = { if (!approvalRecord) { return context.throw(404); } - if ( - !approvalRecord.workflow.enabled || - approvalRecord.execution.status || - approvalRecord.job.status || - approvalRecord.status !== APPROVAL_ACTION_STATUS.PENDING || - (!needUpdateRecord && !(approvalRecord.node.config.actions ?? []).includes(status)) - ) { - return context.throw(400); + + // NOTE: 为了更改设定, 让切换版本后, 已经在进程中的审批流程也可以执行下去. 所以这里先注释掉. + // 原设定是, 切换版本后, 已经在流程中的, 置为未处理状态, 然后禁止继续执行. + switch (true) { + // case !approvalRecord.workflow.enabled: + // return context.throw(400, ERROR_CODE_MAP['not_enable_workflow']); + case approvalRecord.execution.status: + return context.throw(400, ERROR_CODE_MAP['execution_finished']); + case approvalRecord.job.status: + return context.throw(400, ERROR_CODE_MAP['job_finished']); + case approvalRecord.status !== APPROVAL_ACTION_STATUS.PENDING: + return context.throw(400, ERROR_CODE_MAP['not_approval_pending']); + case !needUpdateRecord && !(approvalRecord.node.config.actions ?? []).includes(status): + return context.throw(400, ERROR_CODE_MAP['not_need_update']); + default: + break; } + await approvalRecord.update({ status: status, comment: data.comment, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvals.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvals.ts index a541507d8..02621eeec 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvals.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions/approvals.ts @@ -3,7 +3,7 @@ import { parseCollectionName } from '@tachybase/data-source-manager'; import { traverseJSON } from '@tachybase/database'; import { EXECUTION_STATUS, JOB_STATUS, PluginWorkflow } from '../../..'; -import { APPROVAL_STATUS } from '../constants'; +import { APPROVAL_STATUS } from '../constants/status'; import { getSummary } from '../tools'; import { getAssociationName, jsonParse } from '../utils'; diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/error-code.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/error-code.ts new file mode 100644 index 000000000..e502286ae --- /dev/null +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/error-code.ts @@ -0,0 +1,22 @@ +export const ERROR_CODE_MAP = { + ['not_enable_workflow']: { + code: 9000, + message: 'not_enable_workflow', + }, + ['execution_finished']: { + code: 9001, + message: 'execution_finished', + }, + ['job_finished']: { + code: 9002, + message: 'job_finished', + }, + ['not_approval_pending']: { + code: 9003, + message: 'not_approval_pending', + }, + ['not_need_update']: { + code: 9004, + message: 'not_need_update', + }, +}; diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/status.ts similarity index 100% rename from packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants.ts rename to packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/constants/status.ts