From c2ee68cf597e0c710b35626a12c4de59ce37189a Mon Sep 17 00:00:00 2001 From: gillespi314 <73313222+gillespi314@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:34:14 -0600 Subject: [PATCH] Set initial platform values for template policies (#4435) --- cypress/integration/all/app/policiesflow.spec.ts | 13 +++++++++++++ .../PolicyPage/components/PolicyForm/PolicyForm.tsx | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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"));