metis-desk/modules/resources/src/api/application/resource-global-gates.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-10-24 23:19:17 +00:00
import { z } from "zod/v4";
import type { ResourcePurpose } from "../../common";
/** R2.5 mantiene gates independientes para software y perfiles. */
export const ResourceGlobalGatesSchema = z.strictObject({
operatingSystemCatalog: z.boolean().optional(),
operatingSystemSoftware: z.boolean().optional(),
2026-10-24 23:19:17 +00:00
catalog: z.boolean(),
administration: z.boolean(),
mixedSelection: z.boolean(),
software: z.boolean(),
profile: z.boolean(),
});
export const resourceGlobalGates = Object.freeze(
ResourceGlobalGatesSchema.parse({
catalog: false,
administration: true,
mixedSelection: false,
software: false,
profile: false,
})
);
export function globalResourcePurposeEnabled(
purpose: ResourcePurpose,
gates = resourceGlobalGates,
kind: "application" | "os" = "application"
2026-10-24 23:19:17 +00:00
): boolean {
if (kind === "os") {
return (
purpose === "software-installation" &&
Boolean(gates.operatingSystemCatalog && gates.operatingSystemSoftware)
);
}
2026-10-24 23:19:17 +00:00
const consumer = purpose === "software-installation" ? gates.software : gates.profile;
return gates.catalog && consumer;
}
export type ResourceGlobalGates = z.infer<typeof ResourceGlobalGatesSchema>;