refactor(租户): 站点超管判定收成唯一静态出口,看板补第四道门
"super_admin 才算平台超管"这句判断此前在 src/main 里被手抄过 19 遍,2026-10-07 定的 「company_super_admin 在业务数据面同权、只在管理动作收窄」要落地就得一次改到每一处, 漏一处的表现是某一页静默 403 或静默多放行,两边都不报错。现在口径只在 DeviceSessionPolicy.isSuper 比一次: - 出口做成静态谓词而不是 AdminAuthSupport 实例方法——那 18 支测试里 mock 的是 AdminAuthSupport,新增实例方法不会被桩到,默认 false 会把范围静默改窄; - 12 个文件的 15 处调用点改为 DeviceSessionPolicy.isSuper(currentRole(...)), DataReadScope/AdminAuthSupport 只留一个委托包装; - 「客户端任务管理」五个 handler 的成员集计算折进 DataReadScope.superAdminScopedUserIds, 并在 CompanyIdParamGoesThroughReadScopeTest 里补成第四道门(正反探针各一, 判据不会因"抽进私有方法"而失明); - 护栏 SuperAdminPredicateSingleOutletTest 双向钉:出口定义==1、包装==1、调用点==16, 且 banned 掉实例方法形状(自检断言保证它真能红)。 今天口径仍只认 super_admin,这一层是接缝不是开关。Java 全量在本批收口后的那棵树实测 4032 例 0 红 7 skip(7 支是要本地凭据/夹具的回放与实况探测类,历来 skip)。 一并落在这支的文件(同一文件只能进一次提交,故与同批的归属收口混装):ImageVideo/InvalidAsin/ AdminDeviceLog/AdminTaskCenter/DedupeTotalData/AdminShopDataCrawlTasks/AdminShopDataDuplicateCheck/ QueryAsin/ShopManage/SkipPriceAsin 这 10 支控制器的请求身份改走会话出口见 cp-item7 的说明; PermissionMenuService 还删掉了 create/update/delete 三个"operator 传 null 即跳过归属闸门"的 无操作者写重载(src/main 无人调用),判据在 MenuWriteOutletOperatorTest。
This commit is contained in:
+15
-32
@@ -32,16 +32,13 @@ import java.util.List;
|
||||
* <p>仅超管默认可见;管理员需超管在「用户管理 → 菜单权限」授权 {@code admin_task_center}
|
||||
* 后才能访问。数据范围 = 本人 + 本组用户 + 自己管理的成员(超管不裁剪)。</p>
|
||||
*
|
||||
* <p>公司 tab(spec §4):五个端点各收一个可选 {@code company_id},都在 handler 体内过唯一出口
|
||||
* {@link DataReadScope#readScope} 算成员集,再交给 {@code TaskCenterScopeService.resolve} 与既有口径
|
||||
* 求交——一处收窄,五个出口天然同宽(详情走 {@code scope.visible()},用的就是同一条集合)。
|
||||
* 那一行之所以在五个 handler 里各写一遍而不是抽进私有方法:护栏
|
||||
* {@code CompanyIdParamGoesThroughReadScopeTest} 的断言 A 认的是「这支 handler 体内出现过 readScope(」,
|
||||
* 抽走之后**只有 A 会红**(且因为 A 是 fail-fast,只点名第一支);C 根本不响——它的门槛就是「体内含
|
||||
* readScope(」,体内没了就连评估都不评估;D 绿——它认 {@code resolveScope(},而 {@code companyId} 正好
|
||||
* 还在那条私有委托的实参表里。所以逐字重复买到的是「A 这一记看守在每支 handler 上各站一次」,
|
||||
* 不是三重红:别把它当成「C/D 也兜着」而去试 A 拦得住之外的形状(2026-10-05 复评 I-2 订正,
|
||||
* 原话「抽走即三只都红」与 MUT-A 的实测读数 2 tests / 1 failure 不符)。</p>
|
||||
* <p>公司 tab(spec §4):五个端点各收一个可选 {@code company_id},都在 handler 体内过一次唯一出口
|
||||
* {@link DataReadScope#superAdminScopedUserIds} 算成员集,再交给 {@code TaskCenterScopeService.resolve}
|
||||
* 与既有口径求交——一处收窄,五个出口天然同宽(详情走 {@code scope.visible()},用的就是同一条集合)。
|
||||
* 此前这一行在五个 handler 里逐字重复(当时的护栏断言 A 只认「体内出现过 {@code readScope(}」,抽走即红),
|
||||
* 2026-10-07 三期把 {@code superAdminScopedUserIds} 补进 {@code SCOPE_DOORS} 之后,那道理由不再成立:
|
||||
* 判据跟着出口走,而不是让出口迁就判据(见 {@code CompanyIdParamGoesThroughReadScopeTest}
|
||||
* 里 {@code SUPER_SCOPED_*} 三枚探针)。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -65,9 +62,8 @@ public class AdminTaskCenterController {
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.overview(scope));
|
||||
}
|
||||
@@ -80,9 +76,8 @@ public class AdminTaskCenterController {
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.shopOptions(scope));
|
||||
}
|
||||
@@ -98,9 +93,8 @@ public class AdminTaskCenterController {
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.tasks(scope, query));
|
||||
}
|
||||
@@ -114,9 +108,8 @@ public class AdminTaskCenterController {
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
TaskCenterTaskDetailVo detail = queryService.detail(scope, taskNo);
|
||||
if (detail == null) {
|
||||
@@ -138,9 +131,8 @@ public class AdminTaskCenterController {
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(variantService.variantTasks(scope, status, taskType, page, pageSize));
|
||||
}
|
||||
@@ -154,18 +146,9 @@ public class AdminTaskCenterController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否站点超管——用的是 {@code AdminAuthSupport.currentRole}(与 {@code DataReadScope} 内部同一把尺子,
|
||||
* 含「role 为空 + isAdmin=1 + createdById 为空」的历史超管推断),不是这里新造的判定。
|
||||
* 只有超管才按公司 tab 收窄:非超管的可见集里含「靠分组可见」的行,给它叠成员集会把那批行
|
||||
* 从每一个 tab 里静默删掉;它的公司维度本来就由会话独家决定(spec §4)。
|
||||
*/
|
||||
private boolean isSuper(AdminUserEntity operator) {
|
||||
return "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||
}
|
||||
|
||||
/**
|
||||
* 五个端点共用的收窄出口:{@code companyUserIds} 必须是 handler 体内 {@code readScope} 算出来的那个值
|
||||
* ({@code null} = 不收窄),不许在这一层重新取公司值——那样护栏 A/C/D 看见的就不是这条链了。
|
||||
* 五个端点共用的收窄出口:{@code companyUserIds} 必须是 handler 体内
|
||||
* {@link DataReadScope#superAdminScopedUserIds} 算出来的那个值({@code null} = 不收窄),
|
||||
* 不许在这一层重新取公司值——那样护栏 A/C/D 看见的就不是这条链了。
|
||||
*/
|
||||
private TaskCenterScopeService.ScopeContext resolveScope(Long operatorId, List<Long> companyUserIds) {
|
||||
return scopeService.resolve(operatorId, companyUserIds);
|
||||
|
||||
+3
-3
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.taskcenter.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
@@ -104,9 +105,8 @@ public class TaskCenterScopeService {
|
||||
}
|
||||
|
||||
private boolean isSuperAdmin(AdminUserEntity user) {
|
||||
String role = user.getRole() == null ? "" : user.getRole().trim().toLowerCase(Locale.ROOT);
|
||||
return "super_admin".equals(role)
|
||||
|| (role.isEmpty() && Integer.valueOf(1).equals(user.getIsAdmin()) && user.getCreatedById() == null);
|
||||
return user != null
|
||||
&& DeviceSessionPolicy.isSuperAdmin(user.getRole(), user.getIsAdmin(), user.getCreatedById());
|
||||
}
|
||||
|
||||
/** 公司超管判定(老数据 role 为空不参与:公司超管是新角色,只认显式取值)。 */
|
||||
|
||||
Reference in New Issue
Block a user