优化客服权限

This commit is contained in:
yml2213
2026-07-10 12:00:23 +08:00
parent 763f5034fd
commit ca5433ada4
18 changed files with 467 additions and 120 deletions
@@ -154,7 +154,7 @@ export async function getAdminOrderDetail(
kuaishouIndustryVouchers: kuaishouIndustryVouchers.map(mapAdminKuaishouIndustryVoucher),
operations: {
canResendKuaishouIndustryVoucherCode:
viewerContext.canManageTaskLifecycle && kuaishouIndustryVouchers.length > 0,
viewerContext.canOperateKuaishouIndustryVoucher && kuaishouIndustryVouchers.length > 0,
},
}
}
@@ -360,9 +360,9 @@ export async function getAdminTaskDetail(
String(task.executor_key || '').trim() === 'kuaishou_ct_assisted' &&
canReturnKuaishouCloudFulfillmentStatus(task.task_status),
canResendKuaishouIndustryVoucherCode:
viewerContext.canManageTaskLifecycle && hasKuaishouIndustryVoucher,
viewerContext.canOperateKuaishouIndustryVoucher && hasKuaishouIndustryVoucher,
canConsumeKuaishouIndustryVoucher:
viewerContext.canManageTaskLifecycle &&
viewerContext.canOperateKuaishouIndustryVoucher &&
hasKuaishouIndustryVoucher &&
kuaishouIndustryVoucherStatus !== 'CONSUMED' &&
kuaishouIndustryVoucherSendCallbackStatus === 'success',
@@ -39,6 +39,13 @@ test('canViewerCloseTask allows support to close active task but not redeemed ta
assert.equal(canViewerCloseTask({ task_status: 'redeemed' }, viewerContext), false)
})
test('createAdminViewerContext lets support operate vouchers without lifecycle permissions', () => {
const viewerContext = createAdminViewerContext({ role: 'support' })
assert.equal(viewerContext.canOperateKuaishouIndustryVoucher, true)
assert.equal(viewerContext.canManageTaskLifecycle, false)
})
test('mapKuaishouCloudFulfillmentContext exposes cloud account display labels', () => {
const flow = mapKuaishouCloudFulfillmentContext(
{
@@ -25,6 +25,7 @@ export type AdminViewerContext = {
canViewSensitiveTaskData: boolean
canManageTaskLifecycle: boolean
canOperateAssistedTask: boolean
canOperateKuaishouIndustryVoucher: boolean
}
type RedeemResolutionAttempt = {
@@ -370,6 +371,7 @@ export function createAdminViewerContext(
canViewSensitiveTaskData: role === 'admin' || role === 'operator',
canManageTaskLifecycle: role === 'admin' || role === 'operator',
canOperateAssistedTask: role === 'admin' || role === 'operator' || role === 'support',
canOperateKuaishouIndustryVoucher: role === 'admin' || role === 'operator' || role === 'support',
}
}
@@ -369,7 +369,7 @@ export async function resendAdminTaskKuaishouIndustryVoucherCode(
const now = nowIso()
const viewerContext = createAdminViewerContext(session)
if (!viewerContext.canManageTaskLifecycle) {
if (!viewerContext.canOperateKuaishouIndustryVoucher) {
throw createHttpError('当前账号没有权限重发电子凭证发码回调', {
statusCode: 403,
errorCode: 'admin_task_kuaishou_industry_resend_forbidden',
@@ -446,7 +446,7 @@ export async function resendAdminOrderKuaishouIndustryVoucherCodes(
const viewerContext = createAdminViewerContext(session)
const now = nowIso()
if (!viewerContext.canManageTaskLifecycle) {
if (!viewerContext.canOperateKuaishouIndustryVoucher) {
throw createHttpError('当前账号没有权限重发电子凭证发码回调', {
statusCode: 403,
errorCode: 'admin_order_kuaishou_industry_resend_forbidden',
@@ -519,7 +519,7 @@ export async function consumeAdminTaskKuaishouIndustryVoucher(
const now = nowIso()
const viewerContext = createAdminViewerContext(session)
if (!viewerContext.canManageTaskLifecycle) {
if (!viewerContext.canOperateKuaishouIndustryVoucher) {
throw createHttpError('当前账号没有权限执行电子凭证核销', {
statusCode: 403,
errorCode: 'admin_task_kuaishou_industry_consume_forbidden',