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
@@ -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)', () => {