收口(去重库读侧): 按行 company_id 认公司——代导入/上传者已删两族归位
控制方 2026-10-09 截图:admin 在「先锋」tab 代导入的行(company_id=3、 uploader=admin 属公司 1)在先锋 tab 看不见、反而出现在米椿花 tab。读侧 (列表/导出/公司超管)自 V145 起一直按"上传账号"认公司,与写侧(5ccf3c89 起一律显式落 company_id、V154 已摘 DEFAULT)两套口径打架;切换前先把存量 兜底行修对:V156 把组 33/uid=1188(「先锋」,账号已硬删)的 1452 行 company_id 1→3——否则切完它们整批冒给米椿花,且当前正参与米椿花的去重 比对(5ccf3c89 已按 company_id 收窄),先锋自己反而拿不到这批值。 - DataReadScope 新增第五道正门 superAdminScopedCompanyId:与 superAdminScopedUserIds 同形"只对站点超管收窄",维度从上传账号集换成 行 company_id;非超管恒 null(不叠那一刀,可见集仍锁在账号/分组上) - Service applyCompanyScope 由 uploader_user_id IN (成员) 改 eq(company_id); company_super_admin 的 wholeCompany 分支同批切换(1206 从此看得到代导入 行与上传者已删行,例:admin 代导入 14 行 + 组 33 历史 1452 行) - G2 护栏加第五道门 + 正/负三枚探针;单测新增四条(超管切公司、公司超管 全公司、门非超管恒 null、service 层 wrapper 两面) DedupeTotalDataController 的换门接线已随 2a4d15b8(文案批)入库。 影响面(生产只读实查):切后米椿花 tab −14 行、先锋 tab +14+1452 行; 公司超管仅 1206 一个账号。全量 4209 测绿。
This commit is contained in:
+79
-8
@@ -113,20 +113,22 @@ import org.junit.jupiter.api.Test;
|
||||
* D 的代价与射程一并交代:非 {@code Long} 型公司参数取不到绑定名,判红并报形状;而"handler 之外的私有
|
||||
* 收口方法里把公司参数硬写成 {@code null}"这一族 D 看不见——块边界止于该 handler 自己的闭括号
|
||||
* (第 7 条),{@code AdminImageVideoTaskController.scopeOf} 正是它,那一处是<b>故意</b>传 null 的。</li>
|
||||
* <li><b>几条正门,一套判据</b>(批次 2/3 新增;10-06 复验后加第二道,批次 6 加第三道,10-07 三期加第四道)。
|
||||
* 出口现在有四个:
|
||||
* {@code readScope(} 按账号集合给范围(去重库、查询 ASIN、最低价 ASIN、历史、视频),
|
||||
* <li><b>几条正门,一套判据</b>(批次 2/3 新增;10-06 复验后加第二道,批次 6 加第三道,10-07 三期加第四道,
|
||||
* 10-09 去重库口径切换加第五道)。出口现在有五个:
|
||||
* {@code readScope(} 按账号集合给范围(查询 ASIN、最低价 ASIN、历史、视频、店铺管理、设备日志等),
|
||||
* {@code readCompanyIdOrOwn(} 给"归属物化成 {@code company_id} 列、可见集又不靠账号/分组"的表
|
||||
* (今天只有店铺密钥,V150 起每公司一套),{@code resolveScopeCompanyId(} 给菜单字典那一棵树一套
|
||||
* (V149 起,读写共用同一判据,见 {@link #RESOLVE_MENU_SCOPE_CALL} 的理由),
|
||||
* {@code superAdminScopedUserIds(} 给看板那一族"只在站点超管身上收窄"的形状
|
||||
* (见 {@link #SUPER_SCOPED_USER_IDS_CALL} 的理由)。
|
||||
* 四道门共用 A/B/C/D 四条判据:
|
||||
* (见 {@link #SUPER_SCOPED_USER_IDS_CALL} 的理由),
|
||||
* {@code superAdminScopedCompanyId(} 给去重库"同样只对超管收窄、但维度是行 company_id"的形状
|
||||
* (见 {@link #SUPER_SCOPED_COMPANY_ID_CALL} 的理由)。
|
||||
* 五道门共用 A/B/C/D 四条判据:
|
||||
* {@link #SCOPE_DOORS} 供 A 与 C 逐条跑,{@link #SCOPE_CALLEE_NAMES} 供 D 认被调名,
|
||||
* <b>名单只写一次</b>(红因消息与自检断言咬的是拼出来的同一个标签,两处各写一遍会随哈希顺序漂红)。
|
||||
* 每条门各自带能红/能绿两向探针(全局约束 15 那把尺子):只在 {@code readScope} 上验过,
|
||||
* 等于第二道门上的返回值与入参没人看守;第三道门(菜单字典)的三枚 {@code MENU_SCOPE_*} 探针同理,
|
||||
* 第四道门的三枚 {@code SUPER_SCOPED_*} 也是照这一条补的。
|
||||
* 第四、五道门的三枚 {@code SUPER_SCOPED_*} 也是照这一条补的。</li>
|
||||
* <p>批次 2 时这里还有<b>中间</b>那道 {@code readCompanyId(},服务品牌库 {@code biz_invalid_asin_data}
|
||||
* 与商品类目 {@code biz_product_category} 两张物化列表。10-06 控制方把这两页定成全平台共享,
|
||||
* 方法随之删除 ⇒ 门也从名单一起摘掉:名单里留一门没有实现者的门,等于给"把公司开关再接回那两张表"
|
||||
@@ -257,8 +259,20 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
* (全局约束 15),所以正/负两向证据在下面各给一遍。</p>
|
||||
*/
|
||||
private static final String SUPER_SCOPED_USER_IDS_CALL = "superAdminScopedUserIds(";
|
||||
/**
|
||||
* 第五道正门(2026-10-09 去重库读侧口径切换):{@code superAdminScopedCompanyId}。与第四道门同形,
|
||||
* 收窄维度从"上传账号集合"换成"行归属的公司 id"——去重库的归属自 V145 起物化在
|
||||
* {@code company_id} 列上(写侧 39de5035 起一律显式落值、V154 摘 DEFAULT),继续按上传账号推导时
|
||||
* 超管代导入的行会整体归错家(控制方截图:admin 在「先锋」tab 导入的行在先锋 tab 看不见)。
|
||||
*
|
||||
* <p>入名单的前提与第二、三、四道门同一条:它只是 {@code DataReadScope} 上的一个方法,
|
||||
* 不是页里自己写的 if。不加它的话 A 会把去重库那两支合规 handler 判红;只加名字不配探针的话,
|
||||
* 这道门上的返回值与入参没人看守(全局约束 15),所以正/负两向证据在下面各给一遍。</p>
|
||||
*/
|
||||
private static final String SUPER_SCOPED_COMPANY_ID_CALL = "superAdminScopedCompanyId(";
|
||||
private static final List<String> SCOPE_DOORS =
|
||||
List.of(READ_SCOPE_CALL, READ_OWN_COMPANY_ID_CALL, RESOLVE_MENU_SCOPE_CALL, SUPER_SCOPED_USER_IDS_CALL);
|
||||
List.of(READ_SCOPE_CALL, READ_OWN_COMPANY_ID_CALL, RESOLVE_MENU_SCOPE_CALL, SUPER_SCOPED_USER_IDS_CALL,
|
||||
SUPER_SCOPED_COMPANY_ID_CALL);
|
||||
private static final String EXPLICIT_PARAM_NAME = "name = \"company_id\"";
|
||||
private static final String SNAKE_PARAM = "company_id";
|
||||
private static final String CAMEL_PARAM = "companyId";
|
||||
@@ -318,7 +332,7 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
*/
|
||||
private static final List<String> SCOPE_CALLEE_NAMES =
|
||||
List.of("readScope", "resolveScope", "readCompanyIdOrOwn", "resolveScopeCompanyId",
|
||||
"superAdminScopedUserIds");
|
||||
"superAdminScopedUserIds", "superAdminScopedCompanyId");
|
||||
private static final Set<String> SCOPE_CALLEES = Set.copyOf(SCOPE_CALLEE_NAMES);
|
||||
private static final String SCOPE_CALLEE_LABEL = String.join("/", SCOPE_CALLEE_NAMES);
|
||||
|
||||
@@ -575,6 +589,38 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
}
|
||||
""";
|
||||
|
||||
/**
|
||||
* 第五道正门的<b>正探针</b>(形状逐字抄现网 {@code DedupeTotalDataController.page}):
|
||||
* 结果接进变量、又作为实参交给 {@code page(…)},公司参数本身进了门 ⇒ C 与 D 都必须判绿。
|
||||
*/
|
||||
private static final String SUPER_SCOPED_COMPANY_CAUGHT_PROBE = """
|
||||
@GetMapping("/probe")
|
||||
public String superScopedCompanyDoor(@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = session.operator();
|
||||
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(operator, companyId);
|
||||
return String.valueOf(dedupeTotalDataService.page(1L, 15L, null, null, null, null, null, null, null, operatorId, scopedCompanyId));
|
||||
}
|
||||
""";
|
||||
|
||||
/** 第五道正门的<b>裸语句探针</b>(C 在该门上的"能红"证据):门调了,公司 id 当场丢掉。 */
|
||||
private static final String SUPER_SCOPED_COMPANY_DISCARD_PROBE = """
|
||||
@GetMapping("/probe")
|
||||
public String superScopedCompanyDoorDiscard(@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
dataReadScope.superAdminScopedCompanyId(operator, companyId);
|
||||
return "ok";
|
||||
}
|
||||
""";
|
||||
|
||||
/** 第五道正门的<b>负探针</b>(D 在该门上的存在理由):切了 tab,传进门里的还是 {@code null}。 */
|
||||
private static final String SUPER_SCOPED_COMPANY_PASSED_NULL_PROBE = """
|
||||
@GetMapping("/probe")
|
||||
public String superScopedCompanyDoorNull(@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = session.operator();
|
||||
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(operator, null);
|
||||
return String.valueOf(dedupeTotalDataService.page(1L, 15L, null, null, null, null, null, null, null, operatorId, scopedCompanyId));
|
||||
}
|
||||
""";
|
||||
|
||||
/**
|
||||
* 已摘掉那道门的<b>正样本探针</b>(形状抄退回前的 {@code InvalidAsinDataController.page}:
|
||||
* 收 {@code company_id} 参数、体内调 {@code readCompanyId})。它现在应当被 A/C/D 三条同时判红——
|
||||
@@ -787,6 +833,31 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
.isNotNull()
|
||||
.contains("没进任何 " + SCOPE_CALLEE_LABEL + " 的实参列表");
|
||||
|
||||
// 第五道门(去重库按行 company_id 收窄)同样两向取证:它今天有两个真实消费者
|
||||
// (DedupeTotalDataController 的 page 与 export)。只把名字加进 SCOPE_DOORS 而不验
|
||||
// 返回值与入参,这道门就是"名单里有、没人守"——scopedCompanyId 哪天被丢掉或传成 null,
|
||||
// C 与 D 都不求值,切 tab 又变装饰品。
|
||||
assertThat(scopeProbeReason(SUPER_SCOPED_COMPANY_CAUGHT_PROBE, "SUPER_SCOPED_COMPANY_CAUGHT_PROBE"))
|
||||
.as("断言 C 自检(第五道门·正样本):Long scopedCompanyId = superAdminScopedCompanyId(operator, companyId) "
|
||||
+ "且它进了 page(…) 的实参 ⇒ 判红就是护栏假红")
|
||||
.isNull();
|
||||
assertThat(companyIdArgProbeReason(
|
||||
SUPER_SCOPED_COMPANY_CAUGHT_PROBE, "SUPER_SCOPED_COMPANY_CAUGHT_PROBE", CAMEL_PARAM))
|
||||
.as("断言 D 自检(第五道门·正样本):companyId 真进了 superAdminScopedCompanyId 的实参表 ⇒ 不许红")
|
||||
.isNull();
|
||||
assertThat(scopeProbeReason(SUPER_SCOPED_COMPANY_DISCARD_PROBE, "SUPER_SCOPED_COMPANY_DISCARD_PROBE"))
|
||||
.as("断言 C 自检(第五道门·负样本):superAdminScopedCompanyId( 写成裸语句、公司 id 当场丢掉 ⇒ 必须判红")
|
||||
.isNotNull()
|
||||
.contains("范围算了但没接住");
|
||||
assertThat(scopeProbeReason(SUPER_SCOPED_COMPANY_PASSED_NULL_PROBE, "SUPER_SCOPED_COMPANY_PASSED_NULL_PROBE"))
|
||||
.as("断言 D(第五道门)负样本的前提(断言 C):结果接进 scopedCompanyId 又喂给了 page ⇒ C 判它绿")
|
||||
.isNull();
|
||||
assertThat(companyIdArgProbeReason(
|
||||
SUPER_SCOPED_COMPANY_PASSED_NULL_PROBE, "SUPER_SCOPED_COMPANY_PASSED_NULL_PROBE", CAMEL_PARAM))
|
||||
.as("断言 D 自检(第五道门·负样本):superAdminScopedCompanyId(operator, null) ⇒ 必须判红")
|
||||
.isNotNull()
|
||||
.contains("没进任何 " + SCOPE_CALLEE_LABEL + " 的实参列表");
|
||||
|
||||
// 已摘掉的那道门不许再接回(全局约束 15 的"能红"方向)。这一族 handler(品牌库、商品类目)现在定案
|
||||
// 全平台共享、不再收公司参数 ⇒ 它们已不进 A/C/D 的样本,"哪天有人把 ?company_id= 接回这两张表"
|
||||
// 只剩这条探针还在求值,而今天真正拦它的是断言 A:C 与 D 在主循环里都以"体内有正门调用"为前提
|
||||
|
||||
@@ -161,6 +161,34 @@ class DataReadScopeTest {
|
||||
assertThat(dataReadScope.readCompanyIdOrOwn(user(9L, "company_super_admin", 2L), 7L)).isEqualTo(2L);
|
||||
}
|
||||
|
||||
// ---- 第五道正门 superAdminScopedCompanyId(2026-10-09 去重库读侧口径切换)----
|
||||
// 与第四道门 superAdminScopedUserIds 同形"只在站点超管身上收窄",区别是收窄维度:
|
||||
// 那个给"上传账号集合",这个给"行归属的公司 id"(行把归属物化在 company_id 列上的表用)。
|
||||
// 与非超管相关的关键差异(对照第二道门 readCompanyIdOrOwn):非超管<b>返回 null</b>(不叠),
|
||||
// 绝不 pin own——去重库非超管的可见集锁在账号/分组上,叠一刀公司会把"靠分组可见"的行静默删掉。
|
||||
|
||||
@Test
|
||||
@DisplayName("第五道门:超管按 tab 走,0/负数与非空归一化成「没选公司」")
|
||||
void superScopedCompanyIdFollowsTheTabForSuperAdmin() {
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(1L, "super_admin", 1L), 2L)).isEqualTo(2L);
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(1L, "super_admin", 1L), null)).isNull();
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(1L, "super_admin", 1L), 0L)).isNull();
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(1L, "super_admin", 1L), -3L)).isNull();
|
||||
verifyNoInteractions(companyScope);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("第五道门:非超管一律 null(不叠公司谓词),与第二道门 pin 本公司是两回事")
|
||||
void superScopedCompanyIdLeavesNonSuperAdminUnscoped() {
|
||||
// 传 2(本公司)/ 7(别家)/ null 都必须 null,且不许去查公司归属
|
||||
// (readCompanyIdOrOwn 在老位置会返回 own——那一道门管的是"可见集不靠账号/分组"的表,别抄错门)。
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(5L, "admin", 2L), 2L)).isNull();
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(5L, "admin", 2L), 7L)).isNull();
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(5L, "admin", 2L), null)).isNull();
|
||||
assertThat(dataReadScope.superAdminScopedCompanyId(user(9L, "company_super_admin", 2L), 2L)).isNull();
|
||||
verifyNoInteractions(companyScope);
|
||||
}
|
||||
|
||||
// ---- 写侧闸门 writeCompanyId:读收窄而写不收窄="藏起来的行照样能删" ----
|
||||
|
||||
@Test
|
||||
|
||||
+19
-14
@@ -3,7 +3,6 @@ package com.nanri.aiimage.modules.dedupe.controller;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.common.service.ReadScope;
|
||||
import com.nanri.aiimage.modules.dedupe.service.DedupeTotalDataService;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
@@ -46,12 +45,13 @@ class DedupeTotalDataControllerTest {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
DedupeTotalDataController controller = new DedupeTotalDataController(
|
||||
service, authSupport, permissionMenuService, dataReadScope);
|
||||
when(dataReadScope.readScope(any(), any())).thenReturn(ReadScope.unfiltered());
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(8L);
|
||||
operator.setRole("super_admin");
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
// 未选公司 ⇒ 门给 null(Mockito 对包装 Long 的默认返回值是 0L,必须显式桩)
|
||||
when(dataReadScope.superAdminScopedCompanyId(any(), any())).thenReturn(null);
|
||||
doAnswer(invocation -> {
|
||||
OutputStream outputStream = invocation.getArgument(0);
|
||||
outputStream.write(new byte[]{1, 2, 3});
|
||||
@@ -111,12 +111,13 @@ class DedupeTotalDataControllerTest {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
DedupeTotalDataController controller = new DedupeTotalDataController(
|
||||
service, authSupport, permissionMenuService, dataReadScope);
|
||||
when(dataReadScope.readScope(any(), any())).thenReturn(ReadScope.unfiltered());
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(8L);
|
||||
operator.setRole("super_admin");
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
// 未选公司 ⇒ 门给 null(Mockito 对包装 Long 的默认返回值是 0L,必须显式桩)
|
||||
when(dataReadScope.superAdminScopedCompanyId(any(), any())).thenReturn(null);
|
||||
|
||||
ResponseEntity<StreamingResponseBody> response = controller.export(
|
||||
"member",
|
||||
@@ -157,12 +158,13 @@ class DedupeTotalDataControllerTest {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
DedupeTotalDataController controller = new DedupeTotalDataController(
|
||||
service, authSupport, permissionMenuService, dataReadScope);
|
||||
when(dataReadScope.readScope(any(), any())).thenReturn(ReadScope.unfiltered());
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(8L);
|
||||
operator.setRole("super_admin");
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
// 未选公司 ⇒ 门给 null(Mockito 对包装 Long 的默认返回值是 0L,必须显式桩)
|
||||
when(dataReadScope.superAdminScopedCompanyId(any(), any())).thenReturn(null);
|
||||
doAnswer(invocation -> {
|
||||
OutputStream outputStream = invocation.getArgument(0);
|
||||
outputStream.write(new byte[]{4, 5});
|
||||
@@ -215,7 +217,6 @@ class DedupeTotalDataControllerTest {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
DedupeTotalDataController controller = new DedupeTotalDataController(
|
||||
service, authSupport, permissionMenuService, dataReadScope);
|
||||
when(dataReadScope.readScope(any(), any())).thenReturn(ReadScope.unfiltered());
|
||||
|
||||
BusinessException exception = assertThrows(BusinessException.class, () -> controller.export(
|
||||
"member",
|
||||
@@ -231,9 +232,10 @@ class DedupeTotalDataControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void companyTabNarrowsSuperAdminToListOfMemberAccounts() {
|
||||
// 超管点公司 tab ⇒ 成员集必须一路传到 service 的最后一个实参。
|
||||
// 这一记盯的是"参数收了、readScope 也调了、结果却喂了 null"那种假接线(tab 恒不动的现网形状)。
|
||||
void companyTabNarrowsSuperAdminToRequestedCompanyId() {
|
||||
// 超管点公司 tab ⇒ 门给出的公司 id 必须一路传到 service 的最后一个实参。
|
||||
// 这一记盯的是"参数收了、门也调了、结果却喂了 null"那种假接线(tab 恒不动的现网形状)。
|
||||
// 2026-10-09 口径切换:尾参从"成员账号集"换成"公司 id"(行按 company_id 列筛)。
|
||||
DedupeTotalDataService service = mock(DedupeTotalDataService.class);
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
@@ -246,19 +248,19 @@ class DedupeTotalDataControllerTest {
|
||||
operator.setRole("super_admin");
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(dataReadScope.readScope(operator, 2L)).thenReturn(ReadScope.users(List.of(11L, 12L)));
|
||||
when(dataReadScope.superAdminScopedCompanyId(operator, 2L)).thenReturn(2L);
|
||||
|
||||
controller.page(1L, 15L, null, "member", null, null, null, null, null, 2L, request);
|
||||
|
||||
verify(service).page(eq(1L), eq(15L), isNull(), eq("member"),
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), eq(8L), eq(List.of(11L, 12L)));
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), eq(8L), eq(2L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonSuperAdminStaysUnfilteredEvenWhenCompanyTabIsSent() {
|
||||
// 非超管:刻意<b>不</b>按公司收窄。他的可见集里含"靠分组权限可见"的行,
|
||||
// 叠一层账号 IN 会把那批行静默删掉(口径同 ShopManageController)。
|
||||
// 这条是反向钉:哪天有人给非超管也加上成员集,这里必须红。
|
||||
// 非超管:刻意<b>不</b>按公司收窄(门对非超管恒返回 null,规则在 DataReadScope 内)。
|
||||
// 他的可见集里含"靠分组权限可见"的行,叠一层公司谓词会把那批行静默删掉
|
||||
// (口径同 ShopManageController)。这条是反向钉:哪天有人给非超管也加上公司值,这里必须红。
|
||||
DedupeTotalDataService service = mock(DedupeTotalDataService.class);
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
@@ -274,11 +276,14 @@ class DedupeTotalDataControllerTest {
|
||||
PermissionMenuItemVo granted = new PermissionMenuItemVo();
|
||||
granted.setColumnKey("admin_dedupe_total_data");
|
||||
when(permissionMenuService.getUserColumnPermissions(9L, "admin")).thenReturn(List.of(granted));
|
||||
// 门对非超管恒返回 null(此处用桩复现该语义;Mockito 对包装 Long 的默认值是 0L)
|
||||
when(dataReadScope.superAdminScopedCompanyId(operator, 2L)).thenReturn(null);
|
||||
|
||||
controller.page(1L, 15L, null, null, null, null, null, null, null, 2L, request);
|
||||
|
||||
// 门被调(tab 值确实交给了唯一出口),但非超管由门内规则折成 null ⇒ service 不叠公司条件
|
||||
verify(dataReadScope).superAdminScopedCompanyId(operator, 2L);
|
||||
verify(service).page(eq(1L), eq(15L), isNull(), isNull(),
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), eq(9L), isNull());
|
||||
verify(dataReadScope, never()).readScope(any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -1,5 +1,8 @@
|
||||
package com.nanri.aiimage.modules.dedupe.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
@@ -7,10 +10,13 @@ import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.model.entity.ShopManageGroupEntity;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import com.nanri.aiimage.modules.dedupe.mapper.DedupeTotalDataMapper;
|
||||
import com.nanri.aiimage.modules.dedupe.model.entity.DedupeTotalDataEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.service.ShopManageGroupService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@@ -23,6 +29,10 @@ import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -130,4 +140,36 @@ class DedupeTotalDataCompanySuperAdminGroupAccessTest {
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessage("请选择分组");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("读列表按行归属收窄:company_id = 本公司,不再叠「成员上传」(代导入/上传者已删两族不再漏)")
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void pageNarrowsCompanySuperAdminByRowCompanyId() {
|
||||
// 2026-10-09 口径切换(wholeCompany 分支):原条件 uploader_user_id IN (本公司成员)
|
||||
// 会整批漏掉两类行——超管代导入的行(uploader=超管,不属本公司)与上传账号被硬删的行
|
||||
// (JOIN 不上任何成员集)。先锋公司超管(uid=1206)对 admin 代导入的 14 行与组 33 的
|
||||
// 1452 行历史数据一行都看不到,切到行 company_id 后可见。
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""),
|
||||
DedupeTotalDataEntity.class);
|
||||
stubCompanySuperAdmin();
|
||||
when(shopManageGroupService.listCompanyGroupIds(List.of(OPERATOR_ID)))
|
||||
.thenReturn(Set.of(OWN_COMPANY_GROUP_ID));
|
||||
when(dedupeTotalDataMapper.selectCount(any())).thenReturn(0L);
|
||||
when(dedupeTotalDataMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
service.page(1, 15, "", "", null, null, null, null, null, OPERATOR_ID, null);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<DedupeTotalDataEntity>> captor =
|
||||
ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(dedupeTotalDataMapper).selectCount(captor.capture());
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = captor.getValue();
|
||||
query.getSqlSegment();
|
||||
assertTrue(query.getSqlSegment().contains("company_id"),
|
||||
"公司超管必须按行 company_id 看全公司: " + query.getSqlSegment());
|
||||
assertTrue(query.getParamNameValuePairs().containsValue(OWN_COMPANY_ID),
|
||||
"company_id 收窄值必须是本公司: " + query.getParamNameValuePairs());
|
||||
assertFalse(query.getSqlSegment().contains("uploader_user_id"),
|
||||
"不许回退成「成员上传」口径(会漏代导入/上传者已删两族): " + query.getSqlSegment());
|
||||
}
|
||||
}
|
||||
|
||||
+29
-1
@@ -266,6 +266,34 @@ class DedupeTotalDataServiceTest {
|
||||
assertTrue(query.getCustomSqlSegment().contains("FIND_IN_SET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void pageNarrowsSuperAdminByRowCompanyId() {
|
||||
// 2026-10-09 口径切换:超管切公司 tab 后按行自己的 company_id 筛(原按上传账号集合)。
|
||||
// 这条钉的是 applyCompanyScope 的那一刀:删掉 eq(company_id,…),切 tab 就成装饰品;
|
||||
// 反向(又冒回 uploader_user_id)则 admin 代导入的行会重新归错家。
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""),
|
||||
DedupeTotalDataEntity.class);
|
||||
when(adminUserMapper.selectById(1L)).thenReturn(user(1L, "super_admin", "root"));
|
||||
when(dedupeTotalDataMapper.selectCount(any())).thenReturn(0L);
|
||||
when(dedupeTotalDataMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
service.page(1, 15, "", "", null, null, null, null, null, 1L, 2L);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<DedupeTotalDataEntity>> queryCaptor =
|
||||
ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(dedupeTotalDataMapper).selectCount(queryCaptor.capture());
|
||||
LambdaQueryWrapper<DedupeTotalDataEntity> query = queryCaptor.getValue();
|
||||
query.getSqlSegment();
|
||||
assertTrue(query.getSqlSegment().contains("company_id"),
|
||||
"超管切公司后必须按行 company_id 收窄: " + query.getSqlSegment());
|
||||
assertTrue(query.getParamNameValuePairs().containsValue(2L),
|
||||
"company_id 收窄值必须是 tab 传下来的 2: " + query.getParamNameValuePairs());
|
||||
assertFalse(query.getSqlSegment().contains("uploader_user_id"),
|
||||
"不许再按上传账号收窄: " + query.getSqlSegment());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentDuplicateDuringImportIsSkipped() throws Exception {
|
||||
when(adminUserMapper.selectById(23L)).thenReturn(user(23L, "normal", "member-a"));
|
||||
@@ -382,7 +410,7 @@ class DedupeTotalDataServiceTest {
|
||||
when(dedupeTotalDataMapper.delete(any())).thenReturn(1);
|
||||
|
||||
service.deleteBatchByDataValues(List.of("B012345678"),
|
||||
new DedupeTotalDataService.AccessScope(true, java.util.Set.of(), java.util.Set.of(), false),
|
||||
new DedupeTotalDataService.AccessScope(true, java.util.Set.of(), java.util.Set.of(), false, null),
|
||||
null, 3L);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<DedupeTotalDataEntity>> captor =
|
||||
|
||||
Reference in New Issue
Block a user