feat(jd): 京东店铺分类按数据权限分组隔离(V203)

用户口径:不同组不能看到跨组的分类;当前组只管理员可以编辑分类,同组普通号可以进弹窗看但不能增删;
平台超管全量可见可编辑,公司超管管本公司全部组;归类也按组隔离且不再置人工编辑锁。

数据模型:biz_jd_product_group 加 owner_group_id(NOT NULL DEFAULT 0,
uk_company_owner_name(company_id, owner_group_id, name));新增 biz_jd_product_group_assign
(product_id, owner_group_id, category_id, uk_product_owner) 承接归类,同一商品各组可各自归类;
biz_jd_product.group_id 保留但零读零写。

权限:新增 JdCategoryScopeService(GET /api/admin/jd-product-groups/scope 回可见组 + 每组 editable)
四档矩阵;分类增删改与归类走 requireWritableGroup 403;商品行写(编辑/删除)仍只平台超管。

读面:列表/筛选/详情/归类一律按 owner_group_id,分类筛选 group_id 走归属表 EXISTS 下推
(不在 Java 侧 filter);用户端 /api/jd-collect/groups 按登录用户可见组收窄。

前端:工具栏「分组」下拉(多组才渲染,单组锁定显示);店铺分类弹窗对所有有该页菜单权限的人可见,
但按 editable 隐藏新建/改名/删除/勾选/归入移出;编辑抽屉「分类」下拉下线;只读提示改为
「只读:编辑/删除仅超级管理员可用;分类由本组管理员维护」。

验证:后端 mvn -o test 整量 5610 例 0 失败 19 skip;后管 npx vue-tsc 绿 / node --test 1919 绿 /
vitest 132 绿;用户端 vue-tsc 绿;python scripts/_push_gate.py --fast overall=pass。
迁移实跑与真机页面验收留发版窗口(本机无 MySQL/OSS);V203 需与另一路 V202 同窗口发布。
This commit is contained in:
2026-11-16 21:09:44 +08:00
parent e621deea58
commit 61ab844e5d
39 changed files with 2330 additions and 627 deletions
@@ -27,6 +27,7 @@ const jdApi = vi.hoisted(() => ({
fetchJdProductDetail: vi.fn(),
deleteJdProducts: vi.fn(),
fetchJdProductGroups: vi.fn(),
fetchJdCategoryScope: vi.fn(),
fetchJdProductCategories: vi.fn(),
createJdProductGroup: vi.fn(),
updateJdProductGroup: vi.fn(),
@@ -75,11 +76,24 @@ function item(id: number, over: Record<string, unknown> = {}) {
let pinia: Pinia
/** 分组 id 常量:默认作用域就这一个可见且可写的组(组长档形状),分类与行集都按它取。 */
const GROUP_A = 11
/** 分类作用域夹具(GET /scope 的归一形状):单组默认场景。 */
function singleGroupScope(editable = true) {
return {
platformSuperAdmin: false,
defaultGroupId: GROUP_A,
groups: [{ id: GROUP_A, name: '甲组', label: '甲组', editable }],
}
}
beforeEach(() => {
vi.clearAllMocks()
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
jdApi.fetchJdProductGroups.mockResolvedValue([])
jdApi.fetchJdProductCategories.mockResolvedValue([])
confirmMock.mockResolvedValue(true)
@@ -121,7 +135,9 @@ describe('店铺分类弹窗', () => {
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
await flushPromises()
const modal = wrapper.get('.group-modal')
expect(modal.text()).toContain('价格/库存等字段停更')
expect(modal.text()).toContain('不影响采集对价格/库存的更新', 'V203 归类不再置人工编辑锁,文案不得再说「停更」')
expect(modal.text()).not.toContain('停更', '旧「价格/库存等字段停更」口径已废(归类不再置锁)')
expect(modal.text()).toContain('甲组', '标题带当前分组名(跨组同名分类靠它区分)')
expect(modal.find('.scope-tabs').exists()).toBe(false)
await modal.get('.group-row').trigger('click')
await modal.get('.cat-trigger').trigger('click')
@@ -133,11 +149,12 @@ describe('店铺分类弹窗', () => {
await modal.get('tbody input[type="checkbox"]').setValue(true)
await modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.trigger('click')
await flushPromises()
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7)
// 归类落点是「本组」的归属行:第三个参数必须是当前分组(V203 一组一商品一行)。
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A)
await modal.get('tbody input[type="checkbox"]').setValue(true)
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
await flushPromises()
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
await modal.get('.modal-close').trigger('click')
expect(wrapper.find('.group-modal').exists()).toBe(false)
wrapper.unmount()
@@ -200,7 +217,7 @@ describe('店铺分类弹窗', () => {
await modal.get('thead input').setValue(true)
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
await flushPromises()
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
wrapper.unmount()
})
@@ -249,7 +266,8 @@ describe('店铺分类弹窗', () => {
await modal.get('.group-create input').setValue('新分类')
await modal.get('.create-icon-btn').trigger('click')
await flushPromises()
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0 })
// 新建落当前分组的归属(V203 跨组不可见:不带 ownerGroupId 会落到后端默认组)。
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0, ownerGroupId: GROUP_A })
await modal.findAll('button').find(b => b.text() === '改名')!.trigger('click')
await modal.get('.group-row input').setValue('改名后')
await modal.findAll('button').find(b => b.text() === '保存')!.trigger('click')
@@ -729,22 +747,26 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
})
})
/** 写权限收窄(2026-11-16 用户口径「京东数据库只有超管有编辑删除权限」):
* 读按菜单权限可见(列表/筛选/详情照常),写(勾选列/操作列/删除勾选/店铺分类与归类)
* 只对平台超管渲染;后端同口径兜底 403(AdminJdProductController#requirePlatformSuperAdminWrite)。 */
describe('京东数据库写权限收窄(超管专属)', () => {
it('非超管只读:无勾选列、无操作列、无删除勾选与店铺分类入口,列表/筛选/详情照常可用', async () => {
/** 写权限分档(2026-11-16 用户口径):
* 商品行写(编辑/删除/勾选批量删)只对平台超管渲染;
* 分类写由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管)——同组普通号
* 能打开「店铺分类」弹窗看(用户原话「可以进弹窗里看 但是不能添加删除分类」),
* 但新建/改名/删除与归类入口都不渲染,后端同口径 403 兜底。 */
describe('京东数据库写权限分档(商品行写=平台超管;分类写=本组 editable)', () => {
it('非超管只读:无勾选列、无操作列、无删除勾选;列表/筛选/详情照常,弹窗可看不可改', async () => {
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'admin' }
// 同组普通号:可见但不可写(editable=false)。
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
jdApi.fetchJdProductDetail.mockImplementation(() =>
Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' }),
)
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.find('thead').text()).not.toContain('操作', '操作列(编辑/删除)不渲染')
expect(wrapper.text()).toContain('只读:编辑/删除仅超级管理员可用', '只读提示必须看得见')
expect(wrapper.text()).toContain('只读:编辑/删除仅超级管理员可用;分类由本组管理员维护', '只读提示必须看得见并区分两类写权限')
// 读面不受影响:筛选下拉、列表行、点行开详情都还在。
expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选是读面,保留')
@@ -755,6 +777,25 @@ describe('京东数据库写权限收窄(超管专属)', () => {
await flushPromises()
expect(wrapper.find('.drawer-mask').exists()).toBe(true, '点行仍可开只读详情抽屉')
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
await wrapper.find('.drawer-mask').trigger('click')
await flushPromises()
// 「店铺分类」弹窗对所有有本页菜单权限的人可见(可以进弹窗里看)……
const dialogButton = wrapper.findAll('button').find((b) => b.text() === '店铺分类')
expect(dialogButton, '同组普通号也能打开分类弹窗(只读查看)').toBeTruthy()
await dialogButton!.trigger('click')
await flushPromises()
const modal = wrapper.get('.group-modal')
expect(modal.text()).toContain('本组分类(只读)', '弹窗文案点名只读')
expect(modal.text()).toContain('甲组', '看得到本组分类')
// ……但没有建/改/删与归类入口(用户原话「不能添加删除分类」)。
expect(modal.find('.group-create').exists()).toBe(false, '只读账号不渲染新建输入行')
expect(modal.findAll('button').some((b) => b.text() === '改名')).toBe(false, '无改名入口')
expect(modal.findAll('button').some((b) => b.text() === '删除')).toBe(false, '无删除入口')
expect(modal.find('tbody input[type="checkbox"]').exists()).toBe(false, '右栏无勾选列(没有归类写入口)')
expect(modal.findAll('button').some((b) => b.text().includes('归入') || b.text() === '移出分类')).toBe(false,
'无归入/移出入口')
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
wrapper.unmount()
})
@@ -767,7 +808,74 @@ describe('京东数据库写权限收窄(超管专属)', () => {
expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7)
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.text()).not.toContain('只读:')
wrapper.unmount()
})
it('本组管理员(非平台超管):商品行仍只读,但分类弹窗有建/改/删与归类入口', async () => {
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
// 组长档形状:可见组可写 ⇒ editable=true,商品行写仍按 isSuperAdmin 判(不受 editable 影响)。
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 input[type="checkbox"]')).toHaveLength(0, '组管理员也不动商品行(编辑/删除只归平台超管)')
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
await flushPromises()
const modal = wrapper.get('.group-modal')
expect(modal.find('.group-create').exists()).toBe(true, '本组管理员能新建分类')
expect(modal.findAll('button').some((b) => b.text() === '删除')).toBe(true, '能删除分类')
expect(modal.find('tbody input[type="checkbox"]').exists()).toBe(true, '能勾选商品归类')
wrapper.unmount()
})
})
/** 分组作用域(V203):不同组看不到彼此的分类;能看多组的人用「分组」下拉切换。 */
describe('京东数据库分类按数据权限分组隔离(V203)', () => {
it('多组可见:工具栏出「分组」下拉,切换后分类下拉与列表一并用新组取', async () => {
jdApi.fetchJdCategoryScope.mockResolvedValue({
platformSuperAdmin: true,
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 })
// 首屏就按默认组取(不是先不带 ownerGroupId 再补一次)。
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11)
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 })
const picker = wrapper.get('[aria-label="当前分组"]')
expect(picker.findAll('option').map((o) => o.text())).toEqual(['甲公司 / A组', '甲公司 / B组'],
'跨公司组名由后端拼进 label,前端不解析公司字段')
await picker.setValue('12')
await flushPromises()
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 },
'切组后列表按新组重取并回第一页')
wrapper.unmount()
})
it('只有一组:不出下拉(锁定显示组名),分类与行集仍按该组取', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '单组不渲染切换下拉')
expect(wrapper.get('.jd-group-locked').text()).toBe('分组:甲组')
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: GROUP_A })
wrapper.unmount()
})
it('不属于任何数据权限分组:分类全空、不给切换,弹窗直说「你还不属于任何数据权限分组」', async () => {
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
expect(wrapper.find('[aria-label="筛选店铺分类"]').text()).toContain('全部分类', '分类筛选只剩「全部分类」')
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类')
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
await flushPromises()
expect(wrapper.get('.group-modal').text()).toContain('你还不属于任何数据权限分组')
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
wrapper.unmount()
})
})