Realm settings(Client policies -> policies): Add switch for enabling/disabling policy (#1495)
* add switch for enabling/disabling policy fix tests * testing duplicate policy test with added wait * unskip tests * ccomment out JSON policies test
This commit is contained in:
parent
fef9f4f052
commit
c8d4effb34
4 changed files with 97 additions and 31 deletions
|
@ -602,10 +602,10 @@ describe("Realm settings tests", () => {
|
||||||
realmSettingsPage.shouldNavigateBetweenFormAndJSONViewPolicies();
|
realmSettingsPage.shouldNavigateBetweenFormAndJSONViewPolicies();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* it("Check saving changed JSON policies", () => {
|
/* it("Check saving changed JSON policies", () => {
|
||||||
realmSettingsPage.shouldSaveChangedJSONPolicies();
|
realmSettingsPage.shouldSaveChangedJSONPolicies();
|
||||||
realmSettingsPage.shouldDeleteClientPolicyDialog();
|
realmSettingsPage.shouldDeleteClientPolicyDialog();
|
||||||
}); */
|
}); */
|
||||||
|
|
||||||
it("Should not create duplicate client profile", () => {
|
it("Should not create duplicate client profile", () => {
|
||||||
realmSettingsPage.shouldCompleteAndCreateNewClientPolicyFromEmptyState();
|
realmSettingsPage.shouldCompleteAndCreateNewClientPolicyFromEmptyState();
|
||||||
|
@ -615,7 +615,7 @@ describe("Realm settings tests", () => {
|
||||||
cy.findByTestId("rs-policies-clientPolicies-tab").click();
|
cy.findByTestId("rs-policies-clientPolicies-tab").click();
|
||||||
realmSettingsPage.shouldCompleteAndCreateNewClientPolicy();
|
realmSettingsPage.shouldCompleteAndCreateNewClientPolicy();
|
||||||
realmSettingsPage.shouldNotCreateDuplicateClientPolicy();
|
realmSettingsPage.shouldNotCreateDuplicateClientPolicy();
|
||||||
|
cy.wait(200);
|
||||||
sidebarPage.goToRealmSettings();
|
sidebarPage.goToRealmSettings();
|
||||||
cy.findByTestId("rs-clientPolicies-tab").click();
|
cy.findByTestId("rs-clientPolicies-tab").click();
|
||||||
cy.findByTestId("rs-policies-clientPolicies-tab").click();
|
cy.findByTestId("rs-policies-clientPolicies-tab").click();
|
||||||
|
|
|
@ -951,6 +951,7 @@ export default class RealmSettingsPage {
|
||||||
);
|
);
|
||||||
cy.findByTestId(this.saveNewClientPolicyBtn).click();
|
cy.findByTestId(this.saveNewClientPolicyBtn).click();
|
||||||
cy.get(this.alertMessage).should("be.visible", "New client policy created");
|
cy.get(this.alertMessage).should("be.visible", "New client policy created");
|
||||||
|
cy.wait(200);
|
||||||
cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click();
|
cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click();
|
||||||
cy.findByTestId("deleteClientPolicyDropdown").click();
|
cy.findByTestId("deleteClientPolicyDropdown").click();
|
||||||
cy.findByTestId("modalConfirm").contains("Delete").click();
|
cy.findByTestId("modalConfirm").contains("Delete").click();
|
||||||
|
|
|
@ -22,7 +22,7 @@ import {
|
||||||
ValidatedOptions,
|
ValidatedOptions,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { FormAccess } from "../components/form-access/FormAccess";
|
import { FormAccess } from "../components/form-access/FormAccess";
|
||||||
import { ViewHeader } from "../components/view-header/ViewHeader";
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
||||||
import { Link, useHistory, useParams } from "react-router-dom";
|
import { Link, useHistory, useParams } from "react-router-dom";
|
||||||
|
@ -96,6 +96,72 @@ export default function NewClientPolicyForm() {
|
||||||
|
|
||||||
const formValues = form.getValues();
|
const formValues = form.getValues();
|
||||||
|
|
||||||
|
type ClientPoliciesHeaderProps = {
|
||||||
|
onChange: (value: boolean) => void;
|
||||||
|
value: boolean;
|
||||||
|
save: () => void;
|
||||||
|
realmName: string;
|
||||||
|
refresh: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ClientPoliciesHeader = ({
|
||||||
|
save,
|
||||||
|
onChange,
|
||||||
|
value,
|
||||||
|
}: ClientPoliciesHeaderProps) => {
|
||||||
|
const { t } = useTranslation("realm-settings");
|
||||||
|
|
||||||
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
||||||
|
titleKey: "realm-settings:disablePolicyConfirmTitle",
|
||||||
|
messageKey: "realm-settings:disablePolicyConfirm",
|
||||||
|
continueButtonLabel: "common:disable",
|
||||||
|
onConfirm: () => {
|
||||||
|
onChange(!value);
|
||||||
|
save();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DisableConfirm />
|
||||||
|
<DeleteConfirm />
|
||||||
|
<ViewHeader
|
||||||
|
titleKey={
|
||||||
|
showAddConditionsAndProfilesForm || policyName
|
||||||
|
? formValues.name!
|
||||||
|
: t("createPolicy")
|
||||||
|
}
|
||||||
|
divider
|
||||||
|
dropdownItems={
|
||||||
|
showAddConditionsAndProfilesForm || policyName
|
||||||
|
? [
|
||||||
|
<DropdownItem
|
||||||
|
key="delete"
|
||||||
|
value="delete"
|
||||||
|
onClick={() => {
|
||||||
|
toggleDeleteDialog();
|
||||||
|
}}
|
||||||
|
data-testid="deleteClientPolicyDropdown"
|
||||||
|
>
|
||||||
|
{t("deleteClientPolicy")}
|
||||||
|
</DropdownItem>,
|
||||||
|
]
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
isEnabled={value}
|
||||||
|
onToggle={(value) => {
|
||||||
|
if (!value) {
|
||||||
|
toggleDisableDialog();
|
||||||
|
} else {
|
||||||
|
onChange(value);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useFetch(
|
useFetch(
|
||||||
async () => {
|
async () => {
|
||||||
const [policies, profiles] = await Promise.all([
|
const [policies, profiles] = await Promise.all([
|
||||||
|
@ -176,7 +242,9 @@ export default function NewClientPolicyForm() {
|
||||||
policies: getAllPolicies(),
|
policies: getAllPolicies(),
|
||||||
});
|
});
|
||||||
addAlert(
|
addAlert(
|
||||||
t("realm-settings:createClientPolicySuccess"),
|
policyName
|
||||||
|
? t("realm-settings:updateClientPolicySuccess")
|
||||||
|
: t("realm-settings:createClientPolicySuccess"),
|
||||||
AlertVariant.success
|
AlertVariant.success
|
||||||
);
|
);
|
||||||
history.push(
|
history.push(
|
||||||
|
@ -299,6 +367,10 @@ export default function NewClientPolicyForm() {
|
||||||
form.setValue("description", currentPolicy?.description);
|
form.setValue("description", currentPolicy?.description);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const refreshHeader = () => {
|
||||||
|
setKey(new Date().getTime());
|
||||||
|
};
|
||||||
|
|
||||||
const toggleModal = () => {
|
const toggleModal = () => {
|
||||||
setProfilesModalOpen(!profilesModalOpen);
|
setProfilesModalOpen(!profilesModalOpen);
|
||||||
};
|
};
|
||||||
|
@ -343,7 +415,6 @@ export default function NewClientPolicyForm() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DeleteConfirm />
|
|
||||||
<DeleteConditionConfirm />
|
<DeleteConditionConfirm />
|
||||||
<DeleteProfileConfirm />
|
<DeleteProfileConfirm />
|
||||||
<AddClientProfileModal
|
<AddClientProfileModal
|
||||||
|
@ -354,29 +425,19 @@ export default function NewClientPolicyForm() {
|
||||||
open={profilesModalOpen}
|
open={profilesModalOpen}
|
||||||
toggleDialog={toggleModal}
|
toggleDialog={toggleModal}
|
||||||
/>
|
/>
|
||||||
<ViewHeader
|
<Controller
|
||||||
titleKey={
|
name="enabled"
|
||||||
showAddConditionsAndProfilesForm || policyName
|
defaultValue={true}
|
||||||
? formValues.name!
|
control={form.control}
|
||||||
: t("createPolicy")
|
render={({ onChange, value }) => (
|
||||||
}
|
<ClientPoliciesHeader
|
||||||
divider
|
value={value}
|
||||||
dropdownItems={
|
onChange={onChange}
|
||||||
showAddConditionsAndProfilesForm || policyName
|
realmName={realm}
|
||||||
? [
|
refresh={refreshHeader}
|
||||||
<DropdownItem
|
save={save}
|
||||||
key="delete"
|
/>
|
||||||
value="delete"
|
)}
|
||||||
onClick={() => {
|
|
||||||
toggleDeleteDialog();
|
|
||||||
}}
|
|
||||||
data-testid="deleteClientPolicyDropdown"
|
|
||||||
>
|
|
||||||
{t("deleteClientPolicy")}
|
|
||||||
</DropdownItem>,
|
|
||||||
]
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<PageSection variant="light">
|
<PageSection variant="light">
|
||||||
<FormAccess
|
<FormAccess
|
||||||
|
|
|
@ -18,6 +18,9 @@ export default {
|
||||||
disableConfirmTitle: "Disable realm?",
|
disableConfirmTitle: "Disable realm?",
|
||||||
disableConfirm:
|
disableConfirm:
|
||||||
"User and clients can't access the realm if it's disabled. Are you sure you want to continue?",
|
"User and clients can't access the realm if it's disabled. Are you sure you want to continue?",
|
||||||
|
disablePolicyConfirmTitle: "Disable policy?",
|
||||||
|
disablePolicyConfirm:
|
||||||
|
"Users and clients can't access the policy if it's disabled. Are you sure you want to continue?",
|
||||||
editProvider: "Edit provider",
|
editProvider: "Edit provider",
|
||||||
saveSuccess: "Realm successfully updated",
|
saveSuccess: "Realm successfully updated",
|
||||||
saveProviderSuccess: "The provider has been saved successfully.",
|
saveProviderSuccess: "The provider has been saved successfully.",
|
||||||
|
@ -198,6 +201,7 @@ export default {
|
||||||
createPolicy: "Create policy",
|
createPolicy: "Create policy",
|
||||||
createClientPolicy: "Create client policy",
|
createClientPolicy: "Create client policy",
|
||||||
createClientPolicySuccess: "New policy created",
|
createClientPolicySuccess: "New policy created",
|
||||||
|
updateClientPolicySuccess: "Client policy updated",
|
||||||
createClientConditionSuccess: "Condition created successfully.",
|
createClientConditionSuccess: "Condition created successfully.",
|
||||||
createClientConditionError: "Error creating condition: {{error}}",
|
createClientConditionError: "Error creating condition: {{error}}",
|
||||||
updateClientConditionSuccess: "Condition updated successfully.",
|
updateClientConditionSuccess: "Condition updated successfully.",
|
||||||
|
|
Loading…
Reference in a new issue