feat(jd): 京东数据库写权限放宽到管理员级+分组筛选收超管档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」「超管可以有分组筛选,管理员及以下则没有」)——后端 requirePlatformSuperAdminWrite 改 requireJdProductWrite:平台超管/公司超管/admin 三档放行、普通账号(resolveRole=null)403「仅超级管理员或管理员可以编辑或删除京东数据库数据」(四条商品行写路由同闸;批量归类 V203 requireWritableGroup 不动);前端 canWriteProducts(isAdminRole)管操作列/批量删除/勾选列/只读提示,canFilterGroup(平台+公司超管)管筛选行「分组」控件整块显隐(管理员及以下连单组锁定芯片都不渲染,分类面静默落默认组)。判据:后端 29 例(普通账号四写 403 不触服务+admin 四写放行+公司超管放行+结构钉三档谓词与 403 文案);前端挂载 42 例(普通员工 5 列只读+无分组控件、admin 7 列全写+多组也无下拉、公司超管齐写+多组可切组、超管照旧);vue-tsc rc=0;ops fast 闸门 overall=pass

This commit is contained in:
2026-11-17 22:42:15 +08:00
parent 8b0cde4a51
commit 0c4354fc1e
4 changed files with 226 additions and 78 deletions
@@ -31,12 +31,19 @@ import { openAdminConfirm } from '@/components/admin-confirm'
import { loadFailureMessage } from '@/components/load-failure-model'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
import { isAdminRole, isCompanySuperAdminRole } from '@/types/admin'
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 写权限口径(2026-11-16 用户口径):商品行写(编辑/删除/勾选批量删)只对平台超级管理员渲染;
* 分类写(建/改名/删除、归类)由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管)。 */
/** 写权限口径(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」):
* 商品行写(编辑/删除/批量删除/传图)对管理员级(超级管理员/公司超级管理员/admin 档)渲染,
* 普通账号只读(后端 requireJdProductWrite 同口径兜底);分类写(建/改名/删除、归类)
* 由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管),与本档无关。 */
const session = useAdminSessionStore()
const isSuperAdmin = computed(() => session.isSuperAdmin)
const canWriteProducts = computed(() => isAdminRole(session.user?.role))
/** 分组筛选(同日用户口径「超管可以有分组筛选,管理员及以下则没有」):筛选行「分组」控件
* (下拉+单组锁定芯片)只对超管档(超级管理员/公司超级管理员)渲染;管理员及以下
* 不出现,其分类面固定落在作用域默认分组上。 */
const canFilterGroup = computed(() => session.isSuperAdmin || isCompanySuperAdminRole(session.user?.role))
const loading = ref(false)
const loadFailure = ref('')
@@ -75,12 +82,12 @@ const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
const currentGroupName = computed(() => currentGroupOption.value?.name || '')
/** 分类可管理(建/改名/删除/归类):本组管理员、公司超管、平台超管(后端 scope 判)。 */
const canManageCategories = computed(() => currentGroupOption.value?.editable === true)
/** 勾选列服务两类写:批量删除(只超管)+批量编辑分类(本组可写分类的管理员也要勾)。
/** 勾选列服务两类写:批量删除(管理员级)+批量编辑分类(本组可写分类的管理员也要勾)。
* 2026-11-17 弹窗下线后管理员失去弹窗右栏的勾选面 ⇒ 勾选列必须对「本组可写」放开,
* 否则本组管理员没有归类入口。商品行按钮(编辑/删除/批量删除)仍只归平台超管。 */
const hasSelectionColumn = computed(() => isSuperAdmin.value || canManageCategories.value)
/** 空态行 colspan:勾选列有无决定 5/6/7 列三种形状(超管含操作列)。 */
const emptyColspan = computed(() => (isSuperAdmin.value ? 7 : hasSelectionColumn.value ? 6 : 5))
* 否则本组管理员没有归类入口。 */
const hasSelectionColumn = computed(() => canWriteProducts.value || canManageCategories.value)
/** 空态行 colspan:勾选列有无决定 5/6/7 列三种形状(管理员级含操作列)。 */
const emptyColspan = computed(() => (canWriteProducts.value ? 7 : hasSelectionColumn.value ? 6 : 5))
/** 分组下拉只在能看多组时才渲染;只有一组(含无可见组)时按锁定态展示。 */
const canSwitchGroup = computed(() => categoryScope.value.length > 1)
@@ -370,9 +377,11 @@ onMounted(async () => {
@change="onCategoryPicked"
/>
</div>
<div v-if="categoryScope.length" class="form-group">
<div v-if="canFilterGroup && categoryScope.length" class="form-group">
<label>分组</label>
<!-- 当前分组(V203):能看多组的人(平台超管/公司超管)下拉切换;只有一组时锁定显示组名。
<!-- 当前分组(V203):超管档(平台/公司超管)专属——2026-11-17 用户口径
「超管可以有分组筛选,管理员及以下则没有」,本控件对管理员及以下整块不渲染
(其分类面固定落在作用域默认分组)。能看多组的人下拉切换;只有一组时锁定显示组名。
2026-11-16 用户口径「做成分组」:从工具栏裸下拉上移进筛选行,做成带标签的表单控件
(与其他筛选同壳同圆角)。2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的
弹层是浏览器直角原生物,换 el-select(同亚马逊面 admin-filter 同壳),组多时可搜索。
@@ -415,9 +424,10 @@ onMounted(async () => {
:disabled="!selectedCount"
@click="openBatchEdit"
>批量编辑分类</button>
<!-- 商品行写只对平台超管;分类写由当前分组 editable 决定(本组管理员/公司超管/平台超管)。
非超管看到只读提示,分类维护入口=「分类管理」(只读可看,写控件按 editable 分档)。 -->
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类在本页「分类管理」查看与维护</span>
<!-- 商品行写对管理员级(超管+管理员)开放,普通账号看到只读提示;分类写由当前分组
editable 决定(本组管理员/公司超管/平台超管),分类维护入口=「分类管理」
(只读可看,写控件按 editable 分档)。 -->
<span v-if="!canWriteProducts" class="jd-readonly-tip">只读:编辑/删除需超级管理员或管理员;分类在本页「分类管理」查看与维护</span>
<!-- 分类筛选(2026-11-17 与分组同刀换 el-select,弹层圆角与亚马逊统一):保留显式
「全部分类」行(value='',与旧原生下拉同语义——列表里永远有回全量的出口),
选中它/重置回 '' 时闭壳显示同文案占位。 -->
@@ -454,10 +464,10 @@ onMounted(async () => {
@click="openManage"
>分类管理</button>
<!-- 批量删除 2026-11-16 客户口径「不要勾选后才显示」:常显,勾选 0 时置灰。
同日写权限收窄到超管:非超管整颗按钮不渲染(勾选列 2026-11-17 起对本组可写
分类管理员开放,服务批量归类)。文案 2026-11-17 用户口径「删除勾选改成批量删除」。 -->
写权限 2026-11-17 口径放宽到管理员级:普通账号整颗按钮不渲染(勾选列 2026-11-17
起对本组可写分类管理员开放,服务批量归类)。文案 2026-11-17 用户口径「删除勾选改成批量删除」。 -->
<button
v-if="isSuperAdmin"
v-if="canWriteProducts"
class="btn btn-danger jd-delete-btn"
type="button"
:disabled="deleting || !selectedCount"
@@ -478,9 +488,10 @@ onMounted(async () => {
<th style="width: 76px">总库存</th>
<th style="width: 120px">价格</th>
<!-- 同步时间收尾(创建/修改两列 2026-11-16 客户口径「不要」下线,仍收详情抽屉);
操作列 2026-11-16「操作放最后一列」口径置末;同日写权限收窄到超管 ⇒ 非超管不渲染。 -->
操作列 2026-11-16「操作放最后一列」口径置末;写权限 2026-11-17 放宽到
管理员级 ⇒ 普通账号不渲染该列。 -->
<th style="width: 170px">同步时间</th>
<th v-if="isSuperAdmin" style="width: 138px">操作</th>
<th v-if="canWriteProducts" style="width: 138px">操作</th>
</tr>
</thead>
<tbody>
@@ -515,8 +526,8 @@ onMounted(async () => {
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
<!-- 操作列(2026-11-15 用户口径):编辑/删除;@click.stop 防冒泡开详情抽屉。
2026-11-16「操作放最后一列」口径置末;「上架时间 / 商品状态」列同日整列下线;
同日写权限收窄到超管 ⇒ 非超管不渲染该列。 -->
<td v-if="isSuperAdmin" class="jd-ops-cell" @click.stop>
写权限 2026-11-17 口径放宽到管理员级 ⇒ 普通账号不渲染该列。 -->
<td v-if="canWriteProducts" class="jd-ops-cell" @click.stop>
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="deleting" @click="removeOne(row)">删除</button>
</td>
@@ -867,15 +867,15 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
})
})
/** 写权限分档(2026-11-16 用户口径收窄商品行写;2026-11-17 弹窗下线后更新):
* 商品行写(编辑/删除/勾选批量删)只对平台超管渲染;分类写(批量编辑分类、分类管理)由
* scope 的每组 editable 决定(本组管理员/公司超管/平台超管)——同组普通号在本页只读,
* 分类维护入口=工具栏「分类管理」对话框(V204 独立页 2026-11-17 并入,只读可看)。
* 勾选列 2026-11-17 起对本组可写分类管理员开放(服务批量归类),商品行按钮仍只归平台超管。 */
describe('京东数据库写权限分档(商品行写=平台超管;分类写=本组 editable)', () => {
it('非超管且本组不可写:无勾选列、无操作列、无批量删除、无批量编辑分类;列表/筛选/详情照常', async () => {
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'admin' }
// 同组普通号:可见但不可写(editable=false)。
/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,推翻
* 2026-11-16 的平台超管单档):商品行写(编辑/删除/勾选批量删)对管理员级(超管/admin 档)
* 渲染,普通账号只读;分类写(批量编辑分类、分类管理)由 scope 的每组 editable 决定
* (本组管理员/公司超管/平台超管)。同日口径「超管可以有分组筛选,管理员及以下则没有」:
* 筛选行「分组」控件整块只对超管档(超级管理员/公司超级管理员)渲染。 */
describe('京东数据库写权限分档(商品行写=超管+管理员;分组筛选=超管档;分类写=本组 editable)', () => {
it('普通员工且本组不可写:无勾选列、无操作列、无批量删除、无批量编辑分类、无分组控件;列表/筛选/详情照常', async () => {
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
// 普通员工:可见但不可写(editable=false)。
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
jdApi.fetchJdProductDetail.mockImplementation(() =>
@@ -883,18 +883,21 @@ describe('京东数据库写权限分档(商品行写=平台超管;分类
)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '不可写分类的普通号没有勾选列')
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '不可写分类的普通员工没有勾选列')
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '批量删除按钮不渲染')
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '分类写入口不渲染(本组不可写)')
expect(wrapper.findAll('button').some((b) => b.text() === '分类管理')).toBe(true,
'分类管理入口是读面,普通号也能打开看(写控件由对话框按 editable 分档)')
'分类管理入口是读面,普通员工也能打开看(写控件由对话框按 editable 分档)')
expect(wrapper.find('thead').text()).not.toContain('操作', '操作列(编辑/删除)不渲染')
expect(wrapper.text()).toContain('只读:编辑/删除仅超级管理员可用', '只读提示必须看得见并区分两类写权限')
expect(wrapper.text()).toContain('只读:编辑/删除需超级管理员或管理员', '只读提示必须看得见并区分两类写权限')
expect(wrapper.text()).toContain('分类在本页「分类管理」查看与维护', '提示把分类维护入口指向本页「分类管理」(独立页已并入)')
// 分组筛选=超管档专属(2026-11-17 口径):普通员工连单组锁定芯片都不出。
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '普通员工不出分组下拉')
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '普通员工不出分组锁定芯片')
// 读面不受影响:筛选下拉、列表行、点行开详情都还在。
expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选是读面,保留')
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(5, '普通号列表 5 列:分类/商品信息/总库存/价格/同步时间')
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(5, '普通员工列表 5 列:分类/商品信息/总库存/价格/同步时间')
await wrapper.findAll('tbody tr')[0].trigger('click')
await flushPromises()
await flushPromises()
@@ -913,18 +916,35 @@ describe('京东数据库写权限分档(商品行写=平台超管;分类
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(true)
expect(wrapper.text()).not.toContain('只读:')
expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '超管档保留分组控件(单组=锁定芯片)')
wrapper.unmount()
})
it('本组管理员(非平台超管):商品行按钮仍无,但勾选列随批量编辑分类放开(6 列形状)', async () => {
it('公司超级管理员属超管档:写入口齐+分组控件在(单组=锁定芯片)', async () => {
useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' }
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(1)
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7, '公司超管 7 列:含操作列')
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '批量删除对公司超管渲染')
expect(wrapper.text()).not.toContain('只读:')
expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '公司超管保留分组控件')
wrapper.unmount()
})
it('管理员(admin 档):商品行写全放开(7 列+批量删除),分组控件整块不渲染', async () => {
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
// 组长档形状:可见组可写 ⇒ editable=true;商品行写仍按 isSuperAdmin 判(不受 editable 影响)。
// 组长档形状:可见组可写 ⇒ editable=true;商品行写按管理员档判(2026-11-17 口径)。
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(true))
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(6, '管理员 6 列:勾选/分类/商品信息/总库存/价格/同步时间(无操作列)')
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '批量删除(商品行写)仍只归平台超管')
expect(wrapper.find('thead').text()).not.toContain('操作')
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7, '管理员 7 列:勾选/分类/商品信息/总库存/价格/同步/操作')
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '批量删除(商品行写)对管理员渲染')
expect(wrapper.find('thead').text()).toContain('操作', '操作列(编辑/删除)对管理员渲染')
expect(wrapper.text()).not.toContain('只读:')
// 分组筛选=超管档专属:管理员即使本组可写分类,也不出下拉/锁定芯片。
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '管理员不出分组下拉')
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '管理员不出分组锁定芯片')
const editBtn = wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')
expect(editBtn, '本组管理员有批量编辑分类入口').toBeTruthy()
@@ -942,6 +962,48 @@ describe('京东数据库写权限分档(商品行写=平台超管;分类
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A)
wrapper.unmount()
})
it('管理员多组可见也不出「分组」下拉(超管档专属),写入口与默认组取数照常', async () => {
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
jdApi.fetchJdCategoryScope.mockResolvedValue({
platformSuperAdmin: false,
defaultGroupId: 11,
groups: [
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: false },
],
})
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
// 多组对管理员也不渲染切换下拉(作用域静默落在默认组)。
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '多组也不给管理员出分组下拉')
// 写入口不受影响:操作列+批量删除都在,列表按默认组取。
expect(wrapper.find('thead').text()).toContain('操作')
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11)
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 })
wrapper.unmount()
})
it('公司超级管理员多组可见:分组下拉在(超管档专属),可切组取数', async () => {
useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' }
jdApi.fetchJdCategoryScope.mockResolvedValue({
platformSuperAdmin: false,
defaultGroupId: 11,
groups: [
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: true },
],
})
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(true, '公司超管保留分组下拉')
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
await flushPromises()
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 })
wrapper.unmount()
})
})
describe('京东数据库分类按数据权限分组隔离(V203)', () => {
@@ -61,16 +61,18 @@ import java.util.List;
* <p>鉴权照外观专利只读页私有 {@code requireXxxAccess} 形状:JWT → 内部令牌回退 → 超管放行 →
* 非超管菜单权限(column_key/route_path 双匹配)。菜单行由 V196 只插 columns 不预授权
* ⇒ 默认仅 super_admin 可见可访问,其余角色由超管在权限页手工勾授后才放行。
* <b>2026-11-16 起读/写分档</b>:读(列表/类目/详情)按上面的菜单口径放行;写(编辑/上传图片/
* 删除/批量删除/批量归类)在菜单口径之上再要求平台超管,非超管一律 403(前端同窗隐藏写入口)。</p>
* <b>2026-11-16 起读/写分档(2026-11-17 口径放宽)</b>:读(列表/类目/详情)按上面的菜单
* 口径放行;商品行写(编辑/上传图片/删除/批量删除)在菜单口径之上再走管理员级写闸
* (平台超管+公司超管+admin 档放行,普通账号 403,见 {@code requireJdProductWrite});
* 批量归类走 V203 的按组判(requireWritableGroup)。</p>
*
* <p><b>公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」)</b>:读侧零公司
* 维度——company_id 请求参数与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批
* 摘除(2026-11-15 定案「京东数据库不区分公司、属于公共的」的最后一截),行上的 company_id
* 只剩「哪家公司客户端同步的」来源标记,不构成可见性边界;每个拿到本页菜单权限的管理员
* (含站点超管)看到同一份全量公共库。详情与写侧(编辑/删除)同样没有公司维度:
* 对全部公共行可编辑可删除,但<b>写动作只对平台超管开放</b>(2026-11-16 用户口径
* 「京东数据库只有超管有编辑删除权限」,见 {@code requirePlatformSuperAdminWrite}),
* 对全部公共行可编辑可删除,但<b>写动作只对管理员级开放</b>(2026-11-17 用户口径
* 「超管+管理员都可以,只有普通员工不能」,见 {@code requireJdProductWrite}),
* 写侧端点的 company_id 传参已随 2026-11-15 公共化摘除。</p>
*
* <p>导出端点已随 2026-11-15 客户口径「导出也不用」整段下线(控制器/服务/mapper 参数一起删);
@@ -172,7 +174,7 @@ public class AdminJdProductController {
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
@Valid @RequestBody JdProductUpdateRequest body,
HttpServletRequest request) {
RequestOperator operator = requirePlatformSuperAdminWrite(request);
RequestOperator operator = requireJdProductWrite(request);
Long updatedId = jdProductUpdateService.update(id, body);
log.info("[jd-product] 编辑商品 operatorId={} id={} title={}",
operator.id(), updatedId, body.getTitle());
@@ -196,7 +198,7 @@ public class AdminJdProductController {
@Parameter(description = "替换目标图片登记行 id(缺省=新增)")
@RequestParam(value = "replace_image_id", required = false) Long replaceImageId,
HttpServletRequest request) {
RequestOperator operator = requirePlatformSuperAdminWrite(request);
RequestOperator operator = requireJdProductWrite(request);
Long updatedId = jdProductUpdateService.uploadImage(id, file, imageType, attrName, replaceImageId);
log.info("[jd-product] 上传图片 operatorId={} id={} replaceImageId={} imageType={}",
operator.id(), updatedId, replaceImageId, imageType);
@@ -211,7 +213,7 @@ public class AdminJdProductController {
public ApiResponse<JdProductDeleteVo> delete(
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
HttpServletRequest request) {
RequestOperator operator = requirePlatformSuperAdminWrite(request);
RequestOperator operator = requireJdProductWrite(request);
JdProductDeleteVo vo = jdProductDeleteService.delete(List.of(id));
// 管理端破坏性动作必须留痕:谁、删了哪些行、桶里清了几个对象(同分组删除口径)。
log.info("[jd-product] 删除商品 operatorId={} id={} deleted={} objectsDeleted={}",
@@ -246,7 +248,7 @@ public class AdminJdProductController {
public ApiResponse<JdProductDeleteVo> batchDelete(
@Valid @RequestBody JdProductBatchDeleteRequest body,
HttpServletRequest request) {
RequestOperator operator = requirePlatformSuperAdminWrite(request);
RequestOperator operator = requireJdProductWrite(request);
JdProductDeleteVo vo = jdProductDeleteService.delete(body.getIds());
log.info("[jd-product] 批量删除商品 operatorId={} requested={} deleted={} objectsDeleted={} kept={}",
operator.id(), body.getIds().size(), vo.getDeleted(),
@@ -267,23 +269,27 @@ public class AdminJdProductController {
}
/**
* 写端点的越权闸(2026-11-16 用户口径「京东数据库只有超管有编辑删除权限」)。
* 写端点的越权闸(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,
* 推翻 2026-11-16「只有超管有编辑删除权限」的单档)。
*
* <p>读保持菜单权限口径(拿到 {@code admin_jd_database} 列权限的管理员可见同一份公共库),
* 写(编辑 / 上传图片 / 单行删除 / 批量删除 / 批量归类)收窄到<b>平台超级管理员</b>:
* 与 {@code BrandGatingController#requirePlatformSuperAdmin}、
* {@code AdminDeviceLogController#requireSuperAdmin} 同一判据(
* {@code DeviceSessionPolicy#isSuper} 只认站点 super_admin,公司超管不在内)。</p>
* <p>读保持菜单权限口径(拿到 {@code admin_jd_database} 列权限的管理员可见同一份公共库);
* 商品行写(编辑 / 上传图片 / 单行删除 / 批量删除)放宽到<b>管理员级</b>:平台超级管理员、
* 公司超级管理员、admin 角色三档放行,普通账号(role 归不出档)403。分类写不在此闸——
* {@code batch-assign-group} 沿用 V203 的 {@code requireWritableGroup}(本组管理员/
* 公司超管/平台超管,按组判)。</p>
*
* <p>写动作会置人工编辑锁({@code manual_locked=1})并物理删除桶内图片,属影响全平台公共
* 数据的动作,故不随读权限下放;非超管拿到 403 时前端已不渲染这些入口,本闸是兜底。</p>
* <p>写动作会置人工编辑锁({@code manual_locked=1})并物理删除桶内图片;普通账号拿到 403
* 时前端已不渲染这些入口,本闸是兜底。</p>
*/
private RequestOperator requirePlatformSuperAdminWrite(HttpServletRequest request) {
private RequestOperator requireJdProductWrite(HttpServletRequest request) {
RequestOperator operator = requireJdAccess(request);
if (!operator.superAdmin()) {
log.warn("[jd-product] 非平台超管写操作被拒 operatorId={} role={}",
operator.id(), adminAuthSupport.currentRole(operator.user()));
throw new BusinessException(403, "仅平台超级管理员可以编辑或删除京东数据库数据");
String role = adminAuthSupport.currentRole(operator.user());
boolean adminTier = operator.superAdmin()
|| DeviceSessionPolicy.isCompanySuperAdmin(role)
|| "admin".equals(role);
if (!adminTier) {
log.warn("[jd-product] 普通账号写操作被拒 operatorId={} role={}", operator.id(), role);
throw new BusinessException(403, "仅超级管理员或管理员可以编辑或删除京东数据库数据");
}
return operator;
}
@@ -77,7 +77,8 @@ import static org.mockito.Mockito.when;
* <p><b>V203 分类按数据权限分组隔离(2026-11-16 用户口径)</b>:分类归属存
* {@code biz_jd_product_group_assign} 的 (product_id, owner_group_id) 一行,读面靠
* {@code owner_group_id} 取「当前分组」的分类(缺省=作用域默认分组),归类的写权限
* 由 {@link JdCategoryScopeService} 判「该组可写」——商品行编辑/删除仍只平台超管。
* 由 {@link JdCategoryScopeService} 判「该组可写」——商品行编辑/删除走管理员级写闸
* (2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能」)。
* 本类把作用域服务整体 mock 掉(四档角色矩阵在 {@code JdCategoryScopeServiceTest} 里钉),
* 只钉控制器怎么用它、以及拒绝语义不被吞。</p>
*/
@@ -235,25 +236,29 @@ class AdminJdProductControllerTest {
assertTrue(source.contains("\"owner_group_id\""), "列表必须收 owner_group_id(当前分组)");
}
// ===================== 写权限分档(2026-11-16 / V203) =====================
// ===================== 写权限分档(2026-11-17:超管级+管理员可写,普通账号只读) =====================
/** 写端点越权闸的结构判据:商品行四条写路由走超管闸,读三条走菜单正门。 */
/** 写端点越权闸的结构判据:商品行四条写路由走管理员级写闸,读三条走菜单正门。 */
@Test
void 商品页读写权限分档_商品行写端点逐条走超管闸() throws IOException {
void 商品页读写权限分档_商品行写端点逐条走管理员级写闸() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
assertEquals(4, count(source, "requirePlatformSuperAdminWrite(request)"),
"编辑/上传图片/单行删除/批量删除四条商品行写路由必须逐条走超管写闸"
assertEquals(4, count(source, "requireJdProductWrite(request)"),
"编辑/上传图片/单行删除/批量删除四条商品行写路由必须逐条走管理员级写闸"
+ "(归类不在此列:V203 起归本组管理员可做)");
assertEquals(5, count(source, "requireJdAccess(request)"),
"列表/类目/详情/归类四条读+组内写路由,与超管写闸内部一处,共五处菜单权限正门");
assertTrue(source.contains("仅平台超级管理员可以编辑或删除京东数据库数据"),
"非超管写商品的 403 文案必须点名平台超管");
"列表/类目/详情/归类四条读+组内写路由,与写闸内部一处,共五处菜单权限正门");
assertTrue(source.contains("仅超级管理员或管理员可以编辑或删除京东数据库数据"),
"普通账号写商品的 403 文案必须点名超管与管理员(2026-11-17 口径)");
assertTrue(source.contains("operator.superAdmin()"),
"写闸必须在菜单口径之上再判 superAdmin(只放行站点超管,公司超管不在内)");
"写闸必须在菜单口径之上再判 superAdmin(平台超管直放)");
assertTrue(source.contains("DeviceSessionPolicy.isCompanySuperAdmin(role)"),
"写闸必须放行公司超级管理员(超管档,2026-11-17 口径「只有普通员工不能」)");
assertTrue(source.contains("\"admin\".equals(role)"),
"写闸必须放行 admin 角色(管理员档,2026-11-17 口径「超管+管理员都可以」)");
}
@Test
void 非超管有菜单权限时读放行_商品行写一律403且不触服务() {
void 普通账号有菜单权限时读放行_商品行写一律403且不触服务() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
JdProductUpdateService updateService = mock(JdProductUpdateService.class);
@@ -267,11 +272,12 @@ class AdminJdProductControllerTest {
AdminUserEntity operator = new AdminUserEntity();
operator.setId(9L);
operator.setUsername("company-admin");
operator.setUsername("member");
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
// 非超管(管理员 / 公司超管同形):拿到 admin_jd_database 菜单权限后读可进、商品行写仍拒。
when(authSupport.currentRole(operator)).thenReturn("admin");
// 普通账号:resolveRole 归不出档返回 null(AdminAuthSupport.currentRole 真实形状);
// 拿到 admin_jd_database 菜单权限后读可进、商品行写仍拒(2026-11-17 口径「只有普通员工不能」)。
when(authSupport.currentRole(operator)).thenReturn(null);
PermissionMenuItemVo grant = new PermissionMenuItemVo();
grant.setColumnKey(COLUMN_KEY);
grant.setRoutePath(ROUTE_PATH);
@@ -285,28 +291,28 @@ class AdminJdProductControllerTest {
pageVo.setItems(List.of());
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, null, request)
.isSuccess(), "非超管有菜单权限时读必须放行(读写分档只收窄写)");
.isSuccess(), "普通账号有菜单权限时读必须放行(读写分档只收窄写)");
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
JdProductUpdateRequest updateBody = new JdProductUpdateRequest();
updateBody.setTitle("标题");
BusinessException updateEx = assertThrows(BusinessException.class,
() -> controller.update(11L, updateBody, request));
assertTrue(updateEx.getMessage().contains("仅平台超级管理员"), "编辑被拒文案点名平台超管");
assertTrue(updateEx.getMessage().contains("仅超级管理员或管理员"), "编辑被拒文案点名超管与管理员");
BusinessException deleteEx = assertThrows(BusinessException.class,
() -> controller.delete(11L, request));
assertTrue(deleteEx.getMessage().contains("仅平台超级管理员"));
assertTrue(deleteEx.getMessage().contains("仅超级管理员或管理员"));
JdProductBatchDeleteRequest batchBody = new JdProductBatchDeleteRequest();
batchBody.setIds(List.of(11L, 12L));
BusinessException batchEx = assertThrows(BusinessException.class,
() -> controller.batchDelete(batchBody, request));
assertTrue(batchEx.getMessage().contains("仅平台超级管理员"));
assertTrue(batchEx.getMessage().contains("仅超级管理员或管理员"));
BusinessException uploadEx = assertThrows(BusinessException.class,
() -> controller.uploadImage(11L, mock(MultipartFile.class), "MAIN", null, null, request));
assertTrue(uploadEx.getMessage().contains("仅平台超级管理员"),
assertTrue(uploadEx.getMessage().contains("仅超级管理员或管理员"),
"上传/替换图片改桶内对象=写动作,必须同闸");
verify(updateService, never()).update(any(), any());
@@ -315,6 +321,69 @@ class AdminJdProductControllerTest {
verify(deleteService, never()).delete(any());
}
/** 2026-11-17 口径「超管+管理员都可以」:admin 档四条写入口全放行、公司超管(超管档)同闸放行。 */
@Test
void 管理员与公司超管有菜单权限即可写商品_写入口放行且触服务() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
JdProductUpdateService updateService = mock(JdProductUpdateService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, deleteService, updateService, mock(JdProductGroupService.class),
mock(JdCategoryScopeService.class), authSupport, permissionMenuService);
AdminUserEntity operator = new AdminUserEntity();
operator.setId(9L);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
// 管理员(admin 档,非任何超管):菜单权限命中后商品行写全放行。
when(authSupport.currentRole(operator)).thenReturn("admin");
PermissionMenuItemVo grant = new PermissionMenuItemVo();
grant.setColumnKey(COLUMN_KEY);
grant.setRoutePath(ROUTE_PATH);
when(permissionMenuService.getUserColumnPermissions(9L, "admin")).thenReturn(List.of(grant));
JdProductUpdateRequest updateBody = new JdProductUpdateRequest();
updateBody.setTitle("标题");
JdProductDetailVo detailVo = new JdProductDetailVo();
detailVo.setId(11L);
when(updateService.update(11L, updateBody)).thenReturn(11L);
when(queryService.detail(11L, null)).thenReturn(detailVo);
assertEquals(Boolean.TRUE, controller.update(11L, updateBody, request).isSuccess(),
"admin 档编辑放行必须是 success 信封(B80-03)");
verify(updateService).update(11L, updateBody);
when(updateService.uploadImage(11L, null, "MAIN", null, null)).thenReturn(11L);
assertEquals(Boolean.TRUE,
controller.uploadImage(11L, null, "MAIN", null, null, request).isSuccess(),
"admin 档上传图片同闸放行");
verify(updateService).uploadImage(11L, null, "MAIN", null, null);
JdProductDeleteVo receipt = new JdProductDeleteVo();
receipt.setDeleted(1);
when(deleteService.delete(List.of(11L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.delete(11L, request).isSuccess(), "admin 档单行删除放行");
JdProductBatchDeleteRequest batchBody = new JdProductBatchDeleteRequest();
batchBody.setIds(List.of(11L, 12L));
when(deleteService.delete(List.of(11L, 12L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.batchDelete(batchBody, request).isSuccess(), "admin 档批量删除放行");
verify(deleteService).delete(List.of(11L));
verify(deleteService).delete(List.of(11L, 12L));
// 公司超管=超管档:同一道闸放行(单条删除代表性钉住,防「只放平台超管」回潜)。
AdminUserEntity companySuper = new AdminUserEntity();
companySuper.setId(8L);
HttpServletRequest companyRequest = mock(HttpServletRequest.class);
when(authSupport.requireUser(companyRequest)).thenReturn(companySuper);
when(authSupport.currentRole(companySuper)).thenReturn("company_super_admin");
when(permissionMenuService.getUserColumnPermissions(8L, "admin")).thenReturn(List.of(grant));
when(deleteService.delete(List.of(21L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.delete(21L, companyRequest).isSuccess(),
"公司超级管理员属超管档,商品行写同闸放行(2026-11-17 口径)");
verify(deleteService).delete(List.of(21L));
}
@Test
void 不可写组的分组写一律403且不触服务() {
JdProductGroupService groupService = mock(JdProductGroupService.class);