fix(角色叫法): 管理员就叫管理员、normal 档统一「普通账号」
同一角色此前有两套叫法:admin 档在界面叫「管理员」、在后端 6 条 403 与 Swagger 说明里叫 「普通管理员」;normal 档在界面叫「普通用户」。清到第四轮才清净,所以把口径做进源码出口: 新增 task-048 的旧词扫描用例,两棵源码树(admin-frontend-vue/src 216 文件、 backend-java/src 1415 java 文件)里出现「普通管理员」「普通用户」即红,分母与出口文件成员 一起钉死,防"扫了个空集合"式假绿。 - 后端 6 条用户可见文案:PermissionMenuService 两判、ShopManageGroupService 一判、 ShopManageController 三条 @Operation 说明 - company_menu_grant_gate_mutation.py 的 DENIED_THROW 锚同步改,16 条锚命中数逐条复算=1 - 注释与 javadoc 同批收口(等长替换不动排版);NotificationControllerTest 那句讲的是 非后台账号,按本意改写而不是套「普通账号」
This commit is contained in:
@@ -29,7 +29,7 @@ const errors = reactive<CreateUserFormErrors>({})
|
|||||||
const busy = ref(false)
|
const busy = ref(false)
|
||||||
|
|
||||||
/** 角色下拉:站点超管可选公司超管/管理员/普通账号;公司超管只可选管理员/普通账号;
|
/** 角色下拉:站点超管可选公司超管/管理员/普通账号;公司超管只可选管理员/普通账号;
|
||||||
* 普通管理员不显示角色选择(后端强制 normal)。 */
|
* 管理员不显示角色选择(后端强制 normal)。 */
|
||||||
const ROLE_CHOICES: Array<{ value: 'company_super_admin' | 'admin' | 'normal'; label: string }> = [
|
const ROLE_CHOICES: Array<{ value: 'company_super_admin' | 'admin' | 'normal'; label: string }> = [
|
||||||
{ value: 'company_super_admin', label: '公司超级管理员' },
|
{ value: 'company_super_admin', label: '公司超级管理员' },
|
||||||
{ value: 'admin', label: '管理员' },
|
{ value: 'admin', label: '管理员' },
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateReque
|
|||||||
if (originalRole === 'super_admin') {
|
if (originalRole === 'super_admin') {
|
||||||
throw new Error('不能修改超级管理员')
|
throw new Error('不能修改超级管理员')
|
||||||
}
|
}
|
||||||
// 公司超管目标不带 role:弹窗里的单选是给管理员/普通用户用的,带着它会整树提交把
|
// 公司超管目标不带 role:弹窗里的单选是给管理员/普通账号用的,带着它会整树提交把
|
||||||
// 公司超管静默降级。站点超管要调角色,请删号重建或走接口。
|
// 公司超管静默降级。站点超管要调角色,请删号重建或走接口。
|
||||||
const keepsRole = originalRole !== 'company_super_admin'
|
const keepsRole = originalRole !== 'company_super_admin'
|
||||||
const nextRole: EditUserRole = form.role === 'admin' ? 'admin' : 'normal'
|
const nextRole: EditUserRole = form.role === 'admin' ? 'admin' : 'normal'
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export async function fetchShopManageList(params: Partial<ShopManageListParams>
|
|||||||
|
|
||||||
export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
|
export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
|
||||||
|
|
||||||
/** 加载店铺分组下拉选项(超级管理员取全部,普通管理员由后端限定可访问分组)。 */
|
/** 加载店铺分组下拉选项(超级管理员取全部,管理员由后端限定可访问分组)。 */
|
||||||
/** 分组下拉:打的是与分组管理页同一个 GET /groups,所以它也必须跟着公司 tab 收窄,
|
/** 分组下拉:打的是与分组管理页同一个 GET /groups,所以它也必须跟着公司 tab 收窄,
|
||||||
* 否则店铺列表窄了、下拉里还选得到别家的组。 */
|
* 否则店铺列表窄了、下拉里还选得到别家的组。 */
|
||||||
export async function fetchShopManageGroups(companyId?: number | null): Promise<ShopGroupOption[]> {
|
export async function fetchShopManageGroups(companyId?: number | null): Promise<ShopGroupOption[]> {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const reanalyzing = ref(false)
|
|||||||
|
|
||||||
const filter = reactive({ asin: '', shop: '', group: '', country: '', dateFrom: '', dateTo: '' })
|
const filter = reactive({ asin: '', shop: '', group: '', country: '', dateFrom: '', dateTo: '' })
|
||||||
|
|
||||||
/** 角色范围:超管可看全部分组店铺并可跨分组筛选;普通管理员数据已由后端裁剪到自己分组,无需分组筛选。 */
|
/** 角色范围:超管可看全部分组店铺并可跨分组筛选;管理员数据已由后端裁剪到自己分组,无需分组筛选。 */
|
||||||
const session = useAdminSessionStore()
|
const session = useAdminSessionStore()
|
||||||
const isSuper = computed(() => session.isSuperAdmin)
|
const isSuper = computed(() => session.isSuperAdmin)
|
||||||
|
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ test('align_dup_console_role_scope_group_filter_only_super', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('align_dup_console_role_scope_group_controls_only_super', () => {
|
test('align_dup_console_role_scope_group_controls_only_super', () => {
|
||||||
// 分组撞款/分组说明为超管专属交互;后端超管全量、普通管理员所管分组店铺。
|
// 分组撞款/分组说明为超管专属交互;后端超管全量、管理员所管分组店铺。
|
||||||
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
||||||
assert.match(page, /<div v-if="isSuper" class="scope-bar">/, '分组撞款分段仅超管可见')
|
assert.match(page, /<div v-if="isSuper" class="scope-bar">/, '分组撞款分段仅超管可见')
|
||||||
assert.match(page, /v-if="isSuper" class="btn btn-ghost btn-sm" type="button" @click="groupInfoVisible = true"/, '分组说明按钮仅超管可见')
|
assert.match(page, /v-if="isSuper" class="btn btn-ghost btn-sm" type="button" @click="groupInfoVisible = true"/, '分组说明按钮仅超管可见')
|
||||||
const service = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/shopduplicatecheck/service/ShopDataDuplicateCheckQueryService.java')
|
const service = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/shopduplicatecheck/service/ShopDataDuplicateCheckQueryService.java')
|
||||||
assert.match(service, /if \(superAdmin\) \{\s*return null;/, '超管可见范围=全量(null)')
|
assert.match(service, /if \(superAdmin\) \{\s*return null;/, '超管可见范围=全量(null)')
|
||||||
assert.match(service, /selectManagedShopNames\(operatorId\)/, '普通管理员可见范围=所管分组店铺')
|
assert.match(service, /selectManagedShopNames\(operatorId\)/, '管理员可见范围=所管分组店铺')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('align_dup_console_country_labels_chinese', () => {
|
test('align_dup_console_country_labels_chinese', () => {
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import {
|
|||||||
parsePermissionMenuItem,
|
parsePermissionMenuItem,
|
||||||
} from '../src/pages/account/user-menu-auth.ts'
|
} from '../src/pages/account/user-menu-auth.ts'
|
||||||
|
|
||||||
// 2026-09-16 线上事故:非超管(普通管理员)在授权树里勾到自己无权授予的菜单后,
|
// 2026-09-16 线上事故:非超管(管理员)在授权树里勾到自己无权授予的菜单后,
|
||||||
// 后端 ensureGrantable 抛 403 并回滚整笔事务——创建用户与保存权限双双失败,
|
// 后端 ensureGrantable 抛 403 并回滚整笔事务——创建用户与保存权限双双失败,
|
||||||
// 前端只显示「普通管理员只能分配自己已有的菜单权限」。
|
// 前端只显示「管理员只能分配自己已有的菜单权限」。
|
||||||
//
|
//
|
||||||
// 现在的口径:非超管的授权树**只下发**自己已持有的菜单(读接口按操作者过滤),
|
// 现在的口径:非超管的授权树**只下发**自己已持有的菜单(读接口按操作者过滤),
|
||||||
// 范围外的项连展示都没有。为保留「一级分组 + 子页面」层级,可授予项的祖先分组仍
|
// 范围外的项连展示都没有。为保留「一级分组 + 子页面」层级,可授予项的祖先分组仍
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import test from 'node:test'
|
import test from 'node:test'
|
||||||
import assert from 'node:assert/strict'
|
import assert from 'node:assert/strict'
|
||||||
|
import { readdirSync } from 'node:fs'
|
||||||
|
import { join } from 'node:path'
|
||||||
import { readSource } from './helpers.ts'
|
import { readSource } from './helpers.ts'
|
||||||
import {
|
import {
|
||||||
roleDomainOf,
|
roleDomainOf,
|
||||||
@@ -88,3 +90,72 @@ test('test_task_048_normal_role_wording_agrees_across_all_exits', () => {
|
|||||||
)
|
)
|
||||||
assert.deepEqual(buttons, [['normal', word], ['admin', '管理员']], '编辑用户弹窗的角色按钮文案')
|
assert.deepEqual(buttons, [['normal', word], ['admin', '管理员']], '编辑用户弹窗的角色按钮文案')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2026-10-05 定稿:admin 档只叫「管理员」,normal 档只叫「普通账号」。
|
||||||
|
* 旧叫法「普通管理员」「普通用户」当天清了三轮才清干净(列表列、下拉、角色域、弹窗按钮四份出口
|
||||||
|
* 各写一套,后端还留着 6 条 403 与 Swagger 说明),所以钉成尺子而不是记在脑子里。
|
||||||
|
* 判据只扫两棵源码树的源码扩展名:`.playwright-cli/*.yml` 那批 09-12 的页面快照里印着旧词,
|
||||||
|
* 那是历史证据不是口径;`tests/` 也不扫——本文件的禁用清单自己就要写这两个词。
|
||||||
|
*/
|
||||||
|
const RETIRED_ROLE_WORDS = ['普通管理员', '普通用户'] as const
|
||||||
|
|
||||||
|
/** 扫描面。minFiles 是 2026-10-05 实测分母(216 / 1415)的下限,mustInclude 钉"该扫到的文件真在集合里"。 */
|
||||||
|
const ROLE_WORD_SCOPE: ReadonlyArray<{
|
||||||
|
readonly dir: string
|
||||||
|
readonly exts: readonly string[]
|
||||||
|
readonly minFiles: number
|
||||||
|
readonly mustInclude: readonly string[]
|
||||||
|
}> = [
|
||||||
|
{
|
||||||
|
dir: 'src',
|
||||||
|
exts: ['.ts', '.tsx', '.vue', '.js'],
|
||||||
|
minFiles: 200,
|
||||||
|
mustInclude: ['src/types/admin.ts', 'src/pages/account/user-role-map.ts', 'src/pages/account/EditUserDialog.vue'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dir: '../backend-java/src',
|
||||||
|
exts: ['.java'],
|
||||||
|
minFiles: 1300,
|
||||||
|
mustInclude: [
|
||||||
|
'../backend-java/src/main/java/com/nanri/aiimage/modules/permission/service/PermissionMenuService.java',
|
||||||
|
'../backend-java/src/main/java/com/nanri/aiimage/modules/admin/service/AdminUserService.java',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function walkSourceFiles(dir: string, exts: readonly string[], out: string[] = []): string[] {
|
||||||
|
for (const entry of readdirSync(join(process.cwd(), dir), { withFileTypes: true })) {
|
||||||
|
const rel = `${dir}/${entry.name}`
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name.startsWith('.')) continue
|
||||||
|
walkSourceFiles(rel, exts, out)
|
||||||
|
} else if (exts.some((ext) => entry.name.endsWith(ext))) {
|
||||||
|
out.push(rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
test('test_task_048_retired_role_words_are_gone_from_source_trees', () => {
|
||||||
|
const problems: string[] = []
|
||||||
|
for (const scope of ROLE_WORD_SCOPE) {
|
||||||
|
const files = walkSourceFiles(scope.dir, scope.exts)
|
||||||
|
assert.ok(
|
||||||
|
files.length >= scope.minFiles,
|
||||||
|
`${scope.dir} 只扫到 ${files.length} 个文件(下限 ${scope.minFiles}):目录或扩展名写错了,这条尺子没在判任何东西`,
|
||||||
|
)
|
||||||
|
for (const needle of scope.mustInclude) {
|
||||||
|
assert.ok(files.includes(needle), `${scope.dir} 的扫描集合里没有 ${needle},取样面漏了出口文件`)
|
||||||
|
}
|
||||||
|
for (const rel of files) {
|
||||||
|
const lines = readSource(rel).split('\n')
|
||||||
|
lines.forEach((line, index) => {
|
||||||
|
for (const word of RETIRED_ROLE_WORDS) {
|
||||||
|
if (line.includes(word)) problems.push(`${rel}:${index + 1} 出现旧叫法「${word}」→ ${line.trim().slice(0, 60)}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.deepEqual(problems, [], '角色旧叫法回流:' + problems.join(' | '))
|
||||||
|
})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ SUPER_EARLY_RETURN = (
|
|||||||
" }")
|
" }")
|
||||||
DENIED_THROW = (
|
DENIED_THROW = (
|
||||||
" if (!denied.isEmpty()) {\n"
|
" if (!denied.isEmpty()) {\n"
|
||||||
" throw new BusinessException(403, \"普通管理员只能分配自己已有的菜单权限\");\n"
|
" throw new BusinessException(403, \"管理员只能分配自己已有的菜单权限\");\n"
|
||||||
" }")
|
" }")
|
||||||
STRIP_CALL = " requestedIds = stripSuperAdminOnlyGrantIds(requestedIds, operator);"
|
STRIP_CALL = " requestedIds = stripSuperAdminOnlyGrantIds(requestedIds, operator);"
|
||||||
MARKER_LOG = (" log.warn(\"GRANT_SUPER_ADMIN_ONLY_STRIPPED 已剥离超管专属菜单授权 ids={} operatorId={}\", stripped,")
|
MARKER_LOG = (" log.warn(\"GRANT_SUPER_ADMIN_ONLY_STRIPPED 已剥离超管专属菜单授权 ids={} operatorId={}\", stripped,")
|
||||||
|
|||||||
+3
-3
@@ -19,9 +19,9 @@ import java.util.List;
|
|||||||
* <p><b>判定口径(库里不改值,全部现算):</b>生效到期 = 自身 expires_at 与所有上级约束里最早的那个。</p>
|
* <p><b>判定口径(库里不改值,全部现算):</b>生效到期 = 自身 expires_at 与所有上级约束里最早的那个。</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>super_admin:永不适用(返回 null);</li>
|
* <li>super_admin:永不适用(返回 null);</li>
|
||||||
* <li>公司级:本公司所有 company_super_admin 的 expires_at 约束全公司(管理员/普通用户跟随);
|
* <li>公司级:本公司所有 company_super_admin 的 expires_at 约束全公司(管理员/普通账号跟随);
|
||||||
* 公司没有公司超管时无此约束(站点自己的公司通常如此);</li>
|
* 公司没有公司超管时无此约束(站点自己的公司通常如此);</li>
|
||||||
* <li>组级:普通用户受两条链约束——所属分组组长(成员表)与创建人(管理员),
|
* <li>组级:普通账号受两条链约束——所属分组组长(成员表)与创建人(管理员),
|
||||||
* 与数据可见范围的派生口径一致(成员表基本未用、按创建人派生);</li>
|
* 与数据可见范围的派生口径一致(成员表基本未用、按创建人派生);</li>
|
||||||
* <li>管理员(admin):自身 + 公司级。</li>
|
* <li>管理员(admin):自身 + 公司级。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
@@ -101,7 +101,7 @@ public class AccountExpiryService {
|
|||||||
LocalDateTime effective = ownExpiresAt;
|
LocalDateTime effective = ownExpiresAt;
|
||||||
effective = min(effective, companyCascadeExpiresAt(companyId));
|
effective = min(effective, companyCascadeExpiresAt(companyId));
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
// 普通用户:组级约束(组长 + 创建人)。管理员不级联到组长(上级是公司超管/超管,走公司级)。
|
// 普通账号:组级约束(组长 + 创建人)。管理员不级联到组长(上级是公司超管/超管,走公司级)。
|
||||||
effective = min(effective, leaderCascadeExpiresAt(userId));
|
effective = min(effective, leaderCascadeExpiresAt(userId));
|
||||||
effective = min(effective, creatorCascadeExpiresAt(createdById));
|
effective = min(effective, creatorCascadeExpiresAt(createdById));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -360,7 +360,7 @@ public class AdminUserService {
|
|||||||
throw new BusinessException("不能修改超级管理员");
|
throw new BusinessException("不能修改超级管理员");
|
||||||
}
|
}
|
||||||
if ("company_super_admin".equals(role)) {
|
if ("company_super_admin".equals(role)) {
|
||||||
// 公司超管只能编辑本公司管理员/普通用户;同公司的公司超管与站点超管都碰不得
|
// 公司超管只能编辑本公司管理员/普通账号;同公司的公司超管与站点超管都碰不得
|
||||||
if ("company_super_admin".equals(targetRole)) {
|
if ("company_super_admin".equals(targetRole)) {
|
||||||
throw new BusinessException(403, "只有超级管理员可以修改公司超级管理员");
|
throw new BusinessException(403, "只有超级管理员可以修改公司超级管理员");
|
||||||
}
|
}
|
||||||
@@ -500,7 +500,7 @@ public class AdminUserService {
|
|||||||
throw new BusinessException(403, "只能删除自己创建的普通账号");
|
throw new BusinessException(403, "只能删除自己创建的普通账号");
|
||||||
}
|
}
|
||||||
} else if ("company_super_admin".equals(role)) {
|
} else if ("company_super_admin".equals(role)) {
|
||||||
// 公司超管可清退本公司的管理员/普通用户;公司超管之间互删与站点超管一样被拒
|
// 公司超管可清退本公司的管理员/普通账号;公司超管之间互删与站点超管一样被拒
|
||||||
if ("company_super_admin".equals(targetRole)) {
|
if ("company_super_admin".equals(targetRole)) {
|
||||||
throw new BusinessException(403, "只有超级管理员可以删除公司超级管理员");
|
throw new BusinessException(403, "只有超级管理员可以删除公司超级管理员");
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -92,7 +92,7 @@ public class PermissionMenuService {
|
|||||||
}
|
}
|
||||||
// 出口 1(授权树):可授予集合里连超管都不含这些项——超管自己都拿不到,才授不出去。
|
// 出口 1(授权树):可授予集合里连超管都不含这些项——超管自己都拿不到,才授不出去。
|
||||||
// 必须挂在 grantableOnly 上而不是 grantableIds != null 上:resolveGrantableMenuIds 对超管
|
// 必须挂在 grantableOnly 上而不是 grantableIds != null 上:resolveGrantableMenuIds 对超管
|
||||||
// 返回 null(不限制),挂错了条件就等于只挡住了普通管理员,旁路照旧。
|
// 返回 null(不限制),挂错了条件就等于只挡住了管理员,旁路照旧。
|
||||||
// 这里是重新赋值 visibleMenus,绝不能改 menus——它是 toItemVos 的层级/父节点查找表。
|
// 这里是重新赋值 visibleMenus,绝不能改 menus——它是 toItemVos 的层级/父节点查找表。
|
||||||
if (grantableOnly) {
|
if (grantableOnly) {
|
||||||
visibleMenus = visibleMenus.stream()
|
visibleMenus = visibleMenus.stream()
|
||||||
@@ -707,7 +707,7 @@ public class PermissionMenuService {
|
|||||||
* 镜像 V84 惯例(已获「店铺数据任务管理」菜单的用户自动获得初始数据查看授权):
|
* 镜像 V84 惯例(已获「店铺数据任务管理」菜单的用户自动获得初始数据查看授权):
|
||||||
* admin 分区授权更新后,若**有效授权**包含店铺数据相关菜单(任务管理/重复检查,
|
* admin 分区授权更新后,若**有效授权**包含店铺数据相关菜单(任务管理/重复检查,
|
||||||
* 含经一级分组「店铺管理」展开覆盖的情形),自动补上内部数据权限
|
* 含经一级分组「店铺管理」展开覆盖的情形),自动补上内部数据权限
|
||||||
* admin_shop_data_crawl_task_data,避免普通管理员已勾了菜单仍提示
|
* admin_shop_data_crawl_task_data,避免管理员已勾了菜单仍提示
|
||||||
* “无权查看店铺数据任务”。
|
* “无权查看店铺数据任务”。
|
||||||
* 只增不删:数据授权的回收仍走超管专用的「数据范围授权」UI。
|
* 只增不删:数据授权的回收仍走超管专用的「数据范围授权」UI。
|
||||||
*/
|
*/
|
||||||
@@ -744,7 +744,7 @@ public class PermissionMenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除普通管理员直接创建的员工中,超出该管理员当前有效权限范围的授权。
|
* 删除管理员直接创建的员工中,超出该管理员当前有效权限范围的授权。
|
||||||
* 只清理越权项,保留员工合法持有的其他授权。超级管理员无此限制。
|
* 只清理越权项,保留员工合法持有的其他授权。超级管理员无此限制。
|
||||||
*
|
*
|
||||||
* <p>有效集按目标的<b>完整</b>直接授权(读库,含 admin/app 全类型)计算:
|
* <p>有效集按目标的<b>完整</b>直接授权(读库,含 admin/app 全类型)计算:
|
||||||
@@ -945,7 +945,7 @@ public class PermissionMenuService {
|
|||||||
throw new BusinessException(403, "需要管理员权限");
|
throw new BusinessException(403, "需要管理员权限");
|
||||||
}
|
}
|
||||||
if ("company_super_admin".equals(normalizeRole(operator.getRole()))) {
|
if ("company_super_admin".equals(normalizeRole(operator.getRole()))) {
|
||||||
// 公司超管:本公司管理员/普通用户都可授;同公司的公司超管与站点超管碰不得
|
// 公司超管:本公司管理员/普通账号都可授;同公司的公司超管与站点超管碰不得
|
||||||
String targetRole = normalizeRole(target.getRole());
|
String targetRole = normalizeRole(target.getRole());
|
||||||
if ("company_super_admin".equals(targetRole) || "super_admin".equals(targetRole)) {
|
if ("company_super_admin".equals(targetRole) || "super_admin".equals(targetRole)) {
|
||||||
throw new BusinessException(403, "只有超级管理员可以修改公司超级管理员");
|
throw new BusinessException(403, "只有超级管理员可以修改公司超级管理员");
|
||||||
@@ -960,14 +960,14 @@ public class PermissionMenuService {
|
|||||||
&& operator.getId() != null
|
&& operator.getId() != null
|
||||||
&& operator.getId().equals(target.getCreatedById());
|
&& operator.getId().equals(target.getCreatedById());
|
||||||
if (!ownedNormal) {
|
if (!ownedNormal) {
|
||||||
throw new BusinessException(403, "普通管理员只能管理自己创建的普通账号");
|
throw new BusinessException(403, "管理员只能管理自己创建的普通账号");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws 403 when a non-super admin **新增** grants outside their own effective set.
|
* Throws 403 when a non-super admin **新增** grants outside their own effective set.
|
||||||
*
|
*
|
||||||
* <p>目标用户已持有的直接授权不参与校验:那是既有事实(通常由超管分配),普通管理员
|
* <p>目标用户已持有的直接授权不参与校验:那是既有事实(通常由超管分配),管理员
|
||||||
* 编辑该用户时整树提交会把它原样带回,若一并判为越权,整笔事务会回滚——连建号、改密
|
* 编辑该用户时整树提交会把它原样带回,若一并判为越权,整笔事务会回滚——连建号、改密
|
||||||
* 都做不成(生产 2026-09-16 现象:勾到一个越权项,创建用户与保存权限双双失败)。
|
* 都做不成(生产 2026-09-16 现象:勾到一个越权项,创建用户与保存权限双双失败)。
|
||||||
* 只放行「保留已有」不放行「新增」,因此不构成提权。
|
* 只放行「保留已有」不放行「新增」,因此不构成提权。
|
||||||
@@ -989,7 +989,7 @@ public class PermissionMenuService {
|
|||||||
.filter(id -> !effective.contains(id))
|
.filter(id -> !effective.contains(id))
|
||||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
if (!denied.isEmpty()) {
|
if (!denied.isEmpty()) {
|
||||||
throw new BusinessException(403, "普通管理员只能分配自己已有的菜单权限");
|
throw new BusinessException(403, "管理员只能分配自己已有的菜单权限");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1042,7 +1042,7 @@ public class PermissionMenuService {
|
|||||||
}
|
}
|
||||||
String role = normalizeRole(user.getRole());
|
String role = normalizeRole(user.getRole());
|
||||||
if (!role.isEmpty()) {
|
if (!role.isEmpty()) {
|
||||||
// company_super_admin 也是授权链上的一级主管(可给本公司的管理员/普通用户授权)
|
// company_super_admin 也是授权链上的一级主管(可给本公司的管理员/普通账号授权)
|
||||||
return "super_admin".equals(role) || "admin".equals(role) || "company_super_admin".equals(role);
|
return "super_admin".equals(role) || "admin".equals(role) || "company_super_admin".equals(role);
|
||||||
}
|
}
|
||||||
return Integer.valueOf(1).equals(user.getIsAdmin());
|
return Integer.valueOf(1).equals(user.getIsAdmin());
|
||||||
|
|||||||
+3
-3
@@ -117,7 +117,7 @@ public class ShopManageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/groups")
|
@GetMapping("/groups")
|
||||||
@Operation(summary = "查询分组列表", description = "普通管理员返回当前可访问的分组,超级管理员返回全部;"
|
@Operation(summary = "查询分组列表", description = "管理员返回当前可访问的分组,超级管理员返回全部;"
|
||||||
+ "company_id 只收窄可见集、不放大,跨公司查看仅超管")
|
+ "company_id 只收窄可见集、不放大,跨公司查看仅超管")
|
||||||
public ApiResponse<java.util.List<ShopManageGroupItemVo>> listGroups(
|
public ApiResponse<java.util.List<ShopManageGroupItemVo>> listGroups(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@@ -143,7 +143,7 @@ public class ShopManageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/groups/{id}")
|
@PutMapping("/groups/{id}")
|
||||||
@Operation(summary = "更新分组", description = "普通管理员只能修改自己可访问的分组")
|
@Operation(summary = "更新分组", description = "管理员只能修改自己可访问的分组")
|
||||||
public ApiResponse<ShopManageGroupItemVo> updateGroup(
|
public ApiResponse<ShopManageGroupItemVo> updateGroup(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@Parameter(description = "主键 ID", required = true) @PathVariable Long id,
|
@Parameter(description = "主键 ID", required = true) @PathVariable Long id,
|
||||||
@@ -154,7 +154,7 @@ public class ShopManageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/groups/{id}")
|
@DeleteMapping("/groups/{id}")
|
||||||
@Operation(summary = "删除分组", description = "普通管理员只能删除自己可访问的分组")
|
@Operation(summary = "删除分组", description = "管理员只能删除自己可访问的分组")
|
||||||
public ApiResponse<Void> deleteGroup(
|
public ApiResponse<Void> deleteGroup(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@Parameter(description = "主键 ID", required = true) @PathVariable Long id) {
|
@Parameter(description = "主键 ID", required = true) @PathVariable Long id) {
|
||||||
|
|||||||
+1
-1
@@ -245,7 +245,7 @@ public class ShopManageGroupService {
|
|||||||
}
|
}
|
||||||
Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空");
|
Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空");
|
||||||
if (!normalizedOperatorId.equals(leaderId)) {
|
if (!normalizedOperatorId.equals(leaderId)) {
|
||||||
throw new BusinessException("普通管理员只能创建自己作为组长的分组");
|
throw new BusinessException("管理员只能创建自己作为组长的分组");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ public class ExpiredAccountTaskStopService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期账号 → 需要连带停任务的成员集合。与登录侧级联判定同口径:
|
* 过期账号 → 需要连带停任务的成员集合。与登录侧级联判定同口径:
|
||||||
* 公司超管过期圈全公司;管理员过期圈名下子账户 + 所带分组的成员表成员;普通用户只有自己。
|
* 公司超管过期圈全公司;管理员过期圈名下子账户 + 所带分组的成员表成员;普通账号只有自己。
|
||||||
*/
|
*/
|
||||||
private Set<Long> resolveAffectedUserIds(List<AdminUserEntity> boundary) {
|
private Set<Long> resolveAffectedUserIds(List<AdminUserEntity> boundary) {
|
||||||
LinkedHashSet<Long> affected = new LinkedHashSet<>();
|
LinkedHashSet<Long> affected = new LinkedHashSet<>();
|
||||||
|
|||||||
+5
-5
@@ -25,8 +25,8 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 到期级联判定(V146)口径钉:
|
* 到期级联判定(V146)口径钉:
|
||||||
* super_admin 永不适用;公司超管到期 → 全公司跟随;管理员到期 → 创建人链上的普通用户跟随;
|
* super_admin 永不适用;公司超管到期 → 全公司跟随;管理员到期 → 创建人链上的普通账号跟随;
|
||||||
* 普通用户同时受自身/创建人/组长/公司超管四条约束取最早;库里不改值,全部现算。
|
* 普通账号同时受自身/创建人/组长/公司超管四条约束取最早;库里不改值,全部现算。
|
||||||
*/
|
*/
|
||||||
class AccountExpiryServiceTest {
|
class AccountExpiryServiceTest {
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ class AccountExpiryServiceTest {
|
|||||||
csa.setExpiresAt(companyExpiry);
|
csa.setExpiresAt(companyExpiry);
|
||||||
when(adminUserMapper.selectList(any())).thenReturn(List.of(csa));
|
when(adminUserMapper.selectList(any())).thenReturn(List.of(csa));
|
||||||
|
|
||||||
// 普通用户(自身无到期)被公司超管的到期拉进去
|
// 普通账号(自身无到期)被公司超管的到期拉进去
|
||||||
assertThat(service.effectiveExpiresAt(entity(3L, "normal", null, 1L, null))).isEqualTo(companyExpiry);
|
assertThat(service.effectiveExpiresAt(entity(3L, "normal", null, 1L, null))).isEqualTo(companyExpiry);
|
||||||
// 管理员同样被拉进去
|
// 管理员同样被拉进去
|
||||||
assertThat(service.effectiveExpiresAt(entity(2L, "admin", null, 1L, null))).isEqualTo(companyExpiry);
|
assertThat(service.effectiveExpiresAt(entity(2L, "admin", null, 1L, null))).isEqualTo(companyExpiry);
|
||||||
@@ -106,7 +106,7 @@ class AccountExpiryServiceTest {
|
|||||||
assertThat(service.effectiveExpiresAt(entity(3L, "normal", null, 1L, own))).isEqualTo(company);
|
assertThat(service.effectiveExpiresAt(entity(3L, "normal", null, 1L, own))).isEqualTo(company);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 组级联:管理员到期 → 名下/组内普通用户 ----------
|
// ---------- 组级联:管理员到期 → 名下/组内普通账号 ----------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void expiredCreatorAdminCascadesToNormalUser() {
|
void expiredCreatorAdminCascadesToNormalUser() {
|
||||||
@@ -135,7 +135,7 @@ class AccountExpiryServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void normalUserIsNotCascadedByNormalCreator() {
|
void normalUserIsNotCascadedByNormalCreator() {
|
||||||
// 创建人自己是普通用户(历史脏数据):不构成组级约束
|
// 创建人自己是普通账号(历史脏数据):不构成组级约束
|
||||||
AdminUserEntity creator = new AdminUserEntity();
|
AdminUserEntity creator = new AdminUserEntity();
|
||||||
creator.setId(8L);
|
creator.setId(8L);
|
||||||
creator.setRole("normal");
|
creator.setRole("normal");
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 桌面端通知可见范围回归:接收者只能来自 JWT 解析出的本人,
|
* 桌面端通知可见范围回归:接收者只能来自 JWT 解析出的本人,
|
||||||
* 且一律按 audience=user 读写 —— 普通用户只能看到自己的通知,读不到后台管理员通知。
|
* 且一律按 audience=user 读写 —— 非后台账号只能看到自己的通知,读不到后台管理员通知。
|
||||||
*/
|
*/
|
||||||
class NotificationControllerTest {
|
class NotificationControllerTest {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ class Task142Test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_task_142_define_menu_typeadmin_dependency_failure_returns_actionable_message() {
|
void test_task_142_define_menu_typeadmin_dependency_failure_returns_actionable_message() {
|
||||||
// 保留 admin 域;普通用户经有效权限输入再过滤,Controller 不复算授权。
|
// 保留 admin 域;普通账号经有效权限输入再过滤,Controller 不复算授权。
|
||||||
assertEquals("admin", AdminMenuTreeBuilder.filterByMenuType(List.of(item(1L, "a", "admin")), "admin").get(0).getMenuType());
|
assertEquals("admin", AdminMenuTreeBuilder.filterByMenuType(List.of(item(1L, "a", "admin")), "admin").get(0).getMenuType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user