add create client policy form; WIP (#1448)

add client policy tests

checkout realm settings test from master

RealmSettingsPage.ts master

remove comment and add missing translation

fix tests

PR feedback from Jon and Erik

rebase

editClientPolicy

edit client policy

add client policy conditions form

fix bug in create form

remove comment

update help text

fixes

breadcrumbs

add support for adding multiple conditions, deleting conditions, and list conditions in data table

clean up names

add delete functionality to conditions form

PR feedback from Jon

useMemo for conditions

remove comments and logs

remove unused hook

add profiles modal wip

addprofiles wip

profiles wip

help text wip

add help text

remove comments

remove duplicate message

update data test id

PR feedback from Jon 1

Apply suggestions from code review

Co-authored-by: Jon Koops <jonkoops@gmail.com>

remove fragment

create policy detail attribute type

PR feedback from Jon 2

support editing profile name and description

add edit functionality and restore tests

Delete EditCondition.ts

Apply suggestions from code review

Co-authored-by: Jon Koops <jonkoops@gmail.com>

format

fix path

use route fn
This commit is contained in:
Jenny 2021-11-02 13:11:04 -04:00 committed by GitHub
parent 25d2e426b6
commit 8e6f6fb40b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 28 deletions

View file

@ -537,7 +537,7 @@ describe("Realm settings tests", () => {
}); });
}); });
describe.skip("Realm settings client policies tab tests", () => { describe("Realm settings client policies tab tests", () => {
beforeEach(() => { beforeEach(() => {
keycloakBefore(); keycloakBefore();
loginPage.logIn(); loginPage.logIn();

View file

@ -171,6 +171,7 @@ export default class RealmSettingsPage {
private jsonEditorReloadBtn = "jsonEditor-reloadBtn"; private jsonEditorReloadBtn = "jsonEditor-reloadBtn";
private jsonEditor = ".monaco-scrollable-element.editor-scrollable.vs"; private jsonEditor = ".monaco-scrollable-element.editor-scrollable.vs";
private createClientDrpDwn = ".pf-c-dropdown.pf-m-align-right"; private createClientDrpDwn = ".pf-c-dropdown.pf-m-align-right";
private clientPolicyDrpDwn = "action-dropdown";
private searchFld = "[id^=realm-settings][id$=profilesinput]"; private searchFld = "[id^=realm-settings][id$=profilesinput]";
private searchFldPolicies = "[id^=realm-settings][id$=clientPoliciesinput]"; private searchFldPolicies = "[id^=realm-settings][id$=clientPoliciesinput]";
private clientProfileOne = 'a[href*="realm-settings/clientPolicies/Test"]'; private clientProfileOne = 'a[href*="realm-settings/clientPolicies/Test"]';
@ -855,7 +856,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.get(this.createClientDrpDwn).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();
cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get(this.alertMessage).should("be.visible", "Client profile deleted");

View file

@ -35,7 +35,7 @@ import "./RealmSettingsSection.css";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { toAddExecutor } from "./routes/AddExecutor"; import { toAddExecutor } from "./routes/AddExecutor";
import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import type { ClientProfileParams } from "./routes/ClientProfile"; import { ClientProfileParams, toClientProfile } from "./routes/ClientProfile";
type ClientProfileForm = Required<ClientProfileRepresentation>; type ClientProfileForm = Required<ClientProfileRepresentation>;
@ -106,7 +106,7 @@ export default function ClientProfileForm() {
AlertVariant.success AlertVariant.success
); );
history.push(`/${realm}/realm-settings/clientPolicies/${form.name}`); history.push(toClientProfile({ realm, profileName: form.name }));
} catch (error) { } catch (error) {
addError( addError(
editMode editMode
@ -159,9 +159,7 @@ export default function ClientProfileForm() {
globalProfiles, globalProfiles,
}); });
addAlert(t("deleteExecutorSuccess"), AlertVariant.success); addAlert(t("deleteExecutorSuccess"), AlertVariant.success);
history.push( history.push(toClientProfile({ realm, profileName }));
`/${realm}/realm-settings/clientPolicies/${profileName}/edit-profile`
);
} catch (error) { } catch (error) {
addError(t("deleteExecutorError"), error); addError(t("deleteExecutorError"), error);
} }

View file

@ -21,7 +21,7 @@ import { useAdminClient, useFetch } from "../context/auth/AdminClient";
import type ComponentTypeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentTypeRepresentation"; import type ComponentTypeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentTypeRepresentation";
import type { ConfigPropertyRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation"; import type { ConfigPropertyRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation";
import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation"; import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation";
import type { ClientProfileParams } from "./routes/ClientProfile"; import { ClientProfileParams, toClientProfile } from "./routes/ClientProfile";
import { import {
COMPONENTS, COMPONENTS,
isValidComponentType, isValidComponentType,
@ -94,9 +94,7 @@ export default function ExecutorForm() {
globalProfiles: globalProfiles, globalProfiles: globalProfiles,
}); });
addAlert(t("realm-settings:addExecutorSuccess"), AlertVariant.success); addAlert(t("realm-settings:addExecutorSuccess"), AlertVariant.success);
history.push( history.push(toClientProfile({ realm, profileName }));
`/${realm}/realm-settings/clientPolicies/${profileName}/edit-profile`
);
} catch (error) { } catch (error) {
addError("realm-settings:addExecutorError", error); addError("realm-settings:addExecutorError", error);
} }
@ -192,10 +190,7 @@ export default function ExecutorForm() {
<Button <Button
variant="link" variant="link"
component={(props) => ( component={(props) => (
<Link <Link {...props} to={toClientProfile({ realm, profileName })} />
{...props}
to={`/${realm}/realm-settings/clientPolicies/${profileName}/edit-profile`}
/>
)} )}
data-testid="addExecutor-cancelBtn" data-testid="addExecutor-cancelBtn"
> >

View file

@ -93,6 +93,8 @@ export default function NewClientPolicyForm() {
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const refresh = () => setKey(new Date().getTime()); const refresh = () => setKey(new Date().getTime());
const formValues = form.getValues();
useFetch( useFetch(
async () => { async () => {
const [policies, profiles] = await Promise.all([ const [policies, profiles] = await Promise.all([
@ -143,8 +145,6 @@ export default function NewClientPolicyForm() {
"org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider" "org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider"
]; ];
const formValues = form.getValues();
const save = async () => { const save = async () => {
const createdForm = form.getValues(); const createdForm = form.getValues();
const createdPolicy = { const createdPolicy = {
@ -153,19 +153,26 @@ export default function NewClientPolicyForm() {
conditions: [], conditions: [],
}; };
const policyNameExists = policies.find( const getAllPolicies = () => {
(policy) => policy.name === createdPolicy.name const policyNameExists = policies.some(
); (policy) => policy.name === createdPolicy.name
);
const res = policies.map((policy) => if (policyNameExists) {
policy.name === createdPolicy.name ? createdPolicy : policy return policies.map((policy) =>
); policy.name === createdPolicy.name ? createdPolicy : policy
);
const allPolicies = policyNameExists ? res : policies.concat(createdForm); } else if (createdForm.name !== policyName) {
return policies
.filter((item) => item.name !== policyName)
.concat(createdForm);
}
return policies.concat(createdForm);
};
try { try {
await adminClient.clientPolicies.updatePolicy({ await adminClient.clientPolicies.updatePolicy({
policies: allPolicies, policies: getAllPolicies(),
}); });
addAlert( addAlert(
t("realm-settings:createClientPolicySuccess"), t("realm-settings:createClientPolicySuccess"),
@ -328,7 +335,6 @@ export default function NewClientPolicyForm() {
t("realm-settings:addClientProfileSuccess"), t("realm-settings:addClientProfileSuccess"),
AlertVariant.success AlertVariant.success
); );
refresh();
} catch (error) { } catch (error) {
addError("realm-settings:addClientProfileError", error); addError("realm-settings:addClientProfileError", error);
} }
@ -350,7 +356,7 @@ export default function NewClientPolicyForm() {
<ViewHeader <ViewHeader
titleKey={ titleKey={
showAddConditionsAndProfilesForm || policyName showAddConditionsAndProfilesForm || policyName
? policyName! ? formValues.name!
: t("createPolicy") : t("createPolicy")
} }
divider divider