feat(公司tab): 接线 密钥管理与用量统计——分组∩公司取交集,空集不退化
两页都从 controller 这一个唯一出口算范围:收了 company_id 的 handler 自己调 dataReadScope.readScope(operator, companyId),把算好的 ReadScope 交给 service; service 里 scopedUserIds() 只做 companyScope.userIdsOr(base),不再出现第二个判公司的 if。 readScope 落在 controller 而非计划原文写的 service,是因为 Task 8 补的 G2 尺子 CompanyIdParamGoesThroughReadScopeTest 逐 controller 断言"收参数就得自己调出口并把结果当实参交出去"。 空集一律早退(交给 in(...) 会渲染成 IN () → 500),且两条"筛空"日志按超管/主管分开, 排障时看得出是筛空还是查空;非超管空页仍返回带分组下拉的空页,下拉不缩水。 新增 6 条行为用例(超管 group_id∩公司成员集、交集空早退且不查库、不传公司保持不筛、 主管锁定集只被收窄不放大)。分母 3716 → 3722,Failures/Errors 均 0。 FE 侧两页带 company_id 并把 company-tab-wiring 缺口清单从 6 页收到 4 页。
This commit is contained in:
@@ -31,6 +31,8 @@ export interface UserSecretUsageQuery {
|
|||||||
keyword?: string
|
keyword?: string
|
||||||
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
|
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
|
||||||
groupId?: number
|
groupId?: number
|
||||||
|
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
|
||||||
|
companyId?: number | null
|
||||||
page: number
|
page: number
|
||||||
pageSize: number
|
pageSize: number
|
||||||
}
|
}
|
||||||
@@ -42,6 +44,9 @@ export async function fetchUserSecretUsage(params: UserSecretUsageQuery): Promis
|
|||||||
if (params.endDate) query.endDate = params.endDate
|
if (params.endDate) query.endDate = params.endDate
|
||||||
if (params.keyword) query.keyword = params.keyword
|
if (params.keyword) query.keyword = params.keyword
|
||||||
if (params.groupId) query.group_id = params.groupId
|
if (params.groupId) query.group_id = params.groupId
|
||||||
|
// 用 `!= null` 而不是上面那几行的 truthy 写法:company_id=0 会让后端 requireCompanyId 直接抛,
|
||||||
|
// 宁可让参数缺失时它不出现,也别把 0 悄悄当没传。
|
||||||
|
if (params.companyId != null) query.company_id = params.companyId
|
||||||
const { data } = await http.get('/api/admin/user-secret-usage', { params: query })
|
const { data } = await http.get('/api/admin/user-secret-usage', { params: query })
|
||||||
return unwrap<AdminUserSecretUsagePage>(data)
|
return unwrap<AdminUserSecretUsagePage>(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ export interface UserSecretQuery {
|
|||||||
checkStatus?: string
|
checkStatus?: string
|
||||||
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
|
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
|
||||||
groupId?: number
|
groupId?: number
|
||||||
|
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
|
||||||
|
companyId?: number | null
|
||||||
page: number
|
page: number
|
||||||
pageSize: number
|
pageSize: number
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,9 @@ export async function fetchUserSecretList(params: UserSecretQuery): Promise<Admi
|
|||||||
if (params.keyword) query.keyword = params.keyword
|
if (params.keyword) query.keyword = params.keyword
|
||||||
if (params.checkStatus) query.checkStatus = params.checkStatus
|
if (params.checkStatus) query.checkStatus = params.checkStatus
|
||||||
if (params.groupId) query.group_id = params.groupId
|
if (params.groupId) query.group_id = params.groupId
|
||||||
|
// 用 `!= null` 而不是上面那几行的 truthy 写法:company_id=0 会让后端 requireCompanyId 直接抛,
|
||||||
|
// 宁可让参数缺失时它不出现,也别把 0 悄悄当没传。
|
||||||
|
if (params.companyId != null) query.company_id = params.companyId
|
||||||
const { data } = await http.get('/api/admin/user-secrets', { params: query })
|
const { data } = await http.get('/api/admin/user-secrets', { params: query })
|
||||||
return unwrap<AdminUserSecretPage>(data)
|
return unwrap<AdminUserSecretPage>(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import OldPagination from '@/components/OldPagination.vue'
|
import OldPagination from '@/components/OldPagination.vue'
|
||||||
import { todayDateInput } from '@/utils/datetime'
|
import { todayDateInput } from '@/utils/datetime'
|
||||||
@@ -9,8 +9,10 @@ import {
|
|||||||
} from '@/api/user-secret-usage'
|
} from '@/api/user-secret-usage'
|
||||||
import type { GroupOption } from '@/api/user-secrets'
|
import type { GroupOption } from '@/api/user-secrets'
|
||||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||||
|
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||||
|
|
||||||
const session = useAdminSessionStore()
|
const session = useAdminSessionStore()
|
||||||
|
const companyTab = useCompanyTabStore()
|
||||||
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
||||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ async function load() {
|
|||||||
endDate: endDate.value || undefined,
|
endDate: endDate.value || undefined,
|
||||||
keyword: keyword.value.trim() || undefined,
|
keyword: keyword.value.trim() || undefined,
|
||||||
groupId: groupFilter.value || undefined,
|
groupId: groupFilter.value || undefined,
|
||||||
|
companyId: companyTab.requestCompanyId,
|
||||||
page: page.value,
|
page: page.value,
|
||||||
pageSize: pageSize.value,
|
pageSize: pageSize.value,
|
||||||
})
|
})
|
||||||
@@ -62,6 +65,9 @@ async function load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||||||
|
watch(() => companyTab.activeId, () => void load())
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
page.value = 1
|
page.value = 1
|
||||||
load()
|
load()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { formatDateTime } from '@/utils/datetime'
|
import { formatDateTime } from '@/utils/datetime'
|
||||||
import OldPagination from '@/components/OldPagination.vue'
|
import OldPagination from '@/components/OldPagination.vue'
|
||||||
@@ -14,8 +14,10 @@ import {
|
|||||||
type GroupOption,
|
type GroupOption,
|
||||||
} from '@/api/user-secrets'
|
} from '@/api/user-secrets'
|
||||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||||
|
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||||
|
|
||||||
const session = useAdminSessionStore()
|
const session = useAdminSessionStore()
|
||||||
|
const companyTab = useCompanyTabStore()
|
||||||
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
||||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||||
|
|
||||||
@@ -114,6 +116,7 @@ async function load() {
|
|||||||
keyword: keyword.value.trim() || undefined,
|
keyword: keyword.value.trim() || undefined,
|
||||||
checkStatus: statusFilter.value || undefined,
|
checkStatus: statusFilter.value || undefined,
|
||||||
groupId: groupFilter.value || undefined,
|
groupId: groupFilter.value || undefined,
|
||||||
|
companyId: companyTab.requestCompanyId,
|
||||||
page: page.value,
|
page: page.value,
|
||||||
pageSize: pageSize.value,
|
pageSize: pageSize.value,
|
||||||
})
|
})
|
||||||
@@ -127,6 +130,9 @@ async function load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||||||
|
watch(() => companyTab.activeId, () => void load())
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
page.value = 1
|
page.value = 1
|
||||||
load()
|
load()
|
||||||
|
|||||||
@@ -51,10 +51,20 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
|
|||||||
{ file: 'src/pages/task-center/task-center-model.ts', shape: null, note: '同上:这一页有两个取数模块,两个都得登记' },
|
{ file: 'src/pages/task-center/task-center-model.ts', shape: null, note: '同上:这一页有两个取数模块,两个都得登记' },
|
||||||
],
|
],
|
||||||
admin_user_secret_usage: [
|
admin_user_secret_usage: [
|
||||||
{ file: 'src/api/user-secret-usage.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
{
|
||||||
|
file: 'src/api/user-secret-usage.ts',
|
||||||
|
// fetchUserSecretUsage(params: UserSecretUsageQuery):唯一入参对象是 params(:45 那一行的形状)。
|
||||||
|
shape: /company_id\s*=\s*params\.companyId\b/,
|
||||||
|
note: 'query 由本函数自己从零构造,companyId 只能取自 params;api 模块不碰 Pinia store(node --test 直接 import 会抛 no active pinia)',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
admin_user_secrets: [
|
admin_user_secrets: [
|
||||||
{ file: 'src/api/user-secrets.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
{
|
||||||
|
file: 'src/api/user-secrets.ts',
|
||||||
|
// fetchUserSecretList(params: UserSecretQuery):唯一入参对象是 params(:71 那一行的形状)。
|
||||||
|
shape: /company_id\s*=\s*params\.companyId\b/,
|
||||||
|
note: '同上:值由 UserSecretsPage.vue 传 companyTab.requestCompanyId,api 里不读任何归一化/构造出来的中间对象',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
admin_device_logs: [
|
admin_device_logs: [
|
||||||
{ file: 'src/api/device-logs.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
{ file: 'src/api/device-logs.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
||||||
|
|||||||
+7
-1
@@ -3,6 +3,8 @@ package com.nanri.aiimage.modules.usersecret.controller;
|
|||||||
import com.nanri.aiimage.common.api.ApiResponse;
|
import com.nanri.aiimage.common.api.ApiResponse;
|
||||||
import com.nanri.aiimage.config.UserSecretProperties;
|
import com.nanri.aiimage.config.UserSecretProperties;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
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.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretQuery;
|
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretQuery;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.dto.UserApiSecretSaveRequest;
|
import com.nanri.aiimage.modules.usersecret.model.dto.UserApiSecretSaveRequest;
|
||||||
@@ -43,6 +45,7 @@ public class AdminUserApiSecretController {
|
|||||||
private final UserApiSecretService userApiSecretService;
|
private final UserApiSecretService userApiSecretService;
|
||||||
private final UserSecretProperties userSecretProperties;
|
private final UserSecretProperties userSecretProperties;
|
||||||
private final AdminAuthSupport adminAuthSupport;
|
private final AdminAuthSupport adminAuthSupport;
|
||||||
|
private final DataReadScope dataReadScope;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分页查询用户密钥", description = "一行一用户;keyword 匹配用户名,checkStatus 按行级状态筛选。主管只能看自己带的分组成员,超管看全量并可按分组筛选。")
|
@Operation(summary = "分页查询用户密钥", description = "一行一用户;keyword 匹配用户名,checkStatus 按行级状态筛选。主管只能看自己带的分组成员,超管看全量并可按分组筛选。")
|
||||||
@@ -51,6 +54,7 @@ public class AdminUserApiSecretController {
|
|||||||
@Parameter(description = "关键字:用户名") @RequestParam(required = false) String keyword,
|
@Parameter(description = "关键字:用户名") @RequestParam(required = false) String keyword,
|
||||||
@Parameter(description = "行级状态筛选:passed/failed/incomplete/error/unknown") @RequestParam(required = false) String checkStatus,
|
@Parameter(description = "行级状态筛选:passed/failed/incomplete/error/unknown") @RequestParam(required = false) String checkStatus,
|
||||||
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||||
|
@Parameter(description = "按公司筛选(仅超管生效;非超管一律按会话公司裁剪,越界公司为空页)") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
||||||
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
||||||
@@ -60,7 +64,9 @@ public class AdminUserApiSecretController {
|
|||||||
query.setGroupId(groupId);
|
query.setGroupId(groupId);
|
||||||
query.setPage(page);
|
query.setPage(page);
|
||||||
query.setPageSize(pageSize);
|
query.setPageSize(pageSize);
|
||||||
return ApiResponse.success(userApiSecretService.adminPage(operator, query));
|
// 读范围只在 controller 这唯一出口算一次;service 拿到的是算好的范围,自己不判公司。
|
||||||
|
ReadScope companyScope = dataReadScope.readScope(operator, companyId);
|
||||||
|
return ApiResponse.success(userApiSecretService.adminPage(operator, query, companyScope));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{userId}/check")
|
@PostMapping("/{userId}/check")
|
||||||
|
|||||||
+7
-1
@@ -2,6 +2,8 @@ package com.nanri.aiimage.modules.usersecret.controller;
|
|||||||
|
|
||||||
import com.nanri.aiimage.common.api.ApiResponse;
|
import com.nanri.aiimage.common.api.ApiResponse;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
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.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretUsageQuery;
|
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretUsageQuery;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.vo.AdminUserSecretUsagePageVo;
|
import com.nanri.aiimage.modules.usersecret.model.vo.AdminUserSecretUsagePageVo;
|
||||||
@@ -31,6 +33,7 @@ public class AdminUserSecretUsageController {
|
|||||||
|
|
||||||
private final UserSecretUsageService userSecretUsageService;
|
private final UserSecretUsageService userSecretUsageService;
|
||||||
private final AdminAuthSupport adminAuthSupport;
|
private final AdminAuthSupport adminAuthSupport;
|
||||||
|
private final DataReadScope dataReadScope;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分页查询密钥用量",
|
@Operation(summary = "分页查询密钥用量",
|
||||||
@@ -43,6 +46,7 @@ public class AdminUserSecretUsageController {
|
|||||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||||
@Parameter(description = "关键字:用户名") @RequestParam(required = false) String keyword,
|
@Parameter(description = "关键字:用户名") @RequestParam(required = false) String keyword,
|
||||||
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||||
|
@Parameter(description = "按公司筛选(仅超管生效;非超管一律按会话公司裁剪,越界公司为空页)") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
||||||
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
||||||
@@ -53,6 +57,8 @@ public class AdminUserSecretUsageController {
|
|||||||
query.setGroupId(groupId);
|
query.setGroupId(groupId);
|
||||||
query.setPage(page);
|
query.setPage(page);
|
||||||
query.setPageSize(pageSize);
|
query.setPageSize(pageSize);
|
||||||
return ApiResponse.success(userSecretUsageService.adminPage(operator, query));
|
// 读范围只在 controller 这唯一出口算一次;service 拿到的是算好的范围,自己不判公司。
|
||||||
|
ReadScope companyScope = dataReadScope.readScope(operator, companyId);
|
||||||
|
return ApiResponse.success(userSecretUsageService.adminPage(operator, query, companyScope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-12
@@ -7,6 +7,7 @@ import com.nanri.aiimage.modules.admin.spi.UserSecretCleanupPort;
|
|||||||
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
||||||
import com.nanri.aiimage.config.UserSecretProperties;
|
import com.nanri.aiimage.config.UserSecretProperties;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||||
|
import com.nanri.aiimage.common.service.ReadScope;
|
||||||
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
||||||
import com.nanri.aiimage.modules.notification.service.NotificationService;
|
import com.nanri.aiimage.modules.notification.service.NotificationService;
|
||||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||||
@@ -314,8 +315,9 @@ public class UserApiSecretService implements UserSecretCleanupPort {
|
|||||||
* 先按关键字圈定用户,再全量聚合、行级状态筛选、按最近更新时间倒序后内存分页
|
* 先按关键字圈定用户,再全量聚合、行级状态筛选、按最近更新时间倒序后内存分页
|
||||||
* (当前规模为用户数×3,内存聚合成本可控;量级上来后可改为 GROUP BY 下推)。
|
* (当前规模为用户数×3,内存聚合成本可控;量级上来后可改为 GROUP BY 下推)。
|
||||||
*/
|
*/
|
||||||
/** 后台分页查询:主管(admin)只看自己带的「数据权限分组」成员;超管看全量、可按分组筛选。 */
|
/** 后台分页查询:主管(admin)只看自己带的「数据权限分组」成员;超管看全量、可按分组与公司筛选。 */
|
||||||
public AdminUserSecretPageVo adminPage(AdminUserEntity operator, AdminUserSecretQuery query) {
|
public AdminUserSecretPageVo adminPage(AdminUserEntity operator, AdminUserSecretQuery query,
|
||||||
|
ReadScope companyScope) {
|
||||||
AdminUserSecretQuery safeQuery = query == null ? new AdminUserSecretQuery() : query;
|
AdminUserSecretQuery safeQuery = query == null ? new AdminUserSecretQuery() : query;
|
||||||
long page = safeQuery.getPage() == null || safeQuery.getPage() < 1 ? 1L : safeQuery.getPage();
|
long page = safeQuery.getPage() == null || safeQuery.getPage() < 1 ? 1L : safeQuery.getPage();
|
||||||
long pageSize = safeQuery.getPageSize() == null || safeQuery.getPageSize() < 1
|
long pageSize = safeQuery.getPageSize() == null || safeQuery.getPageSize() < 1
|
||||||
@@ -323,18 +325,19 @@ public class UserApiSecretService implements UserSecretCleanupPort {
|
|||||||
|
|
||||||
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||||
Long requestedGroupId = safeQuery.getGroupId();
|
Long requestedGroupId = safeQuery.getGroupId();
|
||||||
// 组隔离:主管强制锁定自己带的分组(组长本人 + 名下子账户);超管按 group_id 筛选(空 = 全部)。
|
// 组隔离(主管锁定自己带的分组、超管按 group_id 筛)叠上公司 tab:两条维度取**交集**,
|
||||||
List<Long> scopedUserIds = null;
|
// 公司 tab 只能收窄,绝不放大分组看不到的行;范围本身由 controller 经唯一出口算好交下来。
|
||||||
if (superAdmin) {
|
List<Long> scopedUserIds = scopedUserIds(operator, requestedGroupId, companyScope);
|
||||||
if (requestedGroupId != null && requestedGroupId > 0) {
|
// 空集必须早退:交给下面的 in(...) 会渲染成 IN () → SQL 语法错 → 500。
|
||||||
scopedUserIds = adminGroupMapper.selectUserIdsByGroupId(requestedGroupId);
|
// 两条日志分开,排障时看得出是「筛空」(范围交集为空)还是「查空」(库里没记录)。
|
||||||
}
|
if (scopedUserIds != null && scopedUserIds.isEmpty()) {
|
||||||
} else {
|
if (superAdmin) {
|
||||||
scopedUserIds = userDataScopeSupport.resolveVisibleUserIds(operator.getId());
|
log.info("[user-secret] 后台密钥列表:公司或分组筛后无匹配用户,返回空 operatorId={} groupId={}",
|
||||||
if (scopedUserIds.isEmpty()) {
|
operator.getId(), requestedGroupId);
|
||||||
|
} else {
|
||||||
log.info("[user-secret] 后台密钥列表:主管名下无子账户,返回空 operatorId={}", operator.getId());
|
log.info("[user-secret] 后台密钥列表:主管名下无子账户,返回空 operatorId={}", operator.getId());
|
||||||
return emptyPageWithGroups(page, pageSize, groupOptions(operator, false));
|
|
||||||
}
|
}
|
||||||
|
return emptyPageWithGroups(page, pageSize, groupOptions(operator, superAdmin));
|
||||||
}
|
}
|
||||||
List<Long> ledGroupIds = superAdmin ? List.of() : userDataScopeSupport.listLedGroupIds(operator.getId());
|
List<Long> ledGroupIds = superAdmin ? List.of() : userDataScopeSupport.listLedGroupIds(operator.getId());
|
||||||
|
|
||||||
@@ -399,6 +402,25 @@ public class UserApiSecretService implements UserSecretCleanupPort {
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台列表的可见用户集:组长锁定 ∩ 超管 group_id ∩ 公司 tab。
|
||||||
|
* <p>{@code null} = 不筛(超管既没选公司也没选分组,今天的行为);<b>空集由调用方早退</b>,
|
||||||
|
* 不许交给 {@code LambdaQueryWrapper.in(...)}。交集只在 {@link ReadScope#userIdsOr(java.util.List)}
|
||||||
|
* 这一处发生——service 里不许再写第二个判公司的 if。
|
||||||
|
*/
|
||||||
|
List<Long> scopedUserIds(AdminUserEntity operator, Long requestedGroupId, ReadScope companyScope) {
|
||||||
|
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||||
|
List<Long> base = null;
|
||||||
|
if (superAdmin) {
|
||||||
|
if (requestedGroupId != null && requestedGroupId > 0) {
|
||||||
|
base = adminGroupMapper.selectUserIdsByGroupId(requestedGroupId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
base = userDataScopeSupport.resolveVisibleUserIds(operator.getId());
|
||||||
|
}
|
||||||
|
return companyScope.userIdsOr(base);
|
||||||
|
}
|
||||||
|
|
||||||
/** 分组筛选项:超管=全部;主管=自己带的分组。 */
|
/** 分组筛选项:超管=全部;主管=自己带的分组。 */
|
||||||
private List<AdminUserSecretPageVo.GroupOptionVo> groupOptions(AdminUserEntity operator, boolean superAdmin) {
|
private List<AdminUserSecretPageVo.GroupOptionVo> groupOptions(AdminUserEntity operator, boolean superAdmin) {
|
||||||
List<ShopManageGroupEntity> groups = superAdmin
|
List<ShopManageGroupEntity> groups = superAdmin
|
||||||
|
|||||||
+31
-10
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.usersecret.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||||
|
import com.nanri.aiimage.common.service.ReadScope;
|
||||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
import com.nanri.aiimage.modules.permission.support.UserDataScopeSupport;
|
import com.nanri.aiimage.modules.permission.support.UserDataScopeSupport;
|
||||||
@@ -90,7 +91,8 @@ public class UserSecretUsageService {
|
|||||||
* 隔离规则同密钥列表:主管只看自己带的「数据权限分组」成员,超管看全量并可按分组筛选;
|
* 隔离规则同密钥列表:主管只看自己带的「数据权限分组」成员,超管看全量并可按分组筛选;
|
||||||
* 先全量聚合、再按合计次数倒序内存分页(当前规模可控,量级上来后可改 GROUP BY 下推)。
|
* 先全量聚合、再按合计次数倒序内存分页(当前规模可控,量级上来后可改 GROUP BY 下推)。
|
||||||
*/
|
*/
|
||||||
public AdminUserSecretUsagePageVo adminPage(AdminUserEntity operator, AdminUserSecretUsageQuery query) {
|
public AdminUserSecretUsagePageVo adminPage(AdminUserEntity operator, AdminUserSecretUsageQuery query,
|
||||||
|
ReadScope companyScope) {
|
||||||
AdminUserSecretUsageQuery safeQuery = query == null ? new AdminUserSecretUsageQuery() : query;
|
AdminUserSecretUsageQuery safeQuery = query == null ? new AdminUserSecretUsageQuery() : query;
|
||||||
long page = safeQuery.getPage() == null || safeQuery.getPage() < 1 ? 1L : safeQuery.getPage();
|
long page = safeQuery.getPage() == null || safeQuery.getPage() < 1 ? 1L : safeQuery.getPage();
|
||||||
long pageSize = safeQuery.getPageSize() == null || safeQuery.getPageSize() < 1
|
long pageSize = safeQuery.getPageSize() == null || safeQuery.getPageSize() < 1
|
||||||
@@ -98,17 +100,18 @@ public class UserSecretUsageService {
|
|||||||
|
|
||||||
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||||
Long requestedGroupId = safeQuery.getGroupId();
|
Long requestedGroupId = safeQuery.getGroupId();
|
||||||
List<Long> scopedUserIds = null;
|
// 组隔离(主管锁定自己带的分组、超管按 group_id 筛)叠上公司 tab:取**交集**,公司 tab 只收窄。
|
||||||
if (superAdmin) {
|
List<Long> scopedUserIds = scopedUserIds(operator, requestedGroupId, companyScope);
|
||||||
if (requestedGroupId != null && requestedGroupId > 0) {
|
// 空集必须早退:交给下面的 in(...) 会渲染成 IN () → SQL 语法错 → 500。
|
||||||
scopedUserIds = adminGroupMapper.selectUserIdsByGroupId(requestedGroupId);
|
// 两条日志分开,排障时看得出是「筛空」(范围交集为空)还是「查空」(库里没记录)。
|
||||||
}
|
if (scopedUserIds != null && scopedUserIds.isEmpty()) {
|
||||||
} else {
|
if (superAdmin) {
|
||||||
scopedUserIds = userDataScopeSupport.resolveVisibleUserIds(operator.getId());
|
log.info("[user-secret-usage] 用量统计:公司或分组筛后无匹配用户,返回空 operatorId={} groupId={}",
|
||||||
if (scopedUserIds.isEmpty()) {
|
operator.getId(), requestedGroupId);
|
||||||
|
} else {
|
||||||
log.info("[user-secret-usage] 用量统计:主管名下无子账户,返回空 operatorId={}", operator.getId());
|
log.info("[user-secret-usage] 用量统计:主管名下无子账户,返回空 operatorId={}", operator.getId());
|
||||||
return emptyPage(page, pageSize, groupOptions(operator, false));
|
|
||||||
}
|
}
|
||||||
|
return emptyPage(page, pageSize, groupOptions(operator, superAdmin));
|
||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<UserSecretUsageEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserSecretUsageEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
@@ -207,6 +210,24 @@ public class UserSecretUsageService {
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用量统计的可见用户集:组长锁定 ∩ 超管 group_id ∩ 公司 tab(与密钥列表同形)。
|
||||||
|
* <p>{@code null} = 不筛(超管既没选公司也没选分组);<b>空集由调用方早退</b>,不许交给
|
||||||
|
* {@code LambdaQueryWrapper.in(...)}。交集只在 {@link ReadScope#userIdsOr(java.util.List)} 这一处发生。
|
||||||
|
*/
|
||||||
|
List<Long> scopedUserIds(AdminUserEntity operator, Long requestedGroupId, ReadScope companyScope) {
|
||||||
|
boolean superAdmin = "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||||
|
List<Long> base = null;
|
||||||
|
if (superAdmin) {
|
||||||
|
if (requestedGroupId != null && requestedGroupId > 0) {
|
||||||
|
base = adminGroupMapper.selectUserIdsByGroupId(requestedGroupId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
base = userDataScopeSupport.resolveVisibleUserIds(operator.getId());
|
||||||
|
}
|
||||||
|
return companyScope.userIdsOr(base);
|
||||||
|
}
|
||||||
|
|
||||||
/** 本页行补用户名与分组名(各一次批量查询)。 */
|
/** 本页行补用户名与分组名(各一次批量查询)。 */
|
||||||
private void fillRowMeta(List<AdminUserSecretUsageRowVo> pageItems) {
|
private void fillRowMeta(List<AdminUserSecretUsageRowVo> pageItems) {
|
||||||
List<Long> userIds = pageItems.stream()
|
List<Long> userIds = pageItems.stream()
|
||||||
|
|||||||
+61
-5
@@ -8,6 +8,7 @@ import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|||||||
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
||||||
import com.nanri.aiimage.config.UserSecretProperties;
|
import com.nanri.aiimage.config.UserSecretProperties;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||||
|
import com.nanri.aiimage.common.service.ReadScope;
|
||||||
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
||||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
@@ -22,6 +23,7 @@ import com.nanri.aiimage.modules.usersecret.model.entity.UserApiSecretEntity;
|
|||||||
import com.nanri.aiimage.modules.usersecret.model.vo.AdminUserSecretModuleVo;
|
import com.nanri.aiimage.modules.usersecret.model.vo.AdminUserSecretModuleVo;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.vo.UserApiSecretBundleVo;
|
import com.nanri.aiimage.modules.usersecret.model.vo.UserApiSecretBundleVo;
|
||||||
import com.nanri.aiimage.modules.usersecret.support.UserSecretModule;
|
import com.nanri.aiimage.modules.usersecret.support.UserSecretModule;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
@@ -477,7 +479,7 @@ class UserApiSecretServiceTest {
|
|||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(88L);
|
operator.setId(88L);
|
||||||
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
var page = service.adminPage(operator, new AdminUserSecretQuery());
|
var page = service.adminPage(operator, new AdminUserSecretQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).hasSize(1);
|
assertThat(page.getItems()).hasSize(1);
|
||||||
var rowVo = page.getItems().get(0);
|
var rowVo = page.getItems().get(0);
|
||||||
@@ -500,7 +502,7 @@ class UserApiSecretServiceTest {
|
|||||||
when(adminGroupMapper.selectLedGroups(88L)).thenReturn(List.of());
|
when(adminGroupMapper.selectLedGroups(88L)).thenReturn(List.of());
|
||||||
when(adminUserMapper.selectList(any())).thenReturn(List.of());
|
when(adminUserMapper.selectList(any())).thenReturn(List.of());
|
||||||
|
|
||||||
var page = service.adminPage(operator, new AdminUserSecretQuery());
|
var page = service.adminPage(operator, new AdminUserSecretQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).isEmpty();
|
assertThat(page.getItems()).isEmpty();
|
||||||
assertThat(page.getGroupOptions()).isEmpty();
|
assertThat(page.getGroupOptions()).isEmpty();
|
||||||
@@ -526,7 +528,7 @@ class UserApiSecretServiceTest {
|
|||||||
ref.setGroupName("一组");
|
ref.setGroupName("一组");
|
||||||
when(adminGroupMapper.selectGroupNamesByUserIds(any())).thenReturn(List.of(ref));
|
when(adminGroupMapper.selectGroupNamesByUserIds(any())).thenReturn(List.of(ref));
|
||||||
|
|
||||||
var page = service.adminPage(operator, new AdminUserSecretQuery());
|
var page = service.adminPage(operator, new AdminUserSecretQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).hasSize(1);
|
assertThat(page.getItems()).hasSize(1);
|
||||||
assertThat(page.getItems().get(0).getGroups()).containsExactly("一组");
|
assertThat(page.getItems().get(0).getGroups()).containsExactly("一组");
|
||||||
@@ -589,7 +591,7 @@ class UserApiSecretServiceTest {
|
|||||||
when(adminUserMapper.selectBatchIds(any())).thenReturn(List.of(user, leader));
|
when(adminUserMapper.selectBatchIds(any())).thenReturn(List.of(user, leader));
|
||||||
when(adminGroupMapper.selectAllGroups()).thenReturn(List.of());
|
when(adminGroupMapper.selectAllGroups()).thenReturn(List.of());
|
||||||
|
|
||||||
var page = service.adminPage(operator, new AdminUserSecretQuery());
|
var page = service.adminPage(operator, new AdminUserSecretQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).hasSize(1);
|
assertThat(page.getItems()).hasSize(1);
|
||||||
assertThat(page.getItems().get(0).getGroups()).isEmpty();
|
assertThat(page.getItems().get(0).getGroups()).isEmpty();
|
||||||
@@ -607,12 +609,66 @@ class UserApiSecretServiceTest {
|
|||||||
|
|
||||||
AdminUserSecretQuery query = new AdminUserSecretQuery();
|
AdminUserSecretQuery query = new AdminUserSecretQuery();
|
||||||
query.setGroupId(5L);
|
query.setGroupId(5L);
|
||||||
var page = service.adminPage(operator, query);
|
var page = service.adminPage(operator, query, ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).isEmpty();
|
assertThat(page.getItems()).isEmpty();
|
||||||
verify(adminGroupMapper).selectUserIdsByGroupId(5L);
|
verify(adminGroupMapper).selectUserIdsByGroupId(5L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("超管 group_id + company_id 同时给:取交集,不是后一个覆盖前一个")
|
||||||
|
void groupAndCompanyIntersect() {
|
||||||
|
UserApiSecretService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
|
when(adminGroupMapper.selectUserIdsByGroupId(7L)).thenReturn(List.of(12L, 13L, 99L));
|
||||||
|
|
||||||
|
List<Long> scoped = service.scopedUserIds(operator, 7L, ReadScope.users(List.of(11L, 12L, 13L)));
|
||||||
|
|
||||||
|
assertThat(scoped).containsExactlyInAnyOrder(12L, 13L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("公司选了但交集为空:返回空页,不许退化成「不筛」(那是越权)")
|
||||||
|
void emptyIntersectionReturnsEmptyPage() {
|
||||||
|
UserApiSecretService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
|
when(adminGroupMapper.selectUserIdsByGroupId(7L)).thenReturn(List.of(99L));
|
||||||
|
assertThat(service.scopedUserIds(operator, 7L, ReadScope.users(List.of(11L)))).isEmpty();
|
||||||
|
|
||||||
|
// 空集必须由 adminPage 早退:交给 in(...) 会渲染成 IN () → SQL 语法错 → 500。
|
||||||
|
AdminUserSecretQuery query = new AdminUserSecretQuery();
|
||||||
|
query.setGroupId(7L);
|
||||||
|
var page = service.adminPage(operator, query, ReadScope.users(List.of(11L)));
|
||||||
|
assertThat(page.getItems()).isEmpty();
|
||||||
|
verify(mapper, never()).selectList(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("超管不传公司:保持今天的不筛(全局约束 2——tab 不是安全边界,不许把空公司 id 当成筛)")
|
||||||
|
void superAdminWithoutCompanyStaysUnfiltered() {
|
||||||
|
UserApiSecretService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
|
assertThat(service.scopedUserIds(operator, null, ReadScope.unfiltered())).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("主管:组长锁定 ∩ 公司成员集;越界公司的成员集是空集 ⇒ 空页,不是全量")
|
||||||
|
void leaderVisibleSetIsNarrowedByCompany() {
|
||||||
|
UserApiSecretService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(userDataScopeSupport.resolveVisibleUserIds(88L)).thenReturn(List.of(1L, 2L, 88L));
|
||||||
|
assertThat(service.scopedUserIds(operator, null, ReadScope.users(List.of(2L, 88L))))
|
||||||
|
.containsExactlyInAnyOrder(2L, 88L);
|
||||||
|
assertThat(service.scopedUserIds(operator, null, ReadScope.users(List.of()))).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void adminClearByUserDeletesAllRowsOfUser() {
|
void adminClearByUserDeletesAllRowsOfUser() {
|
||||||
UserApiSecretService service = newService();
|
UserApiSecretService service = newService();
|
||||||
|
|||||||
+40
-4
@@ -1,6 +1,7 @@
|
|||||||
package com.nanri.aiimage.modules.usersecret.service;
|
package com.nanri.aiimage.modules.usersecret.service;
|
||||||
|
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||||
|
import com.nanri.aiimage.common.service.ReadScope;
|
||||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
import com.nanri.aiimage.modules.permission.support.UserDataScopeSupport;
|
import com.nanri.aiimage.modules.permission.support.UserDataScopeSupport;
|
||||||
@@ -9,6 +10,7 @@ import com.nanri.aiimage.modules.shopkey.model.dto.UserGroupRef;
|
|||||||
import com.nanri.aiimage.modules.usersecret.mapper.UserSecretUsageMapper;
|
import com.nanri.aiimage.modules.usersecret.mapper.UserSecretUsageMapper;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretUsageQuery;
|
import com.nanri.aiimage.modules.usersecret.model.dto.AdminUserSecretUsageQuery;
|
||||||
import com.nanri.aiimage.modules.usersecret.model.entity.UserSecretUsageEntity;
|
import com.nanri.aiimage.modules.usersecret.model.entity.UserSecretUsageEntity;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -114,7 +116,7 @@ class UserSecretUsageServiceTest {
|
|||||||
ref.setGroupName("一组");
|
ref.setGroupName("一组");
|
||||||
when(adminGroupMapper.selectGroupNamesByUserIds(any())).thenReturn(List.of(ref));
|
when(adminGroupMapper.selectGroupNamesByUserIds(any())).thenReturn(List.of(ref));
|
||||||
|
|
||||||
var page = service.adminPage(new AdminUserEntity(), new AdminUserSecretUsageQuery());
|
var page = service.adminPage(new AdminUserEntity(), new AdminUserSecretUsageQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getTotal()).isEqualTo(2);
|
assertThat(page.getTotal()).isEqualTo(2);
|
||||||
assertThat(page.getItems()).hasSize(2);
|
assertThat(page.getItems()).hasSize(2);
|
||||||
@@ -144,7 +146,7 @@ class UserSecretUsageServiceTest {
|
|||||||
when(userDataScopeSupport.resolveVisibleUserIds(88L)).thenReturn(List.of());
|
when(userDataScopeSupport.resolveVisibleUserIds(88L)).thenReturn(List.of());
|
||||||
when(adminGroupMapper.selectLedGroups(88L)).thenReturn(List.of());
|
when(adminGroupMapper.selectLedGroups(88L)).thenReturn(List.of());
|
||||||
|
|
||||||
var page = service.adminPage(operator, new AdminUserSecretUsageQuery());
|
var page = service.adminPage(operator, new AdminUserSecretUsageQuery(), ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).isEmpty();
|
assertThat(page.getItems()).isEmpty();
|
||||||
assertThat(page.getTotal()).isZero();
|
assertThat(page.getTotal()).isZero();
|
||||||
@@ -167,7 +169,7 @@ class UserSecretUsageServiceTest {
|
|||||||
|
|
||||||
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
||||||
query.setGroupId(5L);
|
query.setGroupId(5L);
|
||||||
var page = service.adminPage(new AdminUserEntity(), query);
|
var page = service.adminPage(new AdminUserEntity(), query, ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).hasSize(1);
|
assertThat(page.getItems()).hasSize(1);
|
||||||
assertThat(page.getItems().get(0).getProxyCount()).isEqualTo(3);
|
assertThat(page.getItems().get(0).getProxyCount()).isEqualTo(3);
|
||||||
@@ -186,9 +188,43 @@ class UserSecretUsageServiceTest {
|
|||||||
|
|
||||||
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
||||||
query.setKeyword("不存在的人");
|
query.setKeyword("不存在的人");
|
||||||
var page = service.adminPage(new AdminUserEntity(), query);
|
var page = service.adminPage(new AdminUserEntity(), query, ReadScope.unfiltered());
|
||||||
|
|
||||||
assertThat(page.getItems()).isEmpty();
|
assertThat(page.getItems()).isEmpty();
|
||||||
verify(usageMapper, never()).selectList(any());
|
verify(usageMapper, never()).selectList(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("用量统计:超管 group_id ∩ 公司成员集;交集为空时早退且不查库")
|
||||||
|
void groupAndCompanyIntersectThenEarlyReturn() {
|
||||||
|
UserSecretUsageService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(adminAuthSupport.currentRole(any())).thenReturn("super_admin");
|
||||||
|
when(adminGroupMapper.selectUserIdsByGroupId(7L)).thenReturn(List.of(12L, 13L, 99L));
|
||||||
|
assertThat(service.scopedUserIds(operator, 7L, ReadScope.users(List.of(11L, 12L, 13L))))
|
||||||
|
.containsExactlyInAnyOrder(12L, 13L);
|
||||||
|
|
||||||
|
when(adminGroupMapper.selectUserIdsByGroupId(7L)).thenReturn(List.of(99L));
|
||||||
|
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
||||||
|
query.setGroupId(7L);
|
||||||
|
var page = service.adminPage(operator, query, ReadScope.users(List.of(11L)));
|
||||||
|
|
||||||
|
assertThat(page.getItems()).isEmpty();
|
||||||
|
verify(usageMapper, never()).selectList(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("用量统计:主管只看自己带的分组成员,公司 tab 只能再收窄不能放大")
|
||||||
|
void leaderVisibleSetIsNarrowedByCompany() {
|
||||||
|
UserSecretUsageService service = newService();
|
||||||
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
|
operator.setId(88L);
|
||||||
|
when(userDataScopeSupport.resolveVisibleUserIds(88L)).thenReturn(List.of(1L, 2L, 88L));
|
||||||
|
assertThat(service.scopedUserIds(operator, null, ReadScope.users(List.of(2L))))
|
||||||
|
.containsExactly(2L);
|
||||||
|
assertThat(service.scopedUserIds(operator, null, ReadScope.unfiltered()))
|
||||||
|
.containsExactlyInAnyOrder(1L, 2L, 88L);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user