feat(flow+gateway): 草稿删除端点 DELETE /models/{id}(超管门)
补前端 T2.5 已按占位契约做好测试的草稿删除两层端点:
flowable-service ProcessModelController:DELETE /api/flow/models/{id}——先 getModel 判 null→404
{status:1,msg};存在则 deleteModel(id)(连带 editorSource/metaInfo 一并删)→{status:0}。
网关:FlowableClient +deleteModel(id)(id 走 uri 变量严格编码,DELETE 无既有封装→照 put 补私有
delete() 助手,无请求体,幂等重试安全);ProcessModelerController +DELETE /api/workflow/models/{id}
过 requireSuperAdmin 门后透传,{status:0} 原样回(对齐前端 deleteDraft 只判成功),下游 404 经既有
FlowGatewayExceptionHandler 透传。
测试(严格 TDD,均先红后绿):
- flowable ProcessModelControllerTest 14→16(删存在的 verify deleteModel 调 1 次/删不存在 404 verify 零删)
- gateway FlowableClientTest 18→20(DELETE 按 id 透传/下游 404 透传 FlowRemote 不重试)
- gateway ProcessModelerControllerTest 21→23(超管 200 透传+非超管 403 门拦下游恰调 1 次/404 胶水经 handler 出 FLOW_REMOTE_ERROR)
两模块 mvn -pl flowable-service,platform-flow-gateway -am test 全绿,BUILD SUCCESS,既有测试零改动。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -317,6 +317,18 @@ public class FlowableClient {
|
||||
return post("从流程定义建草稿", "/api/flow/models/from-procdef", body, Map.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删草稿。对应 flowable-service {@code DELETE /api/flow/models/{id}},返回 {@code {status:0}};
|
||||
* 草稿不存在下游 404 → {@link FlowRemoteException} 透传。
|
||||
*
|
||||
* <p>{@code id} 走 uri 模板变量严格编码(禁字符串拼接)。DELETE 幂等——{@link #execute} 连接级重试安全
|
||||
* (重放同一 DELETE 落到同一 id,删已删=下游 404,不产生额外副作用)。</p>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> deleteModel(String id) {
|
||||
return delete("删草稿", "/api/flow/models/{id}", Map.class, id);
|
||||
}
|
||||
|
||||
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
|
||||
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
|
||||
return execute("发起流程列表", () -> restClient.get()
|
||||
@@ -405,6 +417,17 @@ public class FlowableClient {
|
||||
.body(respType));
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE 转发(RestClient 无既有封装 → 照 {@link #put} 补)。{@code uriTemplate}+{@code uriVars} 走 RestClient
|
||||
* 严格编码({@code id} 作 uri 变量,禁字符串拼接);无请求体;连接级重试 + 4xx/5xx 透传语义与 put 一致(幂等)。
|
||||
*/
|
||||
private <T> T delete(String op, String uriTemplate, Class<T> respType, Object... uriVars) {
|
||||
return execute(op, () -> restClient.delete()
|
||||
.uri(uriTemplate, uriVars)
|
||||
.retrieve()
|
||||
.body(respType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一执行:连接级故障带退避重试 maxRetries 次,耗尽 → 503 语义;业务错(4xx/5xx)立即透传不重试。
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -177,6 +178,19 @@ public class ProcessModelerController {
|
||||
return ResponseEntity.ok(flowableClient.modelFromProcDef(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "删草稿(超管)",
|
||||
description = "超管门后转发 flowable-service DELETE /api/flow/models/{id},返回 {status:0}。"
|
||||
+ "草稿不存在 404 经既有 handler 透传。id 以 uri 变量严格编码转发。")
|
||||
@DeleteMapping("/models/{id}")
|
||||
public ResponseEntity<Map<String, Object>> deleteModel(@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@PathVariable String id) {
|
||||
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||
if (denied != null) {
|
||||
return denied;
|
||||
}
|
||||
return ResponseEntity.ok(flowableClient.deleteModel(id));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- formKey 选择器数据源(T2.2)
|
||||
|
||||
@Operation(summary = "wftemplate 选择器数据源(超管)",
|
||||
|
||||
@@ -397,4 +397,37 @@ class FlowableClientTest {
|
||||
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(422));
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删草稿_DELETE_models按id透传() {
|
||||
FlowGatewayProperties p = props();
|
||||
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||
server.expect(ExpectedCount.once(), requestTo("http://localhost:8089/api/flow/models/m1"))
|
||||
.andExpect(method(HttpMethod.DELETE))
|
||||
.andRespond(withSuccess("{\"status\":0}", MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
Map<String, Object> resp = client.deleteModel("m1");
|
||||
|
||||
assertThat(resp).containsEntry("status", 0);
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删草稿_下游404透传FlowRemote且不重试() {
|
||||
FlowGatewayProperties p = props();
|
||||
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||
server.expect(ExpectedCount.once(), // 业务错不重试
|
||||
requestTo("http://localhost:8089/api/flow/models/nope"))
|
||||
.andExpect(method(HttpMethod.DELETE))
|
||||
.andRespond(withStatus(HttpStatus.NOT_FOUND).body("草稿不存在"));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
assertThatThrownBy(() -> client.deleteModel("nope"))
|
||||
.isInstanceOf(FlowRemoteException.class)
|
||||
.satisfies(e -> assertThat(((FlowRemoteException) e).getStatus().value()).isEqualTo(404));
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
@@ -288,6 +289,32 @@ class ProcessModelerControllerTest {
|
||||
verify(flowableClient, never()).createModel(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删草稿_超管透传200_非超管403门拦下游() {
|
||||
Map<String, Object> downstream = Map.of("status", 0);
|
||||
when(flowableClient.deleteModel("m1")).thenReturn(downstream);
|
||||
|
||||
ResponseEntity<Map<String, Object>> ok = controller.deleteModel(admin(), "m1");
|
||||
assertThat(ok.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(ok.getBody()).isEqualTo(downstream);
|
||||
|
||||
ResponseEntity<Map<String, Object>> denied = controller.deleteModel(normalUser(), "m1");
|
||||
assertThat(denied.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||
assertThat(denied.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
||||
verify(flowableClient).deleteModel("m1"); // 恰 1 次(仅超管):非超管被门拦,未落下游
|
||||
}
|
||||
|
||||
@Test
|
||||
void 胶水_删草稿_下游404经handler透传() throws Exception {
|
||||
when(flowableClient.deleteModel("nope"))
|
||||
.thenThrow(new FlowRemoteException(HttpStatus.NOT_FOUND, "flowable-service 删草稿返回 404"));
|
||||
|
||||
glueMvc().perform(delete("/api/workflow/models/{id}", "nope"))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("$.status").value(404))
|
||||
.andExpect(jsonPath("$.error").value("FLOW_REMOTE_ERROR"));
|
||||
}
|
||||
|
||||
// ---- 422 胶水透传:下游坏 XML 422 经既有 FlowGatewayExceptionHandler 出 FLOW_REMOTE_ERROR 信封 ----
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user