feat(P0②b/P1⑥): overlay审计+strict分流 + 运行时DELETE + publish菜单授权
- PageSchemaController: ?strict分流(白名单外组件可选400,默认warn不破存量)
+ GET /api/page/schema/overlay/audit 白名单对账(只读advisory)
- 运行时DELETE: PageSchemaWriter.deleteStandard + DELETE /api/page/schema/{tpl}/standard
(@Transactional对称撤销:删schema+overlay+软删菜单+清sys_role_menu)
- 菜单授权: MenuRegistrar.grantToRoles(复用sys_role_menu ON CONFLICT范式)
+ PublishOrchestrator.grantMenuRoles + DesignFeatureController.publish透传roleIds(缺省warning)
- 单测 PageSchemaWriter6/MenuRegistrar4/PageSchemaController28/DeploymentPackageBuilder1无回归
scripts/p1-6-acceptance.sh 真库验收(授权落库+负控+DELETE级联+GET404)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,31 @@ public class MenuRegistrar {
|
|||||||
return menuId;
|
return menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P1⑥:给菜单授权角色(写 sys_role_menu)。发布后若不授权,非超管(无 sys_role_menu 行)看不见新功能。
|
||||||
|
* 复用 {@code AdminWriteController.setRoleMenus} 的 {@code (roleid,menuid) ON CONFLICT DO NOTHING} 幂等范式。
|
||||||
|
*
|
||||||
|
* @param menuId 菜单 id
|
||||||
|
* @param roleIds 授权角色 id 列表
|
||||||
|
* @param operator 操作人(审计)
|
||||||
|
* @return 实际写入(授权)的角色数;menuId/roleIds 为空则 0(不写库)
|
||||||
|
*/
|
||||||
|
public int grantToRoles(String menuId, List<String> roleIds, String operator) {
|
||||||
|
if (menuId == null || menuId.isBlank() || roleIds == null || roleIds.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int granted = 0;
|
||||||
|
for (String roleId : roleIds) {
|
||||||
|
if (roleId == null || roleId.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
granted += jdbcTemplate.update(
|
||||||
|
"INSERT INTO sys_role_menu(roleid, menuid) VALUES(?,?) ON CONFLICT DO NOTHING",
|
||||||
|
roleId.trim(), menuId.trim());
|
||||||
|
}
|
||||||
|
return granted;
|
||||||
|
}
|
||||||
|
|
||||||
private ParentMenu ensureNewFeatureParent() {
|
private ParentMenu ensureNewFeatureParent() {
|
||||||
List<String> existingDir = jdbcTemplate.queryForList(
|
List<String> existingDir = jdbcTemplate.queryForList(
|
||||||
"SELECT TRIM(sys_menu_id) FROM sys_menu WHERE name='" + NEW_FEATURE_DIR
|
"SELECT TRIM(sys_menu_id) FROM sys_menu WHERE name='" + NEW_FEATURE_DIR
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ public class PublishOrchestrator {
|
|||||||
return menuRegistrar.register(templateId, menuName, parentMenuId, operator);
|
return menuRegistrar.register(templateId, menuName, parentMenuId, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** P1⑥:给已注册菜单授权角色(写 sys_role_menu),返回授权角色数(roleIds 空则 0)。 */
|
||||||
|
public int grantMenuRoles(String menuId, List<String> roleIds, String operator) {
|
||||||
|
return menuRegistrar.grantToRoles(menuId, roleIds, operator);
|
||||||
|
}
|
||||||
|
|
||||||
/** generateDeploymentPackage != false 时生成 production 人审部署包;否则返回 null。 */
|
/** generateDeploymentPackage != false 时生成 production 人审部署包;否则返回 null。 */
|
||||||
public DeploymentPackage buildDeploymentPackage(String entityId, String tableName, String templateId,
|
public DeploymentPackage buildDeploymentPackage(String entityId, String tableName, String templateId,
|
||||||
String menuName, String menuId,
|
String menuName, String menuId,
|
||||||
|
|||||||
@@ -77,6 +77,24 @@ public class PageSchemaWriter {
|
|||||||
return etag;
|
return etag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标准层页面 schema(运行时撤销净新页)。对称 {@link #upsertStandard},删除也收口唯一写口,
|
||||||
|
* 不走裸 JDBC 旁路。
|
||||||
|
*
|
||||||
|
* @param templateId 页面模板 id
|
||||||
|
* @param operator 操作者标识(审计)
|
||||||
|
* @return 受影响行数(0 = 不存在,幂等)
|
||||||
|
*/
|
||||||
|
public int deleteStandard(String templateId, String operator) {
|
||||||
|
if (templateId == null || templateId.isBlank()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "templateId 不能为空");
|
||||||
|
}
|
||||||
|
int n = jdbcTemplate.update("DELETE FROM sys_page_schema WHERE template_id = ?", templateId);
|
||||||
|
log.info("[standard-delete] operator={} templateId={} deleted={}",
|
||||||
|
operator == null || operator.isBlank() ? "UNKNOWN" : operator, templateId, n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
static String sha256(String text) {
|
static String sha256(String text) {
|
||||||
try {
|
try {
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
|||||||
@@ -395,6 +395,18 @@ public class DesignFeatureController {
|
|||||||
String menuId = publishOrchestrator.registerMenu(templateId, menuName, parentMenuId, operator);
|
String menuId = publishOrchestrator.registerMenu(templateId, menuName, parentMenuId, operator);
|
||||||
data.put("menuId", menuId);
|
data.put("menuId", menuId);
|
||||||
|
|
||||||
|
// P1⑥:可选 roleIds 给菜单授权(写 sys_role_menu);缺省则新功能仅超管可见,返 warning。
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> roleIds = body.get("roleIds") instanceof List<?> rs
|
||||||
|
? rs.stream().map(String::valueOf).filter(s -> !s.isBlank()).toList()
|
||||||
|
: List.of();
|
||||||
|
int grantedRoles = publishOrchestrator.grantMenuRoles(menuId, roleIds, operator);
|
||||||
|
data.put("grantedRoleCount", grantedRoles);
|
||||||
|
if (grantedRoles == 0) {
|
||||||
|
data.put("menuVisibilityWarning",
|
||||||
|
"未指定 roleIds,新功能菜单仅超管可见;请到「角色菜单授权」为业务角色授权");
|
||||||
|
}
|
||||||
|
|
||||||
boolean generatePkg = !(Boolean.FALSE.equals(body.get("generateDeploymentPackage")));
|
boolean generatePkg = !(Boolean.FALSE.equals(body.get("generateDeploymentPackage")));
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<String> flowsForPkg = (List<String>) data.get("flows");
|
List<String> flowsForPkg = (List<String>) data.get("flows");
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ public class PageSchemaController {
|
|||||||
@PutMapping("/api/page/schema/{templateId}/overlay")
|
@PutMapping("/api/page/schema/{templateId}/overlay")
|
||||||
public ResponseEntity<Map<String, Object>> putOverlay(
|
public ResponseEntity<Map<String, Object>> putOverlay(
|
||||||
@PathVariable String templateId,
|
@PathVariable String templateId,
|
||||||
|
@RequestParam(defaultValue = "false") boolean strict,
|
||||||
@RequestBody String schemaJsonRaw) {
|
@RequestBody String schemaJsonRaw) {
|
||||||
|
|
||||||
requireAdmin();
|
requireAdmin();
|
||||||
@@ -193,6 +194,13 @@ public class PageSchemaController {
|
|||||||
// 以后若把 AI 写路径收口到本端点,再按来源加 strict 分流参数。
|
// 以后若把 AI 写路径收口到本端点,再按来源加 strict 分流参数。
|
||||||
TypedPageSchemaReport validation = typedSchemaValidator.validate(schemaJsonRaw);
|
TypedPageSchemaReport validation = typedSchemaValidator.validate(schemaJsonRaw);
|
||||||
if (!validation.valid()) {
|
if (!validation.valid()) {
|
||||||
|
if (strict) {
|
||||||
|
// P0②(b) strict 分流:AI 写路径/净新页可选严格,白名单外组件直接 400。
|
||||||
|
// 默认 strict=false 保留设计器存量页只告警不阻断的现状(存量 13 类组件会触雷)。
|
||||||
|
log.warn("[F4-L1][putOverlay][strict] 拒绝白名单外 schema templateId={}: {}", templateId, validation.issues());
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(fail("typed schema 校验失败(strict)", validationData(validation)));
|
||||||
|
}
|
||||||
log.warn("[F4-L1][putOverlay] typed-recipe 校验 {} 项告警(设计器路径不阻断)templateId={}: {}",
|
log.warn("[F4-L1][putOverlay] typed-recipe 校验 {} 项告警(设计器路径不阻断)templateId={}: {}",
|
||||||
validation.issues().size(), templateId, validation.issues());
|
validation.issues().size(), templateId, validation.issues());
|
||||||
}
|
}
|
||||||
@@ -240,6 +248,43 @@ public class PageSchemaController {
|
|||||||
return ResponseEntity.ok(ok("overlay 保存成功", data));
|
return ResponseEntity.ok(ok("overlay 保存成功", data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "overlay 白名单对账(只读 advisory):列出使用 typed 白名单外组件的 overlay 模板",
|
||||||
|
description = "P0②(b)。扫 sys_page_schema_overlay,对每行跑 typed 校验,聚合 PageComponentRegistry 白名单外组件;"
|
||||||
|
+ "不阻断,供逐步 strict 化(?strict=true)的决策依据。")
|
||||||
|
@GetMapping("/api/page/schema/overlay/audit")
|
||||||
|
public ResponseEntity<Map<String, Object>> auditOverlay() {
|
||||||
|
requireAdmin();
|
||||||
|
List<Map<String, Object>> rows;
|
||||||
|
try {
|
||||||
|
rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT template_id, schema_json::text AS schema_json FROM sys_page_schema_overlay ORDER BY template_id");
|
||||||
|
} catch (DataAccessException ex) {
|
||||||
|
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
|
||||||
|
.body(fail("overlay 表不可用:" + ex.getMessage()));
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> offenders = new java.util.ArrayList<>();
|
||||||
|
java.util.Set<String> distinct = new java.util.TreeSet<>();
|
||||||
|
for (Map<String, Object> row : rows) {
|
||||||
|
TypedPageSchemaReport report = typedSchemaValidator.validate(String.valueOf(row.get("schema_json")));
|
||||||
|
List<String> bad = report.usedComponents().stream()
|
||||||
|
.filter(c -> !componentRegistry.supportsComponent(c))
|
||||||
|
.sorted().toList();
|
||||||
|
if (!bad.isEmpty()) {
|
||||||
|
Map<String, Object> o = new LinkedHashMap<>();
|
||||||
|
o.put("templateId", String.valueOf(row.get("template_id")));
|
||||||
|
o.put("unsupportedComponents", bad);
|
||||||
|
offenders.add(o);
|
||||||
|
distinct.addAll(bad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
data.put("overlayCount", rows.size());
|
||||||
|
data.put("offenderCount", offenders.size());
|
||||||
|
data.put("distinctUnsupportedComponents", new java.util.ArrayList<>(distinct));
|
||||||
|
data.put("offenders", offenders);
|
||||||
|
return ResponseEntity.ok(ok("overlay 白名单对账(advisory)", data));
|
||||||
|
}
|
||||||
|
|
||||||
// ================================================================ PUT standard(写标准层·净新页/设计中心新建/AI 产物)
|
// ================================================================ PUT standard(写标准层·净新页/设计中心新建/AI 产物)
|
||||||
|
|
||||||
@Operation(summary = "写入/更新标准层页面 schema(净新页/设计中心新建/AI 产物,仅管理员)",
|
@Operation(summary = "写入/更新标准层页面 schema(净新页/设计中心新建/AI 产物,仅管理员)",
|
||||||
@@ -297,6 +342,44 @@ public class PageSchemaController {
|
|||||||
return ResponseEntity.ok(ok("overlay 已删除,已还原标准版", null));
|
return ResponseEntity.ok(ok("overlay 已删除,已还原标准版", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除标准层净新页(运行时撤销,仅管理员)",
|
||||||
|
description = "P1⑥:对称撤销 publish 写入——删 sys_page_schema 标准层 + overlay + 软删关联菜单 + 清 sys_role_menu 授权。"
|
||||||
|
+ "默认不删服务流(流可能被多页/引擎复用)。事务内执行,半删不残留。幂等。")
|
||||||
|
@DeleteMapping("/api/page/schema/{templateId}/standard")
|
||||||
|
@org.springframework.transaction.annotation.Transactional
|
||||||
|
public ResponseEntity<Map<String, Object>> deleteStandard(@PathVariable String templateId) {
|
||||||
|
requireAdmin();
|
||||||
|
String operator = currentUserId();
|
||||||
|
// 1. 关联菜单(view_templateid=该页),清角色授权 + 软删菜单(对称 publish 的菜单注册/授权)
|
||||||
|
List<String> menuIds = jdbcTemplate.queryForList(
|
||||||
|
"SELECT sys_menu_id FROM sys_menu WHERE TRIM(view_templateid)=?", String.class, templateId);
|
||||||
|
int roleMenu = 0;
|
||||||
|
for (String mid : menuIds) {
|
||||||
|
roleMenu += jdbcTemplate.update("DELETE FROM sys_role_menu WHERE TRIM(menuid)=?", mid.trim());
|
||||||
|
}
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
int menus = jdbcTemplate.update(
|
||||||
|
"UPDATE sys_menu SET isactive=0, updatetime=?, updateby=? WHERE TRIM(view_templateid)=?",
|
||||||
|
now, operator, templateId);
|
||||||
|
// 2. 删标准层(收口 PageSchemaWriter,不裸 JDBC) + overlay
|
||||||
|
int standard = pageSchemaWriter.deleteStandard(templateId, operator);
|
||||||
|
int overlay = 0;
|
||||||
|
try {
|
||||||
|
overlay = jdbcTemplate.update("DELETE FROM sys_page_schema_overlay WHERE template_id = ?", templateId);
|
||||||
|
} catch (DataAccessException ex) {
|
||||||
|
log.debug("[deleteStandard] overlay 表不可用(忽略): {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
log.info("[deleteStandard] operator={} templateId={} standard={} overlay={} menus={} roleMenu={}",
|
||||||
|
operator, templateId, standard, overlay, menus, roleMenu);
|
||||||
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
|
data.put("templateId", templateId);
|
||||||
|
data.put("standardDeleted", standard);
|
||||||
|
data.put("overlayDeleted", overlay);
|
||||||
|
data.put("menusSoftDeleted", menus);
|
||||||
|
data.put("roleMenuCleared", roleMenu);
|
||||||
|
return ResponseEntity.ok(ok("净新页已删除(schema+overlay+菜单+授权)", data));
|
||||||
|
}
|
||||||
|
|
||||||
// ================================================================ 内部工具
|
// ================================================================ 内部工具
|
||||||
|
|
||||||
/** 构造统一 schema 响应(含 ETag/304 + X-Schema-Layer 头)。 */
|
/** 构造统一 schema 响应(含 ETag/304 + X-Schema-Layer 头)。 */
|
||||||
|
|||||||
@@ -59,4 +59,30 @@ class MenuRegistrarTest {
|
|||||||
org.mockito.ArgumentMatchers.contains("UPDATE sys_menu"),
|
org.mockito.ArgumentMatchers.contains("UPDATE sys_menu"),
|
||||||
eq("演示功能改名"), eq("TPL-1"), any(), eq("admin"), eq("MENU-EXIST"));
|
eq("演示功能改名"), eq("TPL-1"), any(), eq("admin"), eq("MENU-EXIST"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void grantToRolesInsertsPerRole() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
String insert = "INSERT INTO sys_role_menu(roleid, menuid) VALUES(?,?) ON CONFLICT DO NOTHING";
|
||||||
|
when(jdbc.update(eq(insert), eq("R1"), eq("M9"))).thenReturn(1);
|
||||||
|
when(jdbc.update(eq(insert), eq("R2"), eq("M9"))).thenReturn(1);
|
||||||
|
|
||||||
|
MenuRegistrar reg = new MenuRegistrar(jdbc);
|
||||||
|
int granted = reg.grantToRoles("M9", List.of("R1", "R2"), "admin");
|
||||||
|
|
||||||
|
assertThat(granted).isEqualTo(2);
|
||||||
|
verify(jdbc, times(1)).update(eq(insert), eq("R1"), eq("M9"));
|
||||||
|
verify(jdbc, times(1)).update(eq(insert), eq("R2"), eq("M9"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void grantToRolesEmptyIsNoOp() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
MenuRegistrar reg = new MenuRegistrar(jdbc);
|
||||||
|
|
||||||
|
assertThat(reg.grantToRoles("M9", List.of(), "admin")).isZero();
|
||||||
|
assertThat(reg.grantToRoles(" ", List.of("R1"), "admin")).isZero();
|
||||||
|
assertThat(reg.grantToRoles("M9", List.of(" "), "admin")).isZero();
|
||||||
|
verify(jdbc, times(0)).update(anyString(), anyString(), anyString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,4 +79,25 @@ class PageSchemaWriterTest {
|
|||||||
assertEquals(HttpStatus.BAD_REQUEST, e2.getStatusCode());
|
assertEquals(HttpStatus.BAD_REQUEST, e2.getStatusCode());
|
||||||
assertTrue(e2.getReason() != null);
|
assertTrue(e2.getReason() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("5. deleteStandard 删标准层一次,返回受影响行数(幂等,P1⑥)")
|
||||||
|
void deleteStandardRemovesAndReturnsCount() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
when(jdbc.update(anyString(), eq(TID))).thenReturn(1);
|
||||||
|
PageSchemaWriter writer = new PageSchemaWriter(jdbc);
|
||||||
|
|
||||||
|
assertEquals(1, writer.deleteStandard(TID, "admin"));
|
||||||
|
verify(jdbc).update(eq("DELETE FROM sys_page_schema WHERE template_id = ?"), eq(TID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("6. deleteStandard 空 templateId → 400,不写库")
|
||||||
|
void deleteStandardBlankRejected() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
PageSchemaWriter writer = new PageSchemaWriter(jdbc);
|
||||||
|
ResponseStatusException e = assertThrows(ResponseStatusException.class,
|
||||||
|
() -> writer.deleteStandard(" ", "admin"));
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ class PageSchemaControllerTest {
|
|||||||
// 注入 ADMIN 上下文
|
// 注入 ADMIN 上下文
|
||||||
setAdminSession();
|
setAdminSession();
|
||||||
|
|
||||||
var resp = c.putOverlay(TID, SCHEMA_OVERLAY);
|
var resp = c.putOverlay(TID, false, SCHEMA_OVERLAY);
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||||
assertEquals(0, resp.getBody().get("status"));
|
assertEquals(0, resp.getBody().get("status"));
|
||||||
assertTrue(resp.getBody().get("data") != null);
|
assertTrue(resp.getBody().get("data") != null);
|
||||||
@@ -309,7 +309,7 @@ class PageSchemaControllerTest {
|
|||||||
org.springframework.web.server.ResponseStatusException ex =
|
org.springframework.web.server.ResponseStatusException ex =
|
||||||
org.junit.jupiter.api.Assertions.assertThrows(
|
org.junit.jupiter.api.Assertions.assertThrows(
|
||||||
org.springframework.web.server.ResponseStatusException.class,
|
org.springframework.web.server.ResponseStatusException.class,
|
||||||
() -> c.putOverlay(TID, " "));
|
() -> c.putOverlay(TID, false, " "));
|
||||||
assertEquals(org.springframework.http.HttpStatus.BAD_REQUEST, ex.getStatusCode());
|
assertEquals(org.springframework.http.HttpStatus.BAD_REQUEST, ex.getStatusCode());
|
||||||
clearSession();
|
clearSession();
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ class PageSchemaControllerTest {
|
|||||||
org.springframework.web.server.ResponseStatusException ex =
|
org.springframework.web.server.ResponseStatusException ex =
|
||||||
org.junit.jupiter.api.Assertions.assertThrows(
|
org.junit.jupiter.api.Assertions.assertThrows(
|
||||||
org.springframework.web.server.ResponseStatusException.class,
|
org.springframework.web.server.ResponseStatusException.class,
|
||||||
() -> c.putOverlay(TID, SCHEMA_OVERLAY));
|
() -> c.putOverlay(TID, false, SCHEMA_OVERLAY));
|
||||||
assertEquals(HttpStatus.FORBIDDEN, ex.getStatusCode());
|
assertEquals(HttpStatus.FORBIDDEN, ex.getStatusCode());
|
||||||
clearSession();
|
clearSession();
|
||||||
}
|
}
|
||||||
@@ -431,7 +431,7 @@ class PageSchemaControllerTest {
|
|||||||
+ "\"onEvent\":{\"click\":{\"actions\":[{\"actionType\":\"setValue\"}]}}}],"
|
+ "\"onEvent\":{\"click\":{\"actions\":[{\"actionType\":\"setValue\"}]}}}],"
|
||||||
+ "\"filter\":{\"type\":\"form\",\"body\":[{\"type\":\"search-box\"}]}}}";
|
+ "\"filter\":{\"type\":\"form\",\"body\":[{\"type\":\"search-box\"}]}}}";
|
||||||
|
|
||||||
var resp = c.putOverlay(TID, legacyPage);
|
var resp = c.putOverlay(TID, false, legacyPage);
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, resp.getStatusCode(),
|
assertEquals(HttpStatus.OK, resp.getStatusCode(),
|
||||||
"设计器编辑存量页应放行保存,不被 AI 作用域的 typed-recipe 白名单阻断");
|
"设计器编辑存量页应放行保存,不被 AI 作用域的 typed-recipe 白名单阻断");
|
||||||
@@ -441,6 +441,23 @@ class PageSchemaControllerTest {
|
|||||||
clearSession();
|
clearSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("20b. PUT overlay ?strict=true:白名单外组件(search-box) 直接 400,不写库(P0②b)")
|
||||||
|
void putOverlayStrictRejectsUnsupported() {
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
PageSchemaController c = new PageSchemaController(jdbc);
|
||||||
|
setAdminSession();
|
||||||
|
String legacyPage = "{\"type\":\"page\",\"body\":{\"type\":\"crud\","
|
||||||
|
+ "\"filter\":{\"type\":\"form\",\"body\":[{\"type\":\"search-box\"}]}}}";
|
||||||
|
|
||||||
|
var resp = c.putOverlay(TID, true, legacyPage);
|
||||||
|
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, resp.getStatusCode(),
|
||||||
|
"strict=true 时白名单外组件应 400");
|
||||||
|
verify(jdbc, org.mockito.Mockito.never()).update(anyString(), any(), any(), any(), any(), any(), any());
|
||||||
|
clearSession();
|
||||||
|
}
|
||||||
|
|
||||||
// ── M3a 标准层写端点(净新页/设计中心新建/AI 产物,单一写真相) ──────────────
|
// ── M3a 标准层写端点(净新页/设计中心新建/AI 产物,单一写真相) ──────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
68
scripts/p1-6-acceptance.sh
Normal file
68
scripts/p1-6-acceptance.sh
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# P1⑥ · 端到端验收:① publish 菜单授权(写 sys_role_menu) ② 运行时 DELETE 净新页(对称撤销 schema+overlay+菜单+授权)
|
||||||
|
#
|
||||||
|
# 用法:先以 dev profile 起 8094,再 BASE=http://localhost:8094 bash scripts/p1-6-acceptance.sh
|
||||||
|
set -uo pipefail
|
||||||
|
BASE=${BASE:-http://localhost:8094}
|
||||||
|
ACCT=${ACCT:-admin}; PW=${PW:-111111}
|
||||||
|
PGURL=${PGURL:-postgresql://zhengwr@localhost:5433/eip4dev}
|
||||||
|
TS=$(date +%s)
|
||||||
|
TABLE="EIP4PT_P16${TS}"
|
||||||
|
ROLE="EIP4PT_TROLE${TS}"
|
||||||
|
FAIL=0
|
||||||
|
jqpy() { python3 -c "import sys,json;d=json.load(sys.stdin,strict=False);print(eval(\"d$1\"))" 2>/dev/null; }
|
||||||
|
ok() { echo " ✓ $*"; }
|
||||||
|
bad() { echo " ✗ $*"; FAIL=1; }
|
||||||
|
pg() { PGOPTIONS='-c search_path=eip3' psql "$PGURL" -At -c "$1" 2>/dev/null; }
|
||||||
|
|
||||||
|
TOK=$(curl -s -X POST "$BASE/api/auth/login" -H 'Content-Type: application/json' \
|
||||||
|
-d "{\"account\":\"$ACCT\",\"password\":\"$PW\"}" | jqpy "['token']")
|
||||||
|
H=(-H "Authorization: Bearer $TOK" -H 'Content-Type: application/json')
|
||||||
|
[ -n "${TOK:-}" ] && [ "$TOK" != "None" ] && ok "login len=${#TOK}" || { bad "login 失败"; exit 1; }
|
||||||
|
|
||||||
|
echo "[1] 建实体 + recipe 编译 + 发布(带 roleIds=[$ROLE])"
|
||||||
|
EID=$(curl -s -X POST "$BASE/api/meta/entity" "${H[@]}" -d "{\"tablename\":\"$TABLE\",\"name\":\"P16演示\",\"attributes\":[{\"column\":\"TITLE\",\"display\":\"标题\",\"type\":\"string\",\"length\":100,\"mandatory\":true}]}" | jqpy "['data']['entityId']")
|
||||||
|
TID=$(curl -s -X POST "$BASE/api/design/recipe/compile" "${H[@]}" -d "{\"tableName\":\"$TABLE\",\"recipe\":\"maintenance-crud-v1\",\"title\":\"P16演示\",\"displayField\":\"TITLE\"}" | jqpy "['data']['templateId']")
|
||||||
|
[ -n "$TID" ] && [ "$TID" != "None" ] && ok "compile templateId=$TID" || bad "compile 失败"
|
||||||
|
PUB=$(curl -s -X POST "$BASE/api/design/publish" "${H[@]}" -d "{\"entityId\":\"$EID\",\"tableName\":\"$TABLE\",\"templateId\":\"$TID\",\"menuName\":\"P16演示\",\"roleIds\":[\"$ROLE\"],\"generateDeploymentPackage\":false}")
|
||||||
|
MENUID=$(echo "$PUB" | jqpy "['data']['menuId']")
|
||||||
|
GRANTED=$(echo "$PUB" | jqpy "['data']['grantedRoleCount']")
|
||||||
|
[ "$GRANTED" = "1" ] && ok "发布授权 grantedRoleCount=1 menuId=$MENUID" || bad "授权数应=1,实=$GRANTED"
|
||||||
|
|
||||||
|
echo "[2] 菜单授权落库:psql 查 sys_role_menu"
|
||||||
|
N=$(pg "SELECT count(*) FROM sys_role_menu WHERE TRIM(roleid)='$ROLE' AND TRIM(menuid)='$MENUID';")
|
||||||
|
[ "$N" = "1" ] && ok "sys_role_menu 有 ($ROLE,$MENUID)" || bad "sys_role_menu 缺授权行(n=$N)"
|
||||||
|
|
||||||
|
echo "[3] 发布无 roleIds → warning(负控)"
|
||||||
|
TABLE2="${TABLE}B"
|
||||||
|
EID2=$(curl -s -X POST "$BASE/api/meta/entity" "${H[@]}" -d "{\"tablename\":\"$TABLE2\",\"name\":\"P16B\",\"attributes\":[{\"column\":\"TITLE\",\"type\":\"string\",\"length\":100,\"mandatory\":true}]}" | jqpy "['data']['entityId']")
|
||||||
|
TID2=$(curl -s -X POST "$BASE/api/design/recipe/compile" "${H[@]}" -d "{\"tableName\":\"$TABLE2\",\"recipe\":\"maintenance-crud-v1\",\"title\":\"P16B\",\"displayField\":\"TITLE\"}" | jqpy "['data']['templateId']")
|
||||||
|
WARN=$(curl -s -X POST "$BASE/api/design/publish" "${H[@]}" -d "{\"entityId\":\"$EID2\",\"tableName\":\"$TABLE2\",\"templateId\":\"$TID2\",\"menuName\":\"P16B\",\"generateDeploymentPackage\":false}" | jqpy "['data'].get('menuVisibilityWarning','')")
|
||||||
|
[ -n "$WARN" ] && ok "无 roleIds 返 warning(仅超管可见)" || bad "无 roleIds 应返 warning"
|
||||||
|
|
||||||
|
echo "[4] 运行时 DELETE 净新页 $TID(对称撤销)"
|
||||||
|
DEL=$(curl -s -X DELETE "$BASE/api/page/schema/$TID/standard" "${H[@]}")
|
||||||
|
SD=$(echo "$DEL" | jqpy "['data']['standardDeleted']")
|
||||||
|
MD=$(echo "$DEL" | jqpy "['data']['menusSoftDeleted']")
|
||||||
|
RM=$(echo "$DEL" | jqpy "['data']['roleMenuCleared']")
|
||||||
|
{ [ "$SD" -ge 1 ] 2>/dev/null && ok "standardDeleted=$SD"; } || bad "standardDeleted 应≥1(实=$SD)"
|
||||||
|
{ [ "$MD" -ge 1 ] 2>/dev/null && ok "menusSoftDeleted=$MD"; } || bad "menusSoftDeleted 应≥1(实=$MD)"
|
||||||
|
{ [ "$RM" -ge 1 ] 2>/dev/null && ok "roleMenuCleared=$RM"; } || bad "roleMenuCleared 应≥1(实=$RM)"
|
||||||
|
|
||||||
|
echo "[5] DELETE 后核对:GET schema=404、菜单 isactive=0、授权已清"
|
||||||
|
CODE=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/api/page/schema/$TID" "${H[@]}")
|
||||||
|
[ "$CODE" = "404" ] && ok "GET schema → 404(standard 已删)" || bad "GET schema 应 404,实=$CODE"
|
||||||
|
N=$(pg "SELECT count(*) FROM sys_menu WHERE TRIM(view_templateid)='$TID' AND isactive=1;")
|
||||||
|
[ "$N" = "0" ] && ok "菜单已软删(isactive=1 行=0)" || bad "菜单未软删(active=$N)"
|
||||||
|
N=$(pg "SELECT count(*) FROM sys_role_menu WHERE TRIM(roleid)='$ROLE';")
|
||||||
|
[ "$N" = "0" ] && ok "授权已清(sys_role_menu 行=0)" || bad "授权未清(n=$N)"
|
||||||
|
|
||||||
|
echo "[6] 清理"
|
||||||
|
for T in "$TABLE" "$TABLE2"; do curl -s -X DELETE "$BASE/api/meta/entity/$T" "${H[@]}" >/dev/null; done
|
||||||
|
pg "DELETE FROM sys_role_menu WHERE TRIM(roleid) IN ('$ROLE');" >/dev/null
|
||||||
|
pg "DELETE FROM sys_page_schema WHERE template_id IN ('$TID','$TID2');" >/dev/null
|
||||||
|
pg "UPDATE sys_menu SET isactive=0 WHERE TRIM(view_templateid) IN ('$TID','$TID2');" >/dev/null
|
||||||
|
ok "清理完成"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
[ "$FAIL" = "0" ] && echo "[完成] P1⑥ 菜单授权 + 运行时DELETE 端到端验收 ✅ 全绿" || { echo "[失败] 存在未通过项 ✗"; exit 1; }
|
||||||
Reference in New Issue
Block a user