feat: complete phase 5 overseas fulfillment contracts
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
USE baiyue_iam;
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 五期海外排车、出库与派送权限。列表权限同时覆盖列表和详情只读,写操作保持独立授权。
|
||||
DROP PROCEDURE IF EXISTS guard_phase5_delivery_permission_ids;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE guard_phase5_delivery_permission_ids()
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM iam_permission
|
||||
WHERE (id = 5107016 AND permission_code <> 'platform:overseas-warehouse:dispatch:edit')
|
||||
OR (id = 5107017 AND permission_code <> 'platform:overseas-warehouse:dispatch:cancel')
|
||||
OR (id = 5107018 AND permission_code <> 'platform:overseas-warehouse:dispatch:transfer-delivery')
|
||||
OR (id = 5107090 AND permission_code <> 'platform:overseas-warehouse:outbound:list')
|
||||
OR (id = 5107091 AND permission_code <> 'platform:overseas-warehouse:outbound:create')
|
||||
OR (id = 5107092 AND permission_code <> 'platform:overseas-warehouse:delivery:list')
|
||||
OR (id = 5107093 AND permission_code <> 'platform:overseas-warehouse:outbound:cancel')
|
||||
OR (id = 5306000 AND permission_code <> 'merchant:warehouse:delivery:list')
|
||||
OR (id = 5306001 AND permission_code <> 'merchant:warehouse:delivery:create')
|
||||
) OR EXISTS (
|
||||
SELECT 1 FROM iam_permission
|
||||
WHERE (permission_code = 'platform:overseas-warehouse:dispatch:edit' AND id <> 5107016)
|
||||
OR (permission_code = 'platform:overseas-warehouse:dispatch:cancel' AND id <> 5107017)
|
||||
OR (permission_code = 'platform:overseas-warehouse:dispatch:transfer-delivery' AND id <> 5107018)
|
||||
OR (permission_code = 'platform:overseas-warehouse:outbound:list' AND id <> 5107090)
|
||||
OR (permission_code = 'platform:overseas-warehouse:outbound:create' AND id <> 5107091)
|
||||
OR (permission_code = 'platform:overseas-warehouse:delivery:list' AND id <> 5107092)
|
||||
OR (permission_code = 'platform:overseas-warehouse:outbound:cancel' AND id <> 5107093)
|
||||
OR (permission_code = 'merchant:warehouse:delivery:list' AND id <> 5306000)
|
||||
OR (permission_code = 'merchant:warehouse:delivery:create' AND id <> 5306001)
|
||||
) THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:权限ID或编码冲突';
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
CALL guard_phase5_delivery_permission_ids();
|
||||
DROP PROCEDURE guard_phase5_delivery_permission_ids;
|
||||
|
||||
INSERT INTO iam_permission
|
||||
(id, tenant_id, app_code, permission_type, parent_id, permission_code,
|
||||
permission_name, route_path, http_method, sort_no, status, built_in, deleted)
|
||||
VALUES
|
||||
(5107016,0,'PLATFORM','BUTTON',5107010,'platform:overseas-warehouse:dispatch:edit','编辑海外排车',NULL,'PUT',716,'ACTIVE',1,0),
|
||||
(5107017,0,'PLATFORM','BUTTON',5107010,'platform:overseas-warehouse:dispatch:cancel','取消海外排车',NULL,'POST',717,'ACTIVE',1,0),
|
||||
(5107018,0,'PLATFORM','BUTTON',5107010,'platform:overseas-warehouse:dispatch:transfer-delivery','排车转派送',NULL,'POST',718,'ACTIVE',1,0),
|
||||
(5107090,0,'PLATFORM','MENU',0,'platform:overseas-warehouse:outbound:list','海外出库单','/overseas-warehouse/outbounds','GET',765,'ACTIVE',1,0),
|
||||
(5107091,0,'PLATFORM','BUTTON',5107090,'platform:overseas-warehouse:outbound:create','创建海外出库单',NULL,'POST',766,'ACTIVE',1,0),
|
||||
(5107092,0,'PLATFORM','MENU',0,'platform:overseas-warehouse:delivery:list','海外派送单','/overseas-warehouse/delivery-orders','GET',767,'ACTIVE',1,0),
|
||||
(5107093,0,'PLATFORM','BUTTON',5107090,'platform:overseas-warehouse:outbound:cancel','取消海外出库单',NULL,'POST',768,'ACTIVE',1,0),
|
||||
(5306000,0,'MERCHANT','MENU',0,'merchant:warehouse:delivery:list','海外仓派送单','/overseas-warehouse/delivery-orders','GET',60,'ACTIVE',1,0),
|
||||
(5306001,0,'MERCHANT','BUTTON',5306000,'merchant:warehouse:delivery:create','创建海外仓派送单',NULL,'POST',10,'ACTIVE',1,0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
permission_type=VALUES(permission_type), parent_id=VALUES(parent_id),
|
||||
permission_name=VALUES(permission_name), route_path=VALUES(route_path),
|
||||
http_method=VALUES(http_method), sort_no=VALUES(sort_no), status='ACTIVE',
|
||||
built_in=1, deleted=0;
|
||||
|
||||
-- 平台管理员默认拥有五期全部后台动作;已有的平台自定义管理员保持同等五期操作能力。
|
||||
INSERT IGNORE INTO iam_role_permission (tenant_id, role_id, permission_id, created_at)
|
||||
SELECT 0, role.id, permission.id, CURRENT_TIMESTAMP(3)
|
||||
FROM iam_role role
|
||||
JOIN iam_permission permission ON permission.tenant_id=0 AND permission.app_code='PLATFORM'
|
||||
WHERE role.tenant_id=0 AND role.app_code='PLATFORM'
|
||||
AND UPPER(role.role_code) IN ('PLATFORM_ADMIN','PLATFORM_CUSTOM_ADMIN')
|
||||
AND role.status='ACTIVE' AND role.deleted=0
|
||||
AND permission.permission_code IN (
|
||||
'platform:overseas-warehouse:dispatch:edit',
|
||||
'platform:overseas-warehouse:dispatch:cancel',
|
||||
'platform:overseas-warehouse:dispatch:transfer-delivery',
|
||||
'platform:overseas-warehouse:outbound:list',
|
||||
'platform:overseas-warehouse:outbound:create',
|
||||
'platform:overseas-warehouse:outbound:cancel',
|
||||
'platform:overseas-warehouse:delivery:list')
|
||||
AND permission.status='ACTIVE' AND permission.deleted=0;
|
||||
|
||||
-- 仓库后台岗位按最小职责授权;PDA 岗位不得获得后台排车、出库或派送权限。
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_phase5_delivery_role_permission;
|
||||
CREATE TEMPORARY TABLE tmp_phase5_delivery_role_permission (
|
||||
role_code VARCHAR(64) NOT NULL,
|
||||
permission_code VARCHAR(160) NOT NULL,
|
||||
PRIMARY KEY (role_code, permission_code)
|
||||
) ENGINE=MEMORY;
|
||||
INSERT INTO tmp_phase5_delivery_role_permission (role_code, permission_code) VALUES
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:dispatch:edit'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:dispatch:cancel'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:dispatch:transfer-delivery'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:outbound:list'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:outbound:create'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:outbound:cancel'),
|
||||
('WAREHOUSE_OPERATOR','platform:overseas-warehouse:delivery:list'),
|
||||
('WAREHOUSE_TALLY','platform:overseas-warehouse:outbound:list'),
|
||||
('WAREHOUSE_TALLY','platform:overseas-warehouse:delivery:list');
|
||||
|
||||
DELETE grant_row FROM iam_role_permission grant_row
|
||||
JOIN iam_role role ON role.id=grant_row.role_id AND role.tenant_id=grant_row.tenant_id
|
||||
JOIN iam_permission permission ON permission.id=grant_row.permission_id AND permission.tenant_id=grant_row.tenant_id
|
||||
LEFT JOIN tmp_phase5_delivery_role_permission expected
|
||||
ON expected.role_code=role.role_code AND expected.permission_code=permission.permission_code
|
||||
WHERE role.tenant_id=0 AND role.app_code='PLATFORM'
|
||||
AND role.role_code IN ('WAREHOUSE_OPERATOR','WAREHOUSE_TALLY','OVERSEAS_WAREHOUSE_PDA_OPERATOR','CN_FIRSTLEG_PDA_OPERATOR')
|
||||
AND permission.permission_code IN (
|
||||
'platform:overseas-warehouse:dispatch:edit',
|
||||
'platform:overseas-warehouse:dispatch:cancel',
|
||||
'platform:overseas-warehouse:dispatch:transfer-delivery',
|
||||
'platform:overseas-warehouse:outbound:list',
|
||||
'platform:overseas-warehouse:outbound:create',
|
||||
'platform:overseas-warehouse:outbound:cancel',
|
||||
'platform:overseas-warehouse:delivery:list')
|
||||
AND expected.permission_code IS NULL;
|
||||
|
||||
INSERT IGNORE INTO iam_role_permission (tenant_id, role_id, permission_id, created_at)
|
||||
SELECT 0, role.id, permission.id, CURRENT_TIMESTAMP(3)
|
||||
FROM tmp_phase5_delivery_role_permission expected
|
||||
JOIN iam_role role ON role.tenant_id=0 AND role.app_code='PLATFORM'
|
||||
AND role.role_code=expected.role_code AND role.status='ACTIVE' AND role.deleted=0
|
||||
JOIN iam_permission permission ON permission.tenant_id=0 AND permission.app_code='PLATFORM'
|
||||
AND permission.permission_code=expected.permission_code
|
||||
AND permission.status='ACTIVE' AND permission.deleted=0;
|
||||
|
||||
-- 客户默认管理员获得派送列表/详情只读及独立创建;其他客户角色不自动扩权。
|
||||
INSERT IGNORE INTO iam_role_permission (tenant_id, role_id, permission_id, created_at)
|
||||
SELECT 0, role.id, permission.id, CURRENT_TIMESTAMP(3)
|
||||
FROM iam_role role
|
||||
JOIN iam_permission permission ON permission.tenant_id=0 AND permission.app_code='MERCHANT'
|
||||
WHERE role.tenant_id=0 AND role.app_code='MERCHANT' AND role.role_code='MERCHANT_OWNER'
|
||||
AND role.status='ACTIVE' AND role.deleted=0
|
||||
AND permission.permission_code IN (
|
||||
'merchant:warehouse:delivery:list',
|
||||
'merchant:warehouse:delivery:create')
|
||||
AND permission.status='ACTIVE' AND permission.deleted=0;
|
||||
|
||||
DROP PROCEDURE IF EXISTS assert_phase5_delivery_permissions;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE assert_phase5_delivery_permissions()
|
||||
BEGIN
|
||||
IF (SELECT COUNT(*) FROM iam_permission
|
||||
WHERE tenant_id=0 AND status='ACTIVE' AND deleted=0
|
||||
AND permission_code IN (
|
||||
'platform:overseas-warehouse:dispatch:edit',
|
||||
'platform:overseas-warehouse:dispatch:cancel',
|
||||
'platform:overseas-warehouse:dispatch:transfer-delivery',
|
||||
'platform:overseas-warehouse:outbound:list',
|
||||
'platform:overseas-warehouse:outbound:create',
|
||||
'platform:overseas-warehouse:outbound:cancel',
|
||||
'platform:overseas-warehouse:delivery:list',
|
||||
'merchant:warehouse:delivery:list',
|
||||
'merchant:warehouse:delivery:create')) <> 9 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:权限目录不完整';
|
||||
END IF;
|
||||
IF (SELECT COUNT(*) FROM iam_role_permission grant_row
|
||||
JOIN iam_role role ON role.id=grant_row.role_id AND role.tenant_id=grant_row.tenant_id
|
||||
JOIN iam_permission permission ON permission.id=grant_row.permission_id
|
||||
WHERE role.role_code='PLATFORM_ADMIN'
|
||||
AND permission.permission_code IN (
|
||||
'platform:overseas-warehouse:dispatch:edit',
|
||||
'platform:overseas-warehouse:dispatch:cancel',
|
||||
'platform:overseas-warehouse:dispatch:transfer-delivery',
|
||||
'platform:overseas-warehouse:outbound:list',
|
||||
'platform:overseas-warehouse:outbound:create',
|
||||
'platform:overseas-warehouse:outbound:cancel',
|
||||
'platform:overseas-warehouse:delivery:list')) <> 7 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:平台管理员授权不完整';
|
||||
END IF;
|
||||
IF (SELECT COUNT(*) FROM tmp_phase5_delivery_role_permission WHERE role_code='WAREHOUSE_OPERATOR') <> 7
|
||||
OR (SELECT COUNT(*) FROM tmp_phase5_delivery_role_permission WHERE role_code='WAREHOUSE_TALLY') <> 2 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:仓库岗位最小权限矩阵异常';
|
||||
END IF;
|
||||
IF EXISTS (SELECT 1 FROM iam_role_permission grant_row
|
||||
JOIN iam_role role ON role.id=grant_row.role_id AND role.tenant_id=grant_row.tenant_id
|
||||
JOIN iam_permission permission ON permission.id=grant_row.permission_id
|
||||
WHERE role.role_code IN ('OVERSEAS_WAREHOUSE_PDA_OPERATOR','CN_FIRSTLEG_PDA_OPERATOR')
|
||||
AND permission.permission_code IN (
|
||||
'platform:overseas-warehouse:dispatch:edit',
|
||||
'platform:overseas-warehouse:dispatch:cancel',
|
||||
'platform:overseas-warehouse:dispatch:transfer-delivery',
|
||||
'platform:overseas-warehouse:outbound:list',
|
||||
'platform:overseas-warehouse:outbound:create',
|
||||
'platform:overseas-warehouse:outbound:cancel',
|
||||
'platform:overseas-warehouse:delivery:list')) THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:PDA岗位错误获得后台权限';
|
||||
END IF;
|
||||
IF (SELECT COUNT(*) FROM iam_role_permission grant_row
|
||||
JOIN iam_role role ON role.id=grant_row.role_id AND role.tenant_id=grant_row.tenant_id
|
||||
JOIN iam_permission permission ON permission.id=grant_row.permission_id
|
||||
WHERE role.role_code='MERCHANT_OWNER' AND role.app_code='MERCHANT'
|
||||
AND permission.permission_code IN (
|
||||
'merchant:warehouse:delivery:list',
|
||||
'merchant:warehouse:delivery:create')) <> 2 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='五期海外派送权限初始化失败:客户默认管理员授权不完整';
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
CALL assert_phase5_delivery_permissions();
|
||||
DROP PROCEDURE assert_phase5_delivery_permissions;
|
||||
DROP TEMPORARY TABLE tmp_phase5_delivery_role_permission;
|
||||
@@ -74,7 +74,7 @@ paths:
|
||||
get:
|
||||
tags: [IAM Resources / IAM 资源]
|
||||
summary: 查询当前用户有效权限
|
||||
description: 返回当前有效平台成员权限编码;只要求有效 PLATFORM JWT,不依赖 `platform:role:list`。
|
||||
description: 返回当前有效平台成员权限编码;只要求有效 PLATFORM JWT,不依赖 `platform:role:list`。五期海外排车、出库与派送分别返回 `platform:overseas-warehouse:dispatch:edit`、`platform:overseas-warehouse:dispatch:cancel`、`platform:overseas-warehouse:dispatch:transfer-delivery`、`platform:overseas-warehouse:outbound:list`、`platform:overseas-warehouse:outbound:create`、`platform:overseas-warehouse:outbound:cancel`、`platform:overseas-warehouse:delivery:list`;列表权限包含详情只读,写操作独立授权。
|
||||
responses:
|
||||
'200':
|
||||
description: 当前平台成员权限查询成功
|
||||
@@ -276,7 +276,7 @@ paths:
|
||||
get:
|
||||
tags: [IAM Resources / IAM 资源]
|
||||
summary: 查询当前用户有效权限
|
||||
description: 返回当前有效商户成员权限编码。
|
||||
description: 返回当前有效客户成员权限编码。五期客户派送返回 `merchant:warehouse:delivery:list` 和 `merchant:warehouse:delivery:create`;列表权限包含详情只读,创建权限独立授权。
|
||||
responses:
|
||||
'200':
|
||||
description: 当前商户成员权限查询成功
|
||||
|
||||
@@ -20,6 +20,11 @@ class IamOpenApiContractTest {
|
||||
|
||||
assertThat(document).contains("/api/platform/v1/iam/authorization/permissions:")
|
||||
.contains("/api/merchant/v1/iam/authorization/permissions:")
|
||||
.contains("platform:overseas-warehouse:dispatch:transfer-delivery")
|
||||
.contains("platform:overseas-warehouse:outbound:cancel")
|
||||
.contains("merchant:warehouse:delivery:list")
|
||||
.contains("merchant:warehouse:delivery:create")
|
||||
.contains("列表权限包含详情只读")
|
||||
.contains("PermissionCodesApiResponse:")
|
||||
.contains("TenantPageApiResponse:")
|
||||
.contains("TenantApiResponse:")
|
||||
|
||||
+4
@@ -96,6 +96,10 @@ class OverseasPhase4PermissionSqlContractTest {
|
||||
void servicePermissionConstantsExactlyMatchTheIamCatalog() throws Exception {
|
||||
Set<String> moduleCatalog = codes(new ClassPathResource("db/lastleg-permissions.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8));
|
||||
codes(new ClassPathResource("db/phase5-delivery-permissions.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8)).stream()
|
||||
.filter(code -> code.startsWith("platform:"))
|
||||
.forEach(moduleCatalog::add);
|
||||
Set<String> serviceCatalog = new LinkedHashSet<>();
|
||||
serviceCatalog.addAll(codes(repositoryFile(
|
||||
"lastleg-service/src/main/java/com/baiyue/lastleg/security/OverseasPermissions.java")));
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package com.baiyue.iam.repository;
|
||||
|
||||
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 java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class Phase5DeliveryPermissionSqlContractTest {
|
||||
private static final Pattern CODE = Pattern.compile("(?:platform:overseas-warehouse|merchant:warehouse):[a-z0-9:-]+");
|
||||
private static final Set<String> REQUIRED = Set.of(
|
||||
"platform:overseas-warehouse:dispatch:edit",
|
||||
"platform:overseas-warehouse:dispatch:cancel",
|
||||
"platform:overseas-warehouse:dispatch:transfer-delivery",
|
||||
"platform:overseas-warehouse:outbound:list",
|
||||
"platform:overseas-warehouse:outbound:create",
|
||||
"platform:overseas-warehouse:outbound:cancel",
|
||||
"platform:overseas-warehouse:delivery:list",
|
||||
"merchant:warehouse:delivery:list",
|
||||
"merchant:warehouse:delivery:create");
|
||||
|
||||
@Test
|
||||
void definesOnlyTheFrozenPhase5DeliveryCatalogWithoutAliases() throws Exception {
|
||||
String sql = sql();
|
||||
|
||||
assertThat(codes(sql)).containsExactlyInAnyOrderElementsOf(REQUIRED);
|
||||
assertThat(codes(sql)).noneMatch(code -> code.endsWith(":view"));
|
||||
assertThat(sql).contains(
|
||||
"guard_phase5_delivery_permission_ids",
|
||||
"权限ID或编码冲突",
|
||||
"permission_type=VALUES(permission_type)",
|
||||
"列表权限同时覆盖列表和详情只读");
|
||||
}
|
||||
|
||||
@Test
|
||||
void grantsAdministratorsAndWarehouseRolesByTheFrozenMinimumMatrix() throws Exception {
|
||||
String sql = sql();
|
||||
|
||||
assertThat(sql).contains(
|
||||
"UPPER(role.role_code) IN ('PLATFORM_ADMIN','PLATFORM_CUSTOM_ADMIN')",
|
||||
"tmp_phase5_delivery_role_permission",
|
||||
"('WAREHOUSE_OPERATOR','platform:overseas-warehouse:dispatch:edit')",
|
||||
"('WAREHOUSE_OPERATOR','platform:overseas-warehouse:outbound:create')",
|
||||
"('WAREHOUSE_TALLY','platform:overseas-warehouse:outbound:list')",
|
||||
"('WAREHOUSE_TALLY','platform:overseas-warehouse:delivery:list')",
|
||||
"role.role_code IN ('OVERSEAS_WAREHOUSE_PDA_OPERATOR','CN_FIRSTLEG_PDA_OPERATOR')",
|
||||
"PDA岗位错误获得后台权限");
|
||||
assertThat(sql).doesNotContain(
|
||||
"('WAREHOUSE_TALLY','platform:overseas-warehouse:dispatch:edit')",
|
||||
"('WAREHOUSE_TALLY','platform:overseas-warehouse:outbound:create')",
|
||||
"('OVERSEAS_WAREHOUSE_PDA_OPERATOR','platform:overseas-warehouse:",
|
||||
"('CN_FIRSTLEG_PDA_OPERATOR','platform:overseas-warehouse:");
|
||||
}
|
||||
|
||||
@Test
|
||||
void grantsOnlyTheDefaultCustomerAdministratorAutomatically() throws Exception {
|
||||
String sql = sql();
|
||||
int marker = sql.indexOf("-- 客户默认管理员获得派送列表/详情只读及独立创建");
|
||||
int assertion = sql.indexOf("DROP PROCEDURE IF EXISTS assert_phase5_delivery_permissions", marker);
|
||||
assertThat(marker).isGreaterThanOrEqualTo(0);
|
||||
assertThat(assertion).isGreaterThan(marker);
|
||||
|
||||
String grant = sql.substring(marker, assertion);
|
||||
assertThat(grant).contains(
|
||||
"role.role_code='MERCHANT_OWNER'",
|
||||
"merchant:warehouse:delivery:list",
|
||||
"merchant:warehouse:delivery:create");
|
||||
assertThat(grant).doesNotContain("MERCHANT_OPERATOR", "ORDER_VIEWER", "role.role_code IN");
|
||||
}
|
||||
|
||||
@Test
|
||||
void domesticUnifiedEntryInlinesTheCompleteModuleSqlAfterPhase4Permissions() throws Exception {
|
||||
String moduleSql = sql().trim();
|
||||
String unifiedSql = repositoryFile("deploy/sql/头程数据库统一增量-MySQL8.sql");
|
||||
int phase4 = unifiedSql.indexOf("-- 四期海外权限统一目录");
|
||||
int phase5 = unifiedSql.indexOf("-- 五期海外排车、出库与派送权限(来源:iam/db/phase5-delivery-permissions.sql)");
|
||||
int bodyStart = unifiedSql.indexOf("USE baiyue_iam;", phase5);
|
||||
int nextSection = unifiedSql.indexOf("-- 海外智能排车草稿锁", bodyStart);
|
||||
|
||||
assertThat(phase4).isGreaterThanOrEqualTo(0);
|
||||
assertThat(phase5).isGreaterThan(phase4);
|
||||
assertThat(bodyStart).isGreaterThan(phase5);
|
||||
assertThat(nextSection).isGreaterThan(bodyStart);
|
||||
assertThat(unifiedSql.substring(bodyStart, nextSection).trim()).isEqualTo(moduleSql);
|
||||
assertThat(codes(unifiedSql.substring(phase5, nextSection)))
|
||||
.containsExactlyInAnyOrderElementsOf(REQUIRED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deploymentGuideUsesOnlyTheDomesticUnifiedEntry() throws Exception {
|
||||
String readme = repositoryFile("deploy/sql/README.md");
|
||||
|
||||
assertThat(readme).contains(
|
||||
"五期海外排车、出库与派送权限",
|
||||
"测试和部署只执行固定入口,不再单独执行模块脚本",
|
||||
"merchant:warehouse:delivery:list",
|
||||
"merchant:warehouse:delivery:create",
|
||||
"PDA 岗位不得获得上述后台权限");
|
||||
}
|
||||
|
||||
private static String sql() throws Exception {
|
||||
return new ClassPathResource("db/phase5-delivery-permissions.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static Set<String> codes(String source) {
|
||||
Set<String> values = new LinkedHashSet<>();
|
||||
CODE.matcher(source).results().map(result -> result.group()).forEach(values::add);
|
||||
return values;
|
||||
}
|
||||
|
||||
private static String repositoryFile(String relativePath) throws Exception {
|
||||
Path path = Path.of(relativePath);
|
||||
if (!Files.exists(path)) path = Path.of("..").resolve(relativePath);
|
||||
return Files.readString(path, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,22 @@ class AuthorizationSnapshotServiceTest {
|
||||
verify(mapper).findPermissions(42L, 0L, 9L, "PLATFORM");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposesPhase5DeliveryPermissionsFromCurrentRoleAssignments() {
|
||||
when(mapper.countActiveIdentity(42L, 7L, 9L)).thenReturn(1);
|
||||
when(mapper.findRoles(42L, 7L, 9L, "MERCHANT")).thenReturn(List.of("MERCHANT_OWNER"));
|
||||
when(mapper.findPermissions(42L, 7L, 9L, "MERCHANT")).thenReturn(List.of(
|
||||
"merchant:warehouse:delivery:list",
|
||||
"merchant:warehouse:delivery:create"));
|
||||
|
||||
var result = service.currentPermissions(new AuthenticatedUser(42L, 7L, 7L, 9L,
|
||||
"owner", "MERCHANT", "MERCHANT", java.util.Set.of()), "MERCHANT");
|
||||
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"merchant:warehouse:delivery:create",
|
||||
"merchant:warehouse:delivery:list");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsIncompleteCurrentIdentityAsBusinessError() {
|
||||
assertThatThrownBy(() -> service
|
||||
|
||||
Reference in New Issue
Block a user