fix(jd): 分类可见沿管理链上溯,修普通管理员看不到同组分类
线上账号链:阿华112336(normal,1366) → 阿华226655(admin,1365) → 阿华66 (company_super_admin,1353)。旧实现只沿 created_by_id 走一跳,中间 1365 不带组 时可见集为空,分类页报「本组暂无分类」——实际 5 个分类都挂在 1353 建的组 49 下。 - JdCategoryScopeService 新增 collectAncestorGroups:沿 created_by_id 递归上溯, 带已访问集合防成环、深度上限 10、链断即停; - 只继承同公司的组(company_id 相等):平台超管是整片下游的根,不加这道闸会把 别家公司建的组顺链漏进来;HEAD 原有「一跳上级」路径补同一道过滤; - 继承放在可写集计算之后,只影响可见(只读),writable 不因上溯放宽; - 判据 +4:两跳链、继承只读+同级隔离、成环不死循环、跨公司不继承。 反向验证:去掉同公司过滤→跨公司用例红;链收成一跳→两跳用例红。 验证:本提交内容(HEAD+本改动)在干净树 JdCategoryScopeServiceTest 23/23 绿。
This commit is contained in:
+96
@@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -236,6 +237,101 @@ class JdCategoryScopeServiceTest {
|
||||
assertThat(scope.groups()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026-11-24 客户口径「普通管理员看不到同组管理员的分类」(线上账号 阿华112336 的形状:
|
||||
* 员工 1366 → 管理员 1365(不带组)→ 公司超管 1353(带组 49)):可见组沿 created_by_id
|
||||
* <b>两跳</b>上溯补齐,员工只读。
|
||||
*/
|
||||
@Test
|
||||
void 普通号_沿管理链两跳看到超管建的组_只读() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
operator.setCreatedById(5L);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
AdminUserEntity admin = user(5L, COMPANY_ID);
|
||||
admin.setCreatedById(7L);
|
||||
when(adminUserMapper.selectById(5L)).thenReturn(admin);
|
||||
when(adminUserMapper.selectById(7L)).thenReturn(user(7L, COMPANY_ID));
|
||||
when(shopManageGroupMapper.selectLedGroups(5L)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLedGroups(7L)).thenReturn(List.of(group(49L, COMPANY_ID, "测试1111")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(49L);
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
assertThat(scope.defaultGroupId()).isEqualTo(49L);
|
||||
assertThat(scope.groups()).singleElement()
|
||||
.satisfies(option -> assertThat(option.isEditable()).isFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* 「不同组不能看」仍成立:继承只沿自己的上级链。与上级共用同一上游的同级账号(另一条链)
|
||||
* 自己建的组不进可见集;继承来的组也不因它变得可写。
|
||||
*/
|
||||
@Test
|
||||
void 沿管理链继承上级组_同级账号自己建的组仍不可见() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
operator.setCreatedById(3L);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of(group(10L, COMPANY_ID, "自己的组")));
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
when(adminUserMapper.selectById(3L)).thenReturn(user(3L, COMPANY_ID));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(20L, COMPANY_ID, "上级的组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L, 20L);
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
assertThat(scope.canRead(20L)).isTrue();
|
||||
assertThat(scope.canWrite(20L)).isFalse();
|
||||
// 同级账号(另一条 created_by_id 链)自己建的组 30 不在本账号的链上 ⇒ 不可见。
|
||||
assertThat(scope.canRead(30L)).isFalse();
|
||||
assertThat(scope.canWrite(30L)).isFalse();
|
||||
}
|
||||
|
||||
/** 管理链成环(脏数据自指/互指)必须停下,不得死循环。 */
|
||||
@Test
|
||||
void 管理链成环不死循环() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
operator.setCreatedById(4L);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
AdminUserEntity parent = user(4L, COMPANY_ID);
|
||||
parent.setCreatedById(USER_ID);
|
||||
when(adminUserMapper.selectById(4L)).thenReturn(parent);
|
||||
when(shopManageGroupMapper.selectLedGroups(4L)).thenReturn(List.of(group(11L, COMPANY_ID, "A组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(11L);
|
||||
verify(shopManageGroupMapper, atLeastOnce()).selectLedGroups(4L);
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
}
|
||||
|
||||
/** 管理链上溯只继承<b>同公司</b>的组:平台超管根下别家公司建的组不得顺链漏进来。 */
|
||||
@Test
|
||||
void 管理链上溯_别家公司的组不继承() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
operator.setCreatedById(3L);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
when(adminUserMapper.selectById(3L)).thenReturn(user(3L, COMPANY_ID));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(
|
||||
group(21L, COMPANY_ID, "同公司组"), group(22L, 99L, "别家公司组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(21L);
|
||||
assertThat(scope.canRead(22L)).isFalse();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 入参收敛
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user