fix: preserve explicit assist ticket and reject ambiguous recipients
This commit is contained in:
1 parent
3597ec6694
commit
6ce83dd8a7
7 files changed
+339
-56
No files matched your search
@@ -13,10 +13,8 @@ export async function handleApprove(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const explicitCorpId =
|
||||
stringOption(parsed.options, ["corp", "corpid", "id"]) ||
|
||||
parsed.args[0] ||
|
||||
runtime.selectedCorp?.id;
|
||||
const corpOption = stringOption(parsed.options, ["corp", "corpid", "id"]);
|
||||
const explicitCorpId = corpOption || parsed.args[0] || runtime.selectedCorp?.id;
|
||||
|
||||
if (!explicitCorpId) {
|
||||
return {
|
||||
@@ -31,22 +29,38 @@ export async function handleApprove(
|
||||
|
||||
// 1. 识别 corpId 与 ticketId
|
||||
const allCorps = runtime.corpContext?.getAllCorps?.() || [];
|
||||
let targetCorp =
|
||||
allCorps.find((c) => c.id === explicitCorpId || c.corpId === explicitCorpId) ||
|
||||
(runtime.selectedCorp?.id === explicitCorpId || runtime.selectedCorp?.corpId === explicitCorpId
|
||||
const findCorp = (id: string) =>
|
||||
allCorps.find((c) => c.id === id || c.corpId === id) ||
|
||||
(runtime.selectedCorp?.id === id || runtime.selectedCorp?.corpId === id
|
||||
? runtime.selectedCorp
|
||||
: undefined);
|
||||
|
||||
let ticketId = stringOption(parsed.options, ["ticket", "ticket-id"]);
|
||||
let targetCorp = findCorp(explicitCorpId);
|
||||
const ticketOption = stringOption(parsed.options, ["ticket", "ticket-id"]);
|
||||
let positionalTicketId: string | undefined;
|
||||
|
||||
// 如果第 0 个参数不是企业,可能是工单编号
|
||||
if (!targetCorp && parsed.args[0]) {
|
||||
ticketId = parsed.args[0];
|
||||
if (corpOption) {
|
||||
// 显式企业选项下,唯一位置参数始终是工单,不能被本地企业命中结果覆盖。
|
||||
positionalTicketId = parsed.args[0];
|
||||
} else if (!targetCorp && parsed.args[0]) {
|
||||
positionalTicketId = parsed.args[0];
|
||||
targetCorp = runtime.selectedCorp ?? undefined;
|
||||
} else if (targetCorp && parsed.args[1]) {
|
||||
ticketId = parsed.args[1];
|
||||
positionalTicketId = parsed.args[1];
|
||||
}
|
||||
|
||||
const maxArgs = !corpOption && parsed.args[0] && findCorp(parsed.args[0]) ? 2 : 1;
|
||||
if (parsed.args.length > maxArgs ||
|
||||
(ticketOption && positionalTicketId && ticketOption !== positionalTicketId)) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "[ERROR] 企业或工单参数存在歧义或冲突。请使用 approve <工单ID> --corp <企业ID>,且 --ticket 必须与位置工单一致。\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
let ticketId = ticketOption || positionalTicketId;
|
||||
|
||||
if (!targetCorp) {
|
||||
return {
|
||||
stdout: "",
|
||||
|
||||
@@ -86,20 +86,11 @@ export async function handleTransfer(
|
||||
try {
|
||||
resolvedRecipient = await resolveTransferRecipient(client, targetRecipient);
|
||||
} catch (err) {
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
resolvedRecipient = {
|
||||
id: targetRecipient,
|
||||
name: targetRecipient,
|
||||
userRoleId: "",
|
||||
roles: [],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] ${err instanceof Error ? err.message : String(err)}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] ${err instanceof Error ? err.message : String(err)}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (!ticketId) {
|
||||
@@ -136,7 +127,7 @@ export async function handleTransfer(
|
||||
parsed,
|
||||
runtime,
|
||||
operation,
|
||||
`hose-use assist-platform transfer ${targetCorpId} ${ticketId} --to "${resolvedRecipient.name}" --yes`
|
||||
`hose-use assist-platform transfer ${targetCorpId} ${ticketId} --to "${resolvedRecipient.id}" --yes`
|
||||
);
|
||||
|
||||
const result = await transferAssistTicket(client, {
|
||||
|
||||
Reference in new issue
Block a user