feat: 新增租户 active 状态与统一禁用闸门
This commit is contained in:
1 parent
634f0e2b78
commit
0ff3d9a313
21 files changed
+855
-14
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { updateCorpConfig } from "../../../core/config/loader.js";
|
||||
import { confirmationRequired, usageError } from "../../../core/errors.js";
|
||||
import { booleanOption, dryRunOption, stringOption } from "../../parser.js";
|
||||
import { printJson } from "../../printer.js";
|
||||
import type { ParsedArgs } from "../../types.js";
|
||||
|
||||
/**
|
||||
* Tenant availability switch for both `hose` and `seal` sources.
|
||||
*
|
||||
* This is the ONLY command surface allowed to resolve a disabled tenant: without
|
||||
* it, `corps enable` could not restore an enterprise that the gate now blocks.
|
||||
* All other commands resolve through `selectCorp()` and are refused upstream.
|
||||
*/
|
||||
export async function handleCorpActive(
|
||||
action: string | undefined,
|
||||
maybeName: string | undefined,
|
||||
args: ParsedArgs
|
||||
): Promise<boolean> {
|
||||
if (action !== "disable" && action !== "enable") return false;
|
||||
|
||||
const corpId = maybeName ?? stringOption(args.options.corp);
|
||||
if (!corpId) {
|
||||
throw usageError(`Usage: seal-use corps ${action} <corpId> [--dry-run] [--confirm]`);
|
||||
}
|
||||
|
||||
const targetActive = action === "enable";
|
||||
const { selectCorp } = await import("../../helpers.js");
|
||||
const corp = selectCorp(corpId, { allowDisabled: true });
|
||||
const previousActive = corp.active ?? true;
|
||||
|
||||
if (dryRunOption(args)) {
|
||||
printJson({
|
||||
preview: true,
|
||||
dryRun: true,
|
||||
mutation: `corps ${action}`,
|
||||
corpId: corp.id,
|
||||
corpName: corp.name,
|
||||
sourceType: corp.source.type,
|
||||
changesDiff: { before: previousActive, after: targetActive },
|
||||
note: "禁用只阻断显式指定该企业 ID 的命令,不影响 corps list/search 的检索可见性。"
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const confirmed = booleanOption(args.options.confirm) === true || booleanOption(args.options.yes) === true;
|
||||
if (!confirmed) {
|
||||
throw confirmationRequired(
|
||||
`Refusing to ${action} enterprise '${corp.name}' (${corp.id}) without --confirm.`,
|
||||
`seal-use corps ${action} ${corp.id} --confirm`
|
||||
);
|
||||
}
|
||||
|
||||
const updated = updateCorpConfig(corp.id, { active: targetActive });
|
||||
printJson({
|
||||
success: true,
|
||||
id: updated.id,
|
||||
name: updated.name,
|
||||
sourceType: updated.source.type,
|
||||
active: updated.active,
|
||||
previousActive
|
||||
});
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user