diff --git a/cypress/integration/all/app/policiesflow.spec.ts b/cypress/integration/all/app/policiesflow.spec.ts index 4dfad51c23..d360707a79 100644 --- a/cypress/integration/all/app/policiesflow.spec.ts +++ b/cypress/integration/all/app/policiesflow.spec.ts @@ -42,6 +42,19 @@ describe("Policies flow (empty)", () => { cy.findByText(/add a policy/i).click(); }); cy.findByText(/gatekeeper enabled/i).click(); + cy.getAttached(".platforms-select") + .children() + .first() + .within(() => { + cy.getAttached('[type="checkbox"]').should("be.checked"); + }); + cy.getAttached(".platforms-select") + .children() + .first() + .next() + .within(() => { + cy.getAttached('[type="checkbox"]').should("not.be.checked"); + }); cy.findByRole("button", { name: /save policy/i }).click(); cy.findByRole("button", { name: /^Save$/ }).click(); diff --git a/frontend/pages/policies/PolicyPage/components/PolicyForm/PolicyForm.tsx b/frontend/pages/policies/PolicyPage/components/PolicyForm/PolicyForm.tsx index 08021f7187..3b990a98a7 100644 --- a/frontend/pages/policies/PolicyPage/components/PolicyForm/PolicyForm.tsx +++ b/frontend/pages/policies/PolicyPage/components/PolicyForm/PolicyForm.tsx @@ -13,6 +13,7 @@ import { AppContext } from "context/app"; import { PolicyContext } from "context/policy"; import { IPolicy, IPolicyFormData } from "interfaces/policy"; import { IQueryPlatform } from "interfaces/query"; +import { DEFAULT_POLICIES } from "utilities/constants"; import Avatar from "components/Avatar"; import FleetAce from "components/FleetAce"; @@ -131,6 +132,10 @@ const PolicyForm = ({ const isEditMode = !!policyIdForEdit && !isTeamObserver && !isGlobalObserver; + const isNewTemplatePolicy = + !policyIdForEdit && + DEFAULT_POLICIES.find((p) => p.name === lastEditedQueryName); + const hasSavePermissions = isGlobalAdmin || isGlobalMaintainer || isTeamAdmin || isTeamMaintainer; @@ -154,7 +159,7 @@ const PolicyForm = ({ enableLinking: true, }); - if (policyIdForEdit) { + if (policyIdForEdit || isNewTemplatePolicy) { setIsWindowsCompatible(!!lastEditedQueryPlatform?.includes("windows")); setIsDarwinCompatible(!!lastEditedQueryPlatform?.includes("darwin")); setIsLinuxCompatible(!!lastEditedQueryPlatform?.includes("linux"));