fix(iam): 收敛仓库角色权限并纳入统一迁移

This commit is contained in:
2026-08-10 12:22:29 +08:00
parent edd5108625
commit b294695169
29 changed files with 1009 additions and 424 deletions
@@ -4,14 +4,23 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.assertj.core.api.Assertions.assertThat;
class WarehouseRoleSqlContractTest {
@Test
void initializesWarehouseRolesWithLeastPrivilegeAndStableIds() throws Exception {
String sql = new ClassPathResource("db/phase3-warehouse-roles.sql")
.getContentAsString(StandardCharsets.UTF_8);
assertWarehouseRoleContract(moduleSql());
}
@Test
void unifiedDeploymentContainsTheSameWarehouseRoleContract() throws Exception {
assertWarehouseRoleContract(unifiedSql());
}
private static void assertWarehouseRoleContract(String sql) {
assertThat(sql)
.contains("(4000004, 0, 'PLATFORM', 'WAREHOUSE_OPERATOR', '仓库操作员', 'SYSTEM'")
@@ -22,21 +31,31 @@ class WarehouseRoleSqlContractTest {
.contains("'WAREHOUSE_PICKER', 'platform:firstleg:pda:work'")
.contains("'WAREHOUSE_TALLY', 'platform:firstleg:pda:review'")
.contains("'WAREHOUSE_TALLY', 'platform:firstleg:inbound:loading:edit'")
.contains("'WAREHOUSE_OPERATOR', 'platform:firstleg:outbound-dispatch:confirm'")
.contains("WHERE role_code = 'WAREHOUSE_OPERATOR') <> 34")
.contains("WHERE role_code = 'WAREHOUSE_PICKER') <> 18")
.contains("WHERE role_code = 'WAREHOUSE_TALLY') <> 23")
.contains("'WAREHOUSE_OPERATOR', 'platform:firstleg:inbound:loading:edit'")
.contains("WHERE role_code = 'WAREHOUSE_OPERATOR') <> 5")
.contains("WHERE role_code = 'WAREHOUSE_PICKER') <> 2")
.contains("WHERE role_code = 'WAREHOUSE_TALLY') <> 12")
.contains("依赖的三期平台权限尚未完整部署")
.contains("DELETE role_permission")
.contains("expected.permission_code IS NULL")
.contains("最小权限授权未完整写入")
.contains("grant_row.tenant_id = 0) <> 19")
.contains("(6000004, 4000004, 0, 'TENANT', NULL)")
.contains("(6000005, 4000005, 0, 'TENANT', NULL)")
.contains("(6000006, 4000006, 0, 'TENANT', NULL)");
assertRoleGrant(sql, "WAREHOUSE_PICKER", "platform:firstleg:pda:work");
assertRoleGrant(sql, "WAREHOUSE_TALLY", "platform:firstleg:pda:review");
assertRoleGrant(sql, "WAREHOUSE_OPERATOR", "platform:firstleg:pda:assign");
assertRoleGrant(sql, "WAREHOUSE_OPERATOR", "platform:firstleg:inbound:loading:edit");
assertThat(roleGrantBlock(sql, "WAREHOUSE_PICKER"))
.doesNotContain("platform:order")
.doesNotContain("platform:master-data")
.doesNotContain("platform:warehouse:list")
.doesNotContain("platform:firstleg:inbound:")
.doesNotContain("platform:firstleg:container:")
.doesNotContain("platform:firstleg:preload:")
.doesNotContain("platform:firstleg:loading-list:")
.doesNotContain("platform:firstleg:pda:assign")
.doesNotContain("platform:firstleg:pda:review")
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
@@ -44,9 +63,15 @@ class WarehouseRoleSqlContractTest {
.doesNotContain("platform:firstleg:inbound:loading:complete")
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
assertThat(sql)
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:pda:assign'")
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:inbound:loading:complete'")
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:outbound-dispatch:confirm'")
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:outbound-dispatch:reverse'")
.doesNotContain("'WAREHOUSE_PICKER', 'platform:firstleg:smart-loading:delete'")
.doesNotContain("'WAREHOUSE_TALLY', 'firstleg:inbound:fee-detail:edit'");
.doesNotContain("'WAREHOUSE_TALLY', 'firstleg:inbound:fee-detail:edit'")
.doesNotContain("'WAREHOUSE_PICKER', 'merchant:")
.doesNotContain("'WAREHOUSE_OPERATOR', 'merchant:")
.doesNotContain("'WAREHOUSE_TALLY', 'merchant:");
}
private static void assertRoleGrant(String sql, String roleCode, String permissionCode) {
@@ -63,4 +88,17 @@ class WarehouseRoleSqlContractTest {
int end = sql.indexOf("\n-- ", start + marker.length());
return sql.substring(start, end > start ? end : sql.length());
}
private static String moduleSql() throws Exception {
return new ClassPathResource("db/phase3-warehouse-roles.sql")
.getContentAsString(StandardCharsets.UTF_8);
}
private static String unifiedSql() throws Exception {
Path path = Path.of("deploy/sql/头程数据库统一增量-MySQL8.sql");
if (!Files.exists(path)) {
path = Path.of("../deploy/sql/头程数据库统一增量-MySQL8.sql").normalize();
}
return Files.readString(path, StandardCharsets.UTF_8);
}
}