feat(iam): 初始化三期仓库作业角色

This commit is contained in:
2026-08-10 11:54:58 +08:00
parent 037527b4cb
commit 1200ef54ad
3 changed files with 317 additions and 2 deletions
@@ -0,0 +1,66 @@
package com.baiyue.iam.repository;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import java.nio.charset.StandardCharsets;
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);
assertThat(sql)
.contains("(4000004, 0, 'PLATFORM', 'WAREHOUSE_OPERATOR', '仓库操作员', 'SYSTEM'")
.contains("(4000005, 0, 'PLATFORM', 'WAREHOUSE_PICKER', '仓库拣货员', 'SYSTEM'")
.contains("(4000006, 0, 'PLATFORM', 'WAREHOUSE_TALLY', '仓库理货员', 'SYSTEM'")
.contains("ON DUPLICATE KEY UPDATE")
.contains("INSERT IGNORE INTO iam_role_permission")
.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("依赖的三期平台权限尚未完整部署")
.contains("最小权限授权未完整写入")
.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");
assertThat(roleGrantBlock(sql, "WAREHOUSE_PICKER"))
.doesNotContain("platform:firstleg:pda:assign")
.doesNotContain("platform:firstleg:pda:review")
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
assertThat(roleGrantBlock(sql, "WAREHOUSE_TALLY"))
.doesNotContain("platform:firstleg:inbound:loading:complete")
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
assertThat(sql)
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:outbound-dispatch:reverse'")
.doesNotContain("'WAREHOUSE_PICKER', 'platform:firstleg:smart-loading:delete'")
.doesNotContain("'WAREHOUSE_TALLY', 'firstleg:inbound:fee-detail:edit'");
}
private static void assertRoleGrant(String sql, String roleCode, String permissionCode) {
assertThat(sql).contains("('" + roleCode + "', '" + permissionCode + "')");
}
private static String roleGrantBlock(String sql, String roleCode) {
String marker = "-- " + switch (roleCode) {
case "WAREHOUSE_PICKER" -> "拣货员:";
case "WAREHOUSE_TALLY" -> "理货员:";
default -> throw new IllegalArgumentException("unsupported role " + roleCode);
};
int start = sql.indexOf(marker);
int end = sql.indexOf("\n-- ", start + marker.length());
return sql.substring(start, end > start ? end : sql.length());
}
}