Set initial platform values for template policies (#4435)

This commit is contained in:
gillespi314 2022-03-03 14:34:14 -06:00 committed by GitHub
parent 1db1ab933d
commit c2ee68cf59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -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();

View File

@ -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"));