feat(公司tab): 任务看板五个端点按公司筛(一处 resolve 收窄,detail 靠 scope.visible 同宽)
This commit is contained in:
+91
@@ -4,6 +4,8 @@ import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -15,6 +17,7 @@ import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
@@ -25,12 +28,18 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* 客户端任务管理的组范围裁剪:超管直通,管理员 = 本人 + 本组用户 + 自己管理的成员。
|
||||
* 口径与 DedupeTotalDataService.resolveAccessScope 一致。
|
||||
*
|
||||
* <p>公司 tab 的收窄走第二个入参 {@code companyUserIds}(controller 已经过 {@code DataReadScope}
|
||||
* 把成员集算好,见 {@code AdminTaskCenterController} 五个 handler),所以本类只喂 List、不 mock
|
||||
* {@code DataReadScope}:{@code null} = 不收窄,空集 = 「选了公司但这家一个账号都没有」,
|
||||
* 两者绝不许混为一谈(后者必须是恒不命中,不是全量)。</p>
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TaskCenterScopeServiceTest {
|
||||
|
||||
@Mock private AdminUserMapper adminUserMapper;
|
||||
@Mock private ShopManageGroupMapper shopManageGroupMapper;
|
||||
@Mock private CompanyScopeSupport companyScopeSupport;
|
||||
@InjectMocks private TaskCenterScopeService service;
|
||||
|
||||
private AdminUserEntity user(Long id, String role) {
|
||||
@@ -120,4 +129,86 @@ class TaskCenterScopeServiceTest {
|
||||
assertThrows(BusinessException.class, () -> service.resolve(404L));
|
||||
assertThrows(BusinessException.class, () -> service.resolve(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("超管选了公司:allUsers 必须翻成 false,否则集合根本不进 SQL,tab 是装饰品")
|
||||
void superAdminWithCompanyStopsBeingUnfiltered() {
|
||||
when(adminUserMapper.selectById(1L)).thenReturn(user(1L, "super_admin"));
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(1L, List.of(11L, 12L));
|
||||
|
||||
assertFalse(scope.allUsers(), "选了公司还 allUsers=true ⇒ sqlUserIds() 交 null ⇒ SQL 整段条件不渲染");
|
||||
assertEquals(Set.of(11L, 12L), Set.copyOf(scope.sqlUserIds()));
|
||||
assertTrue(scope.visible(11L));
|
||||
assertFalse(scope.visible(13L), "别家账号连 tasks/detail 也进不去(详情走 scope.visible,不走 SQL)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("第二参 null(非超管 / 超管没选公司):今天的行为一分不变")
|
||||
void nullCompanyUserIdsKeepsTodayBehavior() {
|
||||
when(adminUserMapper.selectById(1L)).thenReturn(user(1L, "super_admin"));
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(1L, null);
|
||||
|
||||
assertTrue(scope.allUsers(), "没选公司的超管仍然直通");
|
||||
assertNull(scope.sqlUserIds(), "allUsers=true 时交给 SQL 的是 null = 整段 user_id 条件不加");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("历史超管(role 为空 + isAdmin=1 + createdById 为空)选了公司,也得跟着窄")
|
||||
void legacySuperAdminIsNotLeftUnfiltered() {
|
||||
AdminUserEntity legacy = new AdminUserEntity();
|
||||
legacy.setId(2L);
|
||||
legacy.setIsAdmin(1);
|
||||
legacy.setCreatedById(null);
|
||||
when(adminUserMapper.selectById(2L)).thenReturn(legacy);
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(2L, List.of(31L));
|
||||
|
||||
assertFalse(scope.allUsers(), "controller 那侧认这把的是 AdminAuthSupport.currentRole→resolveRole,"
|
||||
+ "与本类的 isSuperAdmin 必须同一条:哪一天单边改了,红的是这条而不是某个历史超管看见全量");
|
||||
assertEquals(Set.of(31L), scope.visibleUserIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("成员集为空时交给 SQL 的是 [-1] 不是空集:IN () 是语法错,兜底在 ScopeContext 里")
|
||||
void emptyMemberSetFallsBackToSentinelNotEmptyList() {
|
||||
when(adminUserMapper.selectById(1L)).thenReturn(user(1L, "super_admin"));
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(1L, List.of());
|
||||
|
||||
assertTrue(scope.visibleUserIds().isEmpty());
|
||||
assertEquals(List.of(-1L), scope.sqlUserIds(), "本任务不许改 :100 那条兜底");
|
||||
assertFalse(scope.visible(11L), "空公司连详情也不能看见任何人");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("非超管的既有分组集:公司集只与之求交,一律不放大")
|
||||
void adminIntersectsWithGroupScope() {
|
||||
when(adminUserMapper.selectById(5L)).thenReturn(user(5L, "admin"));
|
||||
when(shopManageGroupMapper.selectAccessibleGroupIds(5L)).thenReturn(List.of(3L));
|
||||
when(shopManageGroupMapper.selectUserIdsByGroupIds(List.of(3L))).thenReturn(List.of(6L));
|
||||
when(shopManageGroupMapper.selectManagedMemberUserIds(5L)).thenReturn(List.of());
|
||||
|
||||
// 分组集 = 本人 5 + 组员 6(:42-48 的既有口径),公司集 = 6、7 ⇒ 只剩 6
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(5L, List.of(6L, 7L));
|
||||
|
||||
assertFalse(scope.allUsers());
|
||||
assertEquals(Set.of(6L), scope.visibleUserIds(), "公司集里的 7 不在本组可见集内,不许被放大进来");
|
||||
assertFalse(scope.visible(5L), "连本人都被公司维度筛掉时就是筛掉,不保留全部");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("第三条腿(公司超管按会话定本公司成员)逐字留在 resolveBase:没选公司时一分不变")
|
||||
void companySuperAdminLegStillDecidedBySession() {
|
||||
AdminUserEntity operator = user(9L, "company_super_admin");
|
||||
operator.setCompanyId(7L);
|
||||
when(adminUserMapper.selectById(9L)).thenReturn(operator);
|
||||
when(companyScopeSupport.memberUserIds(7L)).thenReturn(List.of(41L, 42L));
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(9L, null);
|
||||
|
||||
assertFalse(scope.allUsers(), "公司超管不是超管,不能直通");
|
||||
assertEquals(Set.of(9L, 41L, 42L), scope.visibleUserIds(), "本人 + 本公司成员(既有口径)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user