Commit 9cc8e0d37f296d5ed2bcee39a27be9cbb064abb2
1 parent
90ced26b
【功能新增】工作流:流程模型修改时,校验是否为流程的管理员
Showing
5 changed files
with
51 additions
and
34 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java
| ... | ... | @@ -23,6 +23,7 @@ public interface ErrorCodeConstants { |
| 23 | 23 | "原因:用户任务({})未配置审批人,请点击【流程设计】按钮,选择该它的【任务(审批人)】进行配置"); |
| 24 | 24 | ErrorCode MODEL_DEPLOY_FAIL_BPMN_START_EVENT_NOT_EXISTS = new ErrorCode(1_009_002_005, "部署流程失败,原因:BPMN 流程图中,没有开始事件"); |
| 25 | 25 | ErrorCode MODEL_DEPLOY_FAIL_BPMN_USER_TASK_NAME_NOT_EXISTS = new ErrorCode(1_009_002_006, "部署流程失败,原因:BPMN 流程图中,用户任务({})的名字不存在"); |
| 26 | + ErrorCode MODEL_UPDATE_FAIL_NOT_MANAGER = new ErrorCode(1_009_002_007, "操作流程失败,原因:你不是该流程的管理员"); | |
| 26 | 27 | |
| 27 | 28 | // ========== 流程定义 1-009-003-000 ========== |
| 28 | 29 | ErrorCode PROCESS_DEFINITION_KEY_NOT_MATCH = new ErrorCode(1_009_003_000, "流程定义的标识期望是({}),当前是({}),请修改 BPMN 流程图"); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 8 | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; |
| 9 | 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 10 | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO; |
| ... | ... | @@ -36,8 +35,8 @@ import java.util.Set; |
| 36 | 35 | import java.util.stream.Stream; |
| 37 | 36 | |
| 38 | 37 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 39 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 40 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 38 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 39 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 41 | 40 | |
| 42 | 41 | @Tag(name = "管理后台 - 流程模型") |
| 43 | 42 | @RestController |
| ... | ... | @@ -68,7 +67,7 @@ public class BpmModelController { |
| 68 | 67 | // 拼接数据 |
| 69 | 68 | // 获得 Form 表单 |
| 70 | 69 | Set<Long> formIds = convertSet(pageResult.getList(), model -> { |
| 71 | - BpmModelMetaInfoVO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); | |
| 70 | + BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); | |
| 72 | 71 | return metaInfo != null ? metaInfo.getFormId() : null; |
| 73 | 72 | }); |
| 74 | 73 | Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds); |
| ... | ... | @@ -83,8 +82,8 @@ public class BpmModelController { |
| 83 | 82 | List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds); |
| 84 | 83 | Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId); |
| 85 | 84 | // 获得 User Map |
| 86 | - Set<Long> userIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), model -> { | |
| 87 | - BpmModelMetaInfoVO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); | |
| 85 | + Set<Long> userIds = convertSetByFlatMap(pageResult.getList(), model -> { | |
| 86 | + BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); | |
| 88 | 87 | return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty(); |
| 89 | 88 | }); |
| 90 | 89 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); |
| ... | ... | @@ -116,7 +115,7 @@ public class BpmModelController { |
| 116 | 115 | @Operation(summary = "修改模型") |
| 117 | 116 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") |
| 118 | 117 | public CommonResult<Boolean> updateModel(@Valid @RequestBody BpmModelSaveReqVO modelVO) { |
| 119 | - modelService.updateModel(modelVO); | |
| 118 | + modelService.updateModel(getLoginUserId(), modelVO); | |
| 120 | 119 | return success(true); |
| 121 | 120 | } |
| 122 | 121 | |
| ... | ... | @@ -125,7 +124,7 @@ public class BpmModelController { |
| 125 | 124 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 126 | 125 | @PreAuthorize("@ss.hasPermission('bpm:model:deploy')") |
| 127 | 126 | public CommonResult<Boolean> deployModel(@RequestParam("id") String id) { |
| 128 | - modelService.deployModel(id); | |
| 127 | + modelService.deployModel(getLoginUserId(), id); | |
| 129 | 128 | return success(true); |
| 130 | 129 | } |
| 131 | 130 | |
| ... | ... | @@ -133,7 +132,7 @@ public class BpmModelController { |
| 133 | 132 | @Operation(summary = "修改模型的状态", description = "实际更新的部署的流程定义的状态") |
| 134 | 133 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") |
| 135 | 134 | public CommonResult<Boolean> updateModelState(@Valid @RequestBody BpmModelUpdateStateReqVO reqVO) { |
| 136 | - modelService.updateModelState(reqVO.getId(), reqVO.getState()); | |
| 135 | + modelService.updateModelState(getLoginUserId(), reqVO.getId(), reqVO.getState()); | |
| 137 | 136 | return success(true); |
| 138 | 137 | } |
| 139 | 138 | |
| ... | ... | @@ -150,7 +149,7 @@ public class BpmModelController { |
| 150 | 149 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 151 | 150 | @PreAuthorize("@ss.hasPermission('bpm:model:delete')") |
| 152 | 151 | public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) { |
| 153 | - modelService.deleteModel(id); | |
| 152 | + modelService.deleteModel(getLoginUserId(), id); | |
| 154 | 153 | return success(true); |
| 155 | 154 | } |
| 156 | 155 | |
| ... | ... | @@ -167,7 +166,7 @@ public class BpmModelController { |
| 167 | 166 | @Operation(summary = "保存仿钉钉流程设计模型") |
| 168 | 167 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") |
| 169 | 168 | public CommonResult<Boolean> updateSimpleModel(@Valid @RequestBody BpmSimpleModelUpdateReqVO reqVO) { |
| 170 | - modelService.updateSimpleModel(reqVO); | |
| 169 | + modelService.updateSimpleModel(getLoginUserId(), reqVO); | |
| 171 | 170 | return success(Boolean.TRUE); |
| 172 | 171 | } |
| 173 | 172 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
| ... | ... | @@ -42,7 +42,7 @@ public interface BpmModelConvert { |
| 42 | 42 | Map<String, ProcessDefinition> processDefinitionMap, |
| 43 | 43 | Map<Long, AdminUserRespDTO> userMap) { |
| 44 | 44 | List<BpmModelRespVO> list = convertList(pageResult.getList(), model -> { |
| 45 | - BpmModelMetaInfoVO metaInfo = buildMetaInfo(model); | |
| 45 | + BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); | |
| 46 | 46 | BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; |
| 47 | 47 | BpmCategoryDO category = categoryMap.get(model.getCategory()); |
| 48 | 48 | Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null; |
| ... | ... | @@ -55,7 +55,7 @@ public interface BpmModelConvert { |
| 55 | 55 | |
| 56 | 56 | default BpmModelRespVO buildModel(Model model, |
| 57 | 57 | byte[] bpmnBytes) { |
| 58 | - BpmModelMetaInfoVO metaInfo = buildMetaInfo(model); | |
| 58 | + BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); | |
| 59 | 59 | BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null); |
| 60 | 60 | if (ArrayUtil.isNotEmpty(bpmnBytes)) { |
| 61 | 61 | modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes)); |
| ... | ... | @@ -100,7 +100,7 @@ public interface BpmModelConvert { |
| 100 | 100 | model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class))); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - default BpmModelMetaInfoVO buildMetaInfo(Model model) { | |
| 103 | + default BpmModelMetaInfoVO parseMetaInfo(Model model) { | |
| 104 | 104 | return JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); |
| 105 | 105 | } |
| 106 | 106 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
| ... | ... | @@ -59,31 +59,35 @@ public interface BpmModelService { |
| 59 | 59 | /** |
| 60 | 60 | * 修改流程模型 |
| 61 | 61 | * |
| 62 | + * @param userId 用户编号 | |
| 62 | 63 | * @param updateReqVO 更新信息 |
| 63 | 64 | */ |
| 64 | - void updateModel(@Valid BpmModelSaveReqVO updateReqVO); | |
| 65 | + void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO); | |
| 65 | 66 | |
| 66 | 67 | /** |
| 67 | 68 | * 将流程模型,部署成一个流程定义 |
| 68 | 69 | * |
| 70 | + * @param userId 用户编号 | |
| 69 | 71 | * @param id 编号 |
| 70 | 72 | */ |
| 71 | - void deployModel(String id); | |
| 73 | + void deployModel(Long userId, String id); | |
| 72 | 74 | |
| 73 | 75 | /** |
| 74 | 76 | * 删除模型 |
| 75 | 77 | * |
| 78 | + * @param userId 用户编号 | |
| 76 | 79 | * @param id 编号 |
| 77 | 80 | */ |
| 78 | - void deleteModel(String id); | |
| 81 | + void deleteModel(Long userId, String id); | |
| 79 | 82 | |
| 80 | 83 | /** |
| 81 | 84 | * 修改模型的状态,实际更新的部署的流程定义的状态 |
| 82 | 85 | * |
| 86 | + * @param userId 用户编号 | |
| 83 | 87 | * @param id 编号 |
| 84 | 88 | * @param state 状态 |
| 85 | 89 | */ |
| 86 | - void updateModelState(String id, Integer state); | |
| 90 | + void updateModelState(Long userId, String id, Integer state); | |
| 87 | 91 | |
| 88 | 92 | /** |
| 89 | 93 | * 获得流程定义编号对应的 BPMN Model |
| ... | ... | @@ -106,10 +110,9 @@ public interface BpmModelService { |
| 106 | 110 | /** |
| 107 | 111 | * 更新仿钉钉流程设计模型 |
| 108 | 112 | * |
| 113 | + * @param userId 用户编号 | |
| 109 | 114 | * @param reqVO 请求信息 |
| 110 | 115 | */ |
| 111 | - void updateSimpleModel(@Valid BpmSimpleModelUpdateReqVO reqVO); | |
| 112 | - | |
| 113 | - // TODO @jason:另外个问题,因为是存储到 modelExtra 里,那需要 deploy 存储出快照。和 bpmn xml 一样。目前我想到的,就是存储到 BpmProcessDefinitionInfoDO 加一个 simple_model 字段,text 类型。可以看看还有啥方案?【重要】 | |
| 116 | + void updateSimpleModel(Long userId, @Valid BpmSimpleModelUpdateReqVO reqVO); | |
| 114 | 117 | |
| 115 | 118 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.service.definition; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.hutool.core.util.ArrayUtil; |
| 4 | 5 | import cn.hutool.core.util.StrUtil; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -109,9 +110,9 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 109 | 110 | |
| 110 | 111 | @Override |
| 111 | 112 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 |
| 112 | - public void updateModel(@Valid BpmModelSaveReqVO updateReqVO) { | |
| 113 | + public void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO) { | |
| 113 | 114 | // 1. 校验流程模型存在 |
| 114 | - Model model = validateModelExists(updateReqVO.getId()); | |
| 115 | + Model model = validateModelManager(updateReqVO.getId(), userId); | |
| 115 | 116 | |
| 116 | 117 | // 修改流程定义 |
| 117 | 118 | BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO); |
| ... | ... | @@ -127,19 +128,32 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 127 | 128 | return model; |
| 128 | 129 | } |
| 129 | 130 | |
| 130 | -// // 更新 BPMN XML | |
| 131 | -// saveModelBpmnXml(model.getId(), updateReqVO.getBpmnXml()); | |
| 131 | + /** | |
| 132 | + * 校验是否有流程模型的管理权限 | |
| 133 | + * | |
| 134 | + * @param id 流程模型编号 | |
| 135 | + * @param userId 用户编号 | |
| 136 | + * @return 流程模型 | |
| 137 | + */ | |
| 138 | + private Model validateModelManager(String id, Long userId) { | |
| 139 | + Model model = validateModelExists(id); | |
| 140 | + BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); | |
| 141 | + if (metaInfo == null || !CollUtil.contains(metaInfo.getManagerUserIds(), userId)) { | |
| 142 | + throw exception(MODEL_UPDATE_FAIL_NOT_MANAGER); | |
| 143 | + } | |
| 144 | + return model; | |
| 145 | + } | |
| 132 | 146 | |
| 133 | 147 | @Override |
| 134 | 148 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 |
| 135 | - public void deployModel(String id) { | |
| 149 | + public void deployModel(Long userId, String id) { | |
| 136 | 150 | // 1.1 校验流程模型存在 |
| 137 | - Model model = validateModelExists(id); | |
| 151 | + Model model = validateModelManager(id, userId); | |
| 138 | 152 | // 1.2 校验流程图 |
| 139 | 153 | byte[] bpmnBytes = getModelBpmnXML(model.getId()); |
| 140 | 154 | validateBpmnXml(bpmnBytes); |
| 141 | 155 | // 1.3 校验表单已配 |
| 142 | - BpmModelMetaInfoVO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); | |
| 156 | + BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); | |
| 143 | 157 | BpmFormDO form = validateFormConfig(metaInfo); |
| 144 | 158 | // 1.4 校验任务分配规则已配置 |
| 145 | 159 | taskCandidateInvoker.validateBpmnConfig(bpmnBytes); |
| ... | ... | @@ -179,9 +193,9 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 179 | 193 | |
| 180 | 194 | @Override |
| 181 | 195 | @Transactional(rollbackFor = Exception.class) |
| 182 | - public void deleteModel(String id) { | |
| 196 | + public void deleteModel(Long userId, String id) { | |
| 183 | 197 | // 校验流程模型存在 |
| 184 | - Model model = validateModelExists(id); | |
| 198 | + Model model = validateModelManager(id, userId); | |
| 185 | 199 | |
| 186 | 200 | // 执行删除 |
| 187 | 201 | repositoryService.deleteModel(id); |
| ... | ... | @@ -190,9 +204,9 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 190 | 204 | } |
| 191 | 205 | |
| 192 | 206 | @Override |
| 193 | - public void updateModelState(String id, Integer state) { | |
| 207 | + public void updateModelState(Long userId, String id, Integer state) { | |
| 194 | 208 | // 1.1 校验流程模型存在 |
| 195 | - Model model = validateModelExists(id); | |
| 209 | + Model model = validateModelManager(id, userId); | |
| 196 | 210 | // 1.2 校验流程定义存在 |
| 197 | 211 | ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId()); |
| 198 | 212 | if (definition == null) { |
| ... | ... | @@ -217,9 +231,9 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 217 | 231 | } |
| 218 | 232 | |
| 219 | 233 | @Override |
| 220 | - public void updateSimpleModel(BpmSimpleModelUpdateReqVO reqVO) { | |
| 234 | + public void updateSimpleModel(Long userId, BpmSimpleModelUpdateReqVO reqVO) { | |
| 221 | 235 | // 1. 校验流程模型存在 |
| 222 | - Model model = validateModelExists(reqVO.getId()); | |
| 236 | + Model model = validateModelManager(reqVO.getId(), userId); | |
| 223 | 237 | |
| 224 | 238 | // 2.1 JSON 转换成 bpmnModel |
| 225 | 239 | BpmnModel bpmnModel = SimpleModelUtils.buildBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModel()); | ... | ... |