feat(approval): v2 (#1476)

Reviewed-on: daoyoucloud/tachybase#1476
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
bai.zixv 2024-08-26 22:13:18 +08:00 committed by sealday
parent ba75073ec0
commit d34b1fba36
12 changed files with 50 additions and 36 deletions

View File

@ -66,7 +66,6 @@ export const ApproverInterfaceComponent = () => {
value={{
...context,
refresh: () => setId(uid()),
designable: !workflow.executed,
}}
>
<RecordProvider record={{}} parent={false}>

View File

@ -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'

View File

@ -13,16 +13,7 @@ export const WorkflowColumn = observer(
if (value?.enabled) {
return title;
} else {
return (
<span
className={css`
text-decoration: line-through;
`}
title={t('Disabled')}
>
{title}
</span>
);
return <span title={t('Disabled')}>{`${title}*`}</span>;
}
},
{ displayName: 'WorkflowColumn' },

View File

@ -13,16 +13,7 @@ export const ColumnWorkflow = observer(
if (value?.enabled) {
return title;
} else {
return (
<span
className={css`
text-decoration: line-through;
`}
title={t('Disabled')}
>
{title}
</span>
);
return <span title={t('Disabled')}>{`${title}*`}</span>;
}
},
{ displayName: 'ColumnWorkflow' },

View File

@ -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 {

View File

@ -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'),

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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,

View File

@ -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';

View File

@ -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',
},
};