feat: 配置成品策略调整部门查看权限
(cherry picked from commit 6bb376ccb4136e7c16cf89c874406de108106ca4)
This commit is contained in:
parent
07547a5362
commit
ee8b031fff
@ -9,6 +9,19 @@
|
||||
- 独立权限节点:finishedProductStrategy,查看、下载和仓库配置编辑分别控制;复用供应链权限管理。
|
||||
- 报表只读,生成调整建议,不写回商品档案和聚水潭仓库策略。
|
||||
|
||||
### 2026-11-18 部门查看权限
|
||||
|
||||
任务名:成品策略调整部门查看权限配置。
|
||||
|
||||
- 默认仅商品计划部及其下属部门可以查看;使用登录鉴权已读取的真实部门完整路径及多部门归属,完整匹配“商品计划部”层级。缺少完整路径时才使用部门名称,不根据 PLANNING 业务角色扩大默认范围。
|
||||
- 其他部门(包括主管)不再自动放行。供应商及外部人员排除;管理员保留查看、下载、仓库配置和权限管理能力。
|
||||
- 商品计划部默认仅开通查看,下载与仓库配置操作仍由管理员分别授权。管理员通过用户权限管理 → 修改权限 → 供应链 → 经营管理 → 成品策略调整维护岗位或个人权限,个人例外优先;可关闭部门默认查看,也可显式授权其他内部账号。
|
||||
- 菜单、服务端页面和全部读取、导出、配置接口使用同一权限策略;每次读取共享报表快照前仍鉴权,权限撤销立即限制后续请求。权限界面显示实际默认值,并允许管理员关闭或重新开通。
|
||||
|
||||
验证:共享开发次主线 6a3ebdda 基线上,11 个相关 Jest 文件共 161 项通过,覆盖部门识别、主管限制、管理员维护、岗位与个人授权/撤销、配置操作、导出、缓存快照鉴权及既有策略规则;改动源码 ESLint 与专项 TypeScript 检查通过。运行中的原工作区仅增量接入本权限改动,其 6 个相关测试文件共 46 项通过。浏览器在 1920×1080 核验默认查看状态、管理员关闭/开启及重载保留、非商品计划部主管默认关闭,无页面运行错误;管理员真实配置读取接口返回 200。浏览器账号与保存使用请求夹具,未创建真实用户、写入真实账号权限或修改业务数据。本轮未执行全量生产构建或生产部署。
|
||||
|
||||
规范自审:passed。这是自审,不是独立复审。权限集中在现有公共鉴权链路;管理员界面复用现有组件和样式;直接修正部门默认及主管放行规则,未修改数据库结构或其他模块权限。
|
||||
|
||||
## 数据与字段
|
||||
|
||||
商品资料逐条读取 SupplyChainProductArchive,货号使用 sku、商品编码使用 barcode,不混用。其余字段为 productName、productStatus、supplierName、purchaseOwner、packType、productTag、inOutWarehouse、storageType。统计日期使用报表完整生成时间,按 Asia/Shanghai 转换。
|
||||
|
||||
@ -149,7 +149,9 @@ export function PermissionMatrixTable({
|
||||
{supportedActions.has(action.key) ? (
|
||||
<PermissionActionToggle
|
||||
checked={access[action.key]}
|
||||
locked={allLocked || Boolean(mode === 'account' && baseAccess?.[action.key])}
|
||||
locked={allLocked || Boolean(
|
||||
mode === 'account' && row.targetKey !== 'finishedProductStrategy' && baseAccess?.[action.key]
|
||||
)}
|
||||
disabled={allLocked || loading || saving || !roleApplicable}
|
||||
label={`${row.label}${PERMISSION_ACTION_LABELS[action.key]}`}
|
||||
onClick={() => onToggle(row, action.key, rowActions)}
|
||||
|
||||
@ -14,6 +14,33 @@ describe('SupplyChainPermissionWorkspace', () => {
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('成品策略个人权限显示部门默认值,并保存管理员的关闭操作', async () => {
|
||||
const actor = userEvent.setup()
|
||||
const fetchMock = jest.fn().mockImplementation(async (url: string, init?: RequestInit) => {
|
||||
if (url.startsWith('/api/users')) {
|
||||
return { ok: true, json: async () => ({ success: true, data: { unassignedUsers: [{
|
||||
id: 'planner', name: '计划员', email: 'planner@example.com', role: 'USER', status: 'ACTIVE',
|
||||
businessRoles: ['PLANNING'], departmentPaths: ['公司 > 商品计划部'],
|
||||
}] } }) }
|
||||
}
|
||||
return response(init?.body ? JSON.parse(String(init.body)).overrides : {})
|
||||
})
|
||||
global.fetch = fetchMock as typeof fetch
|
||||
render(<SupplyChainPermissionWorkspace />)
|
||||
await screen.findByText('已读取当前权限配置')
|
||||
await actor.click(screen.getByRole('button', { name: '经营管理' }))
|
||||
await actor.click(screen.getByRole('button', { name: '成品策略调整' }))
|
||||
const planningRow = screen.getByText('企划').closest('tr')!
|
||||
await waitFor(() => expect(within(planningRow).getByRole('button', { name: /人/ })).toBeEnabled())
|
||||
await actor.click(within(planningRow).getByRole('button', { name: /人/ }))
|
||||
const view = await screen.findByRole('button', { name: '计划员可见' })
|
||||
expect(view).toHaveAttribute('aria-pressed', 'true')
|
||||
await actor.click(view)
|
||||
await waitFor(() => expect(view).toHaveAttribute('aria-pressed', 'false'))
|
||||
const [, save] = fetchMock.mock.calls.find(([, init]) => init?.method === 'PUT')!
|
||||
expect(JSON.parse(String(save.body)).overrides['finishedProductStrategy:user@planner:view']).toBe(false)
|
||||
})
|
||||
|
||||
it('loads and persists the separate supply-chain permission map', async () => {
|
||||
const actor = userEvent.setup()
|
||||
const fetchMock = jest
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
buildSupplyChainDiscontinuationDataScopeKey,
|
||||
buildSupplyChainPermissionOverrideKey,
|
||||
resolveSupplyChainDiscontinuationDataScopeOverride,
|
||||
resolveFinishedProductStrategyPermissionAccess,
|
||||
resolveSupplyChainPermissionAccess,
|
||||
resolveSupplyChainPermissionSubjectKeys,
|
||||
sanitizeSupplyChainPermissionOverrides,
|
||||
@ -320,15 +321,12 @@ export function SupplyChainPermissionWorkspace() {
|
||||
principalKey: SupplyChainPermissionPrincipalKey,
|
||||
subjectKeys: readonly SupplyChainPermissionRoleKey[],
|
||||
action: SupplyChainPermissionAction,
|
||||
userId?: string,
|
||||
user?: PermissionManagedUser,
|
||||
) {
|
||||
if (disabled) return
|
||||
const access = resolveSupplyChainPermissionAccess(
|
||||
overrides,
|
||||
activeTarget.key,
|
||||
subjectKeys,
|
||||
userId,
|
||||
)
|
||||
const access = activeTarget.key === 'finishedProductStrategy' && user
|
||||
? resolveFinishedProductStrategyPermissionAccess(overrides, user)
|
||||
: resolveSupplyChainPermissionAccess(overrides, activeTarget.key, subjectKeys, user?.id)
|
||||
const key = (targetAction: SupplyChainPermissionAction) =>
|
||||
buildSupplyChainPermissionOverrideKey(activeTarget.key, principalKey, targetAction)
|
||||
const nextValue = !access[action]
|
||||
@ -391,12 +389,9 @@ export function SupplyChainPermissionWorkspace() {
|
||||
|
||||
function renderUser(subject: SupplyChainPermissionSubject, user: PermissionManagedUser) {
|
||||
const userSubjectKeys = resolveSupplyChainPermissionSubjectKeys(user)
|
||||
const access = resolveSupplyChainPermissionAccess(
|
||||
overrides,
|
||||
activeTarget.key,
|
||||
userSubjectKeys,
|
||||
user.id,
|
||||
)
|
||||
const access = activeTarget.key === 'finishedProductStrategy'
|
||||
? resolveFinishedProductStrategyPermissionAccess(overrides, user)
|
||||
: resolveSupplyChainPermissionAccess(overrides, activeTarget.key, userSubjectKeys, user.id)
|
||||
const dataScope = activeTarget.key === 'discontinuationManagement'
|
||||
? resolveSupplyChainDiscontinuationDataScopeOverride(overrides, user.id)
|
||||
: null
|
||||
@ -423,7 +418,7 @@ export function SupplyChainPermissionWorkspace() {
|
||||
checked={access[action]}
|
||||
disabled={disabled}
|
||||
label={`${user.name}${SUPPLY_CHAIN_PERMISSION_ACTION_LABELS[action]}`}
|
||||
onClick={() => toggle(`user@${user.id}`, userSubjectKeys, action, user.id)}
|
||||
onClick={() => toggle(`user@${user.id}`, userSubjectKeys, action, user)}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
|
||||
@ -55,6 +55,39 @@ describe('UnifiedPermissionMatrix', () => {
|
||||
expect(await screen.findByText('已读取当前权限配置')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([undefined, 'supply' as const])('显示商品计划部默认查看权,管理员可关闭后重新开通(%s)', async (section) => {
|
||||
fetchMock.mockImplementation(async (_url: string, init?: RequestInit) => ({
|
||||
ok: true,
|
||||
json: async () => ({ data: { overrides: init?.body ? JSON.parse(String(init.body)).overrides : {} } }),
|
||||
}))
|
||||
const actor = userEvent.setup()
|
||||
render(<UnifiedPermissionMatrix mode="account" section={section} user={{
|
||||
id: 'planner', name: '计划员', email: 'planner@example.com', role: 'USER', status: 'ACTIVE',
|
||||
businessRoles: ['PLANNING'], departmentPaths: ['公司 > 商品计划部 > 一组'],
|
||||
}} />)
|
||||
await screen.findByText('已读取当前权限配置')
|
||||
await actor.type(screen.getByPlaceholderText('搜索权限名称'), '成品策略调整')
|
||||
if (section) {
|
||||
await actor.click(screen.getByRole('button', { name: '经营管理', exact: true }))
|
||||
await actor.click(screen.getByRole('button', { name: '成品策略调整', exact: true }))
|
||||
}
|
||||
const view = screen.getByLabelText('成品策略调整可见')
|
||||
expect(view).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByLabelText('成品策略调整下载')).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(screen.getByLabelText('成品策略调整操作')).toHaveAttribute('aria-pressed', 'false')
|
||||
await actor.click(view)
|
||||
await waitFor(() => expect(view).toHaveAttribute('aria-pressed', 'false'))
|
||||
const saves = () => fetchMock.mock.calls.filter(([, init]) => init?.method === 'PUT')
|
||||
expect(JSON.parse(String(saves()[0][1].body)).overrides).toEqual({
|
||||
'finishedProductStrategy:user@planner:view': false,
|
||||
'finishedProductStrategy:user@planner:download': false,
|
||||
'finishedProductStrategy:user@planner:edit': false,
|
||||
})
|
||||
await actor.click(view)
|
||||
await waitFor(() => expect(view).toHaveAttribute('aria-pressed', 'true'))
|
||||
expect(JSON.parse(String(saves()[1][1].body)).overrides['finishedProductStrategy:user@planner:view']).toBe(true)
|
||||
})
|
||||
|
||||
it('reveals matching nested permissions while searching', async () => {
|
||||
const actor = userEvent.setup()
|
||||
render(
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
buildSupplyChainDiscontinuationDataScopeKey,
|
||||
buildSupplyChainPermissionOverrideKey,
|
||||
resolveSupplyChainDiscontinuationDataScopeOverride,
|
||||
resolveFinishedProductStrategyPermissionAccess,
|
||||
resolveSupplyChainPermissionAccess,
|
||||
resolveSupplyChainPermissionSubjectKeys,
|
||||
sanitizeSupplyChainPermissionOverrides,
|
||||
@ -190,6 +191,9 @@ export function UnifiedPermissionMatrix({
|
||||
includeUser && mode === 'account' ? user?.id : undefined,
|
||||
)
|
||||
}
|
||||
if (row.targetKey === 'finishedProductStrategy' && mode === 'account' && user) {
|
||||
return resolveFinishedProductStrategyPermissionAccess(supplyOverrides, user, includeUser)
|
||||
}
|
||||
return resolveSupplyChainPermissionAccess(
|
||||
supplyOverrides,
|
||||
row.targetKey as SupplyChainPermissionTargetKey,
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
import {
|
||||
resolveFinishedProductStrategyPermissionAccess as access,
|
||||
type SupplyChainPermissionUser,
|
||||
} from './supply-chain-permission-settings'
|
||||
|
||||
const denied = { view: false, download: false, edit: false }
|
||||
const viewOnly = { view: true, download: false, edit: false }
|
||||
const planning: SupplyChainPermissionUser = {
|
||||
id: 'planner', role: 'USER', businessRoles: ['PLANNING'],
|
||||
departmentPaths: ['公司 > 商品计划部 > 计划一组'],
|
||||
}
|
||||
|
||||
describe('成品策略调整部门默认权限', () => {
|
||||
it.each([
|
||||
{ department: { name: '商品计划部' } },
|
||||
{ department: { fullPath: '公司 > 商品计划部 > 一组' } },
|
||||
{ departmentPaths: ['公司/商品计划部/一组'] },
|
||||
{ departmentPaths: ['公司 > 采购部', '公司 > 商品计划部'] },
|
||||
{ departmentPaths: ['公司 > 商品计划部 > 一组'] },
|
||||
])('商品计划部及下属部门默认只可查看:%j', (organization) => {
|
||||
expect(access({}, { ...planning, departmentPaths: [], ...organization })).toEqual(viewOnly)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{},
|
||||
{ businessRoles: ['PLANNING'] },
|
||||
{ role: 'SUPERVISOR', departmentPaths: ['公司 > 采购部'] },
|
||||
{ department: { name: '商品企划部' } },
|
||||
{ departmentPaths: ['公司 > 商品计划部助理组'] },
|
||||
{ department: { name: '商品计划部', fullPath: '公司 > 采购部' } },
|
||||
])('其他部门、未知部门及业务角色不自动放行:%j', (user) => {
|
||||
expect(access({}, user)).toEqual(denied)
|
||||
})
|
||||
|
||||
it('角色关闭可撤销部门默认查看,个人例外仍优先', () => {
|
||||
const overrides = { 'finishedProductStrategy:planning:view': false }
|
||||
expect(access(overrides, planning)).toEqual(denied)
|
||||
expect(access({ ...overrides, 'finishedProductStrategy:user@planner:view': true }, planning))
|
||||
.toEqual(viewOnly)
|
||||
expect(access({ 'finishedProductStrategy:user@planner:view': false }, planning)).toEqual(denied)
|
||||
expect(access({ 'finishedProductStrategy:user@planner:view': false }, planning, false)).toEqual(viewOnly)
|
||||
})
|
||||
|
||||
it('管理员可为其他部门开通查看、下载或操作,互相独立且保留权限依赖', () => {
|
||||
const user = { id: 'buyer', businessRoles: ['PURCHASING'] }
|
||||
expect(access({ 'finishedProductStrategy:user@buyer:view': true }, user)).toEqual(viewOnly)
|
||||
expect(access({ 'finishedProductStrategy:purchase:download': true }, user))
|
||||
.toEqual({ view: true, download: true, edit: false })
|
||||
expect(access({ 'finishedProductStrategy:user@buyer:edit': true }, user))
|
||||
.toEqual({ view: true, download: true, edit: true })
|
||||
})
|
||||
|
||||
it.each(['ADMIN', 'SUPER_ADMIN'])('管理员保留配置能力:%s', (role) => {
|
||||
expect(access({ 'finishedProductStrategy:user@admin:view': false }, { id: 'admin', role }))
|
||||
.toEqual({ view: true, download: true, edit: true })
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ businessRoles: ['SUPPLIER'] },
|
||||
{ businessRoles: ['EXTERNAL_INTAKE'] },
|
||||
])('供应商及外部人员不可通过部门默认或个人授权进入:%j', (user) => {
|
||||
expect(access({ 'finishedProductStrategy:user@planner:edit': true }, { ...planning, ...user }))
|
||||
.toEqual(denied)
|
||||
})
|
||||
})
|
||||
@ -497,6 +497,7 @@ export function isSupplyChainPermissionTargetExcluded(
|
||||
user: SupplyChainPermissionUser,
|
||||
targetKey: SupplyChainPermissionTargetKey,
|
||||
) {
|
||||
if (targetKey === 'finishedProductStrategy') return isSupplyChainExcludedUser(user)
|
||||
return targetKey === 'discontinuationManagement' && isSupplierAccount(user)
|
||||
}
|
||||
|
||||
@ -628,12 +629,13 @@ export function resolveSupplyChainPermissionAccess(
|
||||
targetKey: SupplyChainPermissionTargetKey,
|
||||
subjectKeys: readonly SupplyChainPermissionRoleKey[],
|
||||
userId?: string | null,
|
||||
options?: { defaultOpen?: boolean },
|
||||
options?: { defaultOpen?: boolean; defaultView?: boolean },
|
||||
) {
|
||||
// 商品SABC打标相关节点默认开放(所有人都能查看/导出),
|
||||
// 只有后台里显式关掉(false)才会受限。
|
||||
const defaultOpen = options?.defaultOpen ?? SUPPLY_CHAIN_DEFAULT_OPEN_TARGETS.has(targetKey)
|
||||
let view = defaultOpen
|
||||
const defaultView = defaultOpen || options?.defaultView === true
|
||||
let view = defaultView
|
||||
let download = defaultOpen
|
||||
let edit = false
|
||||
let deniedView = false
|
||||
@ -674,9 +676,9 @@ export function resolveSupplyChainPermissionAccess(
|
||||
download ||= subjectDownload
|
||||
edit ||= subjectEdit
|
||||
})
|
||||
// 只对「默认开放」的节点启用「显式关闭优先」,
|
||||
// 对默认开放查看或下载的节点启用「显式关闭优先」,
|
||||
// 其余节点保持原有的「任一授权即放行」语义,避免影响既有配置。
|
||||
if (defaultOpen) {
|
||||
if (defaultView || defaultOpen) {
|
||||
if (deniedView) { view = false; download = false; edit = false }
|
||||
else if (deniedDownload) { download = false; edit = false }
|
||||
else if (deniedEdit) { edit = false }
|
||||
@ -713,6 +715,34 @@ export function resolveSupplyChainPermissionAccess(
|
||||
return { view, download, edit }
|
||||
}
|
||||
|
||||
/** 成品策略默认仅商品计划部可见,管理员配置的角色/个人例外优先。 */
|
||||
export function resolveFinishedProductStrategyPermissionAccess(
|
||||
overrides: SupplyChainPermissionOverrideMap,
|
||||
user: SupplyChainPermissionUser,
|
||||
includeUser = true,
|
||||
): SupplyChainPermissionAccess {
|
||||
if (isSupplyChainExcludedUser(user)) {
|
||||
return { view: false, download: false, edit: false }
|
||||
}
|
||||
if (canManageSupplyChainPermissions(user)) {
|
||||
return { view: true, download: true, edit: true }
|
||||
}
|
||||
const paths = [user.department?.fullPath, ...(user.departmentPaths ?? [])]
|
||||
.map((path) => path?.trim() ?? '')
|
||||
.filter(Boolean)
|
||||
const departmentPaths = paths.length ? paths : [user.department?.name ?? '']
|
||||
const defaultView = departmentPaths.some((path) => (
|
||||
path.split(/[>>/\\|→]/).some((part) => part.trim() === '商品计划部')
|
||||
))
|
||||
return resolveSupplyChainPermissionAccess(
|
||||
overrides,
|
||||
'finishedProductStrategy',
|
||||
resolveSupplyChainPermissionSubjectKeys(user),
|
||||
includeUser ? user.id : undefined,
|
||||
{ defaultView },
|
||||
)
|
||||
}
|
||||
|
||||
/** 判断某个权限模块是否已有针对该用户/角色的显式授权或拒绝记录。 */
|
||||
export function hasSupplyChainPermissionOverride(
|
||||
overrides: SupplyChainPermissionOverrideMap,
|
||||
|
||||
@ -21,6 +21,19 @@ const testPrisma = prisma as unknown as {
|
||||
}
|
||||
|
||||
describe('supply chain permission settings service', () => {
|
||||
it('商品计划部的查看权不包含权限管理,只有管理员可更改配置', async () => {
|
||||
const planner = {
|
||||
id: 'planner', email: 'planner@example.com', name: '计划员', role: 'USER' as const,
|
||||
status: 'ACTIVE' as const, departmentPaths: ['公司 > 商品计划部'],
|
||||
}
|
||||
await expect(supplyChainPermissionSettingsService.getSettings(planner))
|
||||
.rejects.toThrow('只有管理员可以维护供应链开发权限')
|
||||
await expect(supplyChainPermissionSettingsService.updateSettings({
|
||||
overrides: { 'finishedProductStrategy:user@planner:edit': true },
|
||||
}, planner)).rejects.toThrow('只有管理员可以维护供应链开发权限')
|
||||
expect(testPrisma.$transaction).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('denies supplier accounts access to discontinuation management', async () => {
|
||||
await expect(
|
||||
supplyChainPermissionSettingsService.getUserAccess(
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
/** @jest-environment node */
|
||||
jest.mock('@/lib/prisma', () => ({
|
||||
prisma: { supplyChainPermissionOverride: { findMany: jest.fn() } },
|
||||
}))
|
||||
jest.mock('@/server/repositories/finished-product-strategy.repository', () => ({ finishedProductStrategyRepository: {} }))
|
||||
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { strategyQuerySchema } from '@/lib/finished-product-strategy'
|
||||
import type { AuthUser } from '@/server/core/types'
|
||||
import { FinishedProductStrategyService } from './finished-product-strategy.service'
|
||||
import { supplyChainPermissionSettingsService } from './supply-chain-permission-settings.service'
|
||||
|
||||
it('已缓存报表仍逐次鉴权,撤销查看权限后读取、配置和导出均受限', async () => {
|
||||
const findMany = prisma.supplyChainPermissionOverride.findMany as jest.Mock
|
||||
findMany.mockResolvedValue([])
|
||||
const planner = { id: 'planner', role: 'USER', departmentPaths: ['公司 > 商品计划部'] } as AuthUser
|
||||
const supervisor = { id: 'supervisor', role: 'SUPERVISOR', departmentPaths: ['公司 > 采购部'] } as AuthUser
|
||||
const repository = {
|
||||
listArchive: jest.fn().mockResolvedValue([]),
|
||||
listInventory: jest.fn().mockResolvedValue({ warehouses: [], inventory: [], cloud: [] }),
|
||||
listWarehouses: jest.fn().mockResolvedValue([]),
|
||||
getWarehouseConfiguration: jest.fn().mockResolvedValue(null),
|
||||
saveWarehouseConfiguration: jest.fn(),
|
||||
}
|
||||
const service = new FinishedProductStrategyService(repository, supplyChainPermissionSettingsService)
|
||||
const query = strategyQuerySchema.parse({})
|
||||
await service.getReadState(planner, query)
|
||||
await new Promise((resolve) => setTimeout(resolve, 0))
|
||||
const ready = await service.getReadState(planner, query)
|
||||
expect(ready.status).toBe('ready')
|
||||
if (ready.status !== 'ready') throw new Error('Expected a shared report snapshot')
|
||||
const output = { generatedAt: ready.data.generatedAt, filters: {}, columns: [{ key: 'barcode', width: 180 }] }
|
||||
|
||||
await expect(service.export(planner, output)).rejects.toThrow('下载权限')
|
||||
await expect(service.saveWarehouseConfiguration(planner, { warehouseIds: [1] }))
|
||||
.rejects.toThrow('配置编辑权限')
|
||||
await expect(service.getReadState(supervisor, query)).rejects.toThrow('查看权限')
|
||||
|
||||
findMany.mockResolvedValue([{ targetKey: 'finishedProductStrategy', subjectKey: 'user@planner', action: 'view', enabled: false }])
|
||||
await expect(service.getReadState(planner, query)).rejects.toThrow('查看权限')
|
||||
await expect(service.getWarehouseConfiguration(planner)).rejects.toThrow('查看权限')
|
||||
await expect(service.export(planner, output)).rejects.toThrow('下载权限')
|
||||
expect(repository.listArchive).toHaveBeenCalledTimes(1)
|
||||
expect(repository.listWarehouses).not.toHaveBeenCalled()
|
||||
expect(repository.saveWarehouseConfiguration).not.toHaveBeenCalled()
|
||||
})
|
||||
@ -41,6 +41,36 @@ describe('supply chain permission settings service', () => {
|
||||
mockFindMany.mockReset()
|
||||
})
|
||||
|
||||
it.each(['USER', 'SUPERVISOR'])('成品策略菜单与接口对商品计划部保持一致(%s)', async (role) => {
|
||||
mockFindMany.mockResolvedValue([])
|
||||
const planner = { ...user, role, departmentPaths: ['公司 > 商品计划部 > 一组'] }
|
||||
const buyer = { ...user, role, departmentPaths: ['公司 > 采购部'] }
|
||||
for (const [account, visible] of [[planner, true], [buyer, false]] as const) {
|
||||
await expect(supplyChainPermissionSettingsService.getUserAccess(account, 'finishedProductStrategy'))
|
||||
.resolves.toEqual({ view: visible, download: false, edit: false })
|
||||
const menu = await supplyChainPermissionSettingsService.getVisibleTargetKeys(account)
|
||||
expect(menu.includes('finishedProductStrategy')).toBe(visible)
|
||||
}
|
||||
mockFindMany.mockResolvedValue([override('finishedProductStrategy', 'view', false)])
|
||||
await expect(supplyChainPermissionSettingsService.getUserAccess(planner, 'finishedProductStrategy'))
|
||||
.resolves.toEqual({ view: false, download: false, edit: false })
|
||||
await expect(supplyChainPermissionSettingsService.getVisibleTargetKeys(planner))
|
||||
.resolves.not.toContain('finishedProductStrategy')
|
||||
mockFindMany.mockResolvedValue([override('finishedProductStrategy', 'view')])
|
||||
await expect(supplyChainPermissionSettingsService.getUserAccess(buyer, 'finishedProductStrategy'))
|
||||
.resolves.toEqual({ view: true, download: false, edit: false })
|
||||
await expect(supplyChainPermissionSettingsService.getVisibleTargetKeys(buyer))
|
||||
.resolves.toContain('finishedProductStrategy')
|
||||
})
|
||||
|
||||
it('成品策略管理员无需部门身份仍可进入并配置', async () => {
|
||||
await expect(supplyChainPermissionSettingsService.getUserAccess({ role: 'ADMIN' }, 'finishedProductStrategy'))
|
||||
.resolves.toEqual({ view: true, download: true, edit: true })
|
||||
await expect(supplyChainPermissionSettingsService.getVisibleTargetKeys({ role: 'ADMIN' }))
|
||||
.resolves.toContain('finishedProductStrategy')
|
||||
expect(mockFindMany).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('includes the clearance menu for administrators', async () => {
|
||||
const targets = await supplyChainPermissionSettingsService
|
||||
.getVisibleTargetKeys({ role: 'ADMIN' })
|
||||
|
||||
@ -15,6 +15,7 @@ import {
|
||||
parseSupplyChainDiscontinuationDataScopeKey,
|
||||
parseSupplyChainPermissionOverrideKey,
|
||||
resolveSupplyChainDiscontinuationDataScopeOverride,
|
||||
resolveFinishedProductStrategyPermissionAccess,
|
||||
resolveSupplyChainPermissionAccess,
|
||||
resolveSupplyChainPermissionSubjectKeys,
|
||||
sanitizeSupplyChainPermissionOverrides,
|
||||
@ -571,6 +572,17 @@ class SupplyChainPermissionSettingsService {
|
||||
targetKey: SupplyChainPermissionTargetKey,
|
||||
) {
|
||||
if (isSupplyChainPermissionTargetExcluded(user, targetKey)) return emptyAccess()
|
||||
if (targetKey === 'finishedProductStrategy') {
|
||||
if (canManageSupplyChainPermissions(user)) {
|
||||
return resolveFinishedProductStrategyPermissionAccess({}, user)
|
||||
}
|
||||
try {
|
||||
return resolveFinishedProductStrategyPermissionAccess(await this.readOverrides(), user)
|
||||
} catch (error) {
|
||||
if (isMissingPermissionTable(error)) return emptyAccess()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
if (targetKey === 'workspace' && !canAccessSupplyChainWorkspace(user)) {
|
||||
return { view: false, download: false, edit: false }
|
||||
@ -686,21 +698,23 @@ class SupplyChainPermissionSettingsService {
|
||||
try {
|
||||
const overrides = await this.readOverrides()
|
||||
const subjectKeys = resolveSupplyChainPermissionSubjectKeys(user)
|
||||
return roleVisibleTargetKeys.filter((targetKey) => (
|
||||
(
|
||||
targetKey !== 'freightMaintenance'
|
||||
&& targetKey !== 'discontinuationManagement'
|
||||
return roleVisibleTargetKeys.filter((targetKey) => {
|
||||
if (targetKey === 'finishedProductStrategy') {
|
||||
return resolveFinishedProductStrategyPermissionAccess(overrides, user).view
|
||||
}
|
||||
return (
|
||||
(
|
||||
targetKey !== 'freightMaintenance'
|
||||
&& targetKey !== 'discontinuationManagement'
|
||||
)
|
||||
|| this.resolveAccessFromOverrides(overrides, targetKey, subjectKeys, user.id).view
|
||||
)
|
||||
|| this.resolveAccessFromOverrides(
|
||||
overrides,
|
||||
targetKey,
|
||||
subjectKeys,
|
||||
user.id,
|
||||
).view
|
||||
))
|
||||
})
|
||||
} catch (error) {
|
||||
if (isMissingPermissionTable(error)) {
|
||||
return roleVisibleTargetKeys.filter((targetKey) => targetKey !== 'freightMaintenance')
|
||||
return roleVisibleTargetKeys.filter((targetKey) => (
|
||||
targetKey !== 'freightMaintenance' && targetKey !== 'finishedProductStrategy'
|
||||
))
|
||||
}
|
||||
throw error
|
||||
}
|
||||
@ -719,6 +733,9 @@ class SupplyChainPermissionSettingsService {
|
||||
const targetKeys = SUPPLY_CHAIN_PERMISSION_TARGET_KEYS
|
||||
return targetKeys.filter((targetKey) => {
|
||||
if (isSupplyChainPermissionTargetExcluded(user, targetKey)) return false
|
||||
if (targetKey === 'finishedProductStrategy') {
|
||||
return resolveFinishedProductStrategyPermissionAccess(overrides, user).view
|
||||
}
|
||||
if (isModularProcessingPermissionTarget(targetKey)) return false
|
||||
if (isProductionStopPermissionTarget(targetKey)) return false
|
||||
if (isProductStopPermissionTarget(targetKey) && targetKey !== 'productInventoryStop') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user