added import and save functions to resource tab (#1676)

* added import and save functions to resource tab

* added test

* fixed the test
This commit is contained in:
Erik Jan de Wit 2021-12-16 17:31:17 +01:00 committed by GitHub
parent 97641e51cb
commit a473a0b07f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 15 deletions

View file

@ -45,11 +45,7 @@ describe("Clients SAML tests", () => {
}); });
it("should save force name id format", () => { it("should save force name id format", () => {
const load = "auth/admin/realms/master/client-scopes";
cy.intercept(load).as("load");
cy.get(".pf-c-jump-links__list").contains("SAML capabilities").click(); cy.get(".pf-c-jump-links__list").contains("SAML capabilities").click();
cy.wait("@load");
cy.findByTestId("forceNameIdFormat").click({ cy.findByTestId("forceNameIdFormat").click({
force: true, force: true,
@ -142,6 +138,9 @@ describe("Clients SAML tests", () => {
it("Should update the resource server settings", () => { it("Should update the resource server settings", () => {
listingPage.searchItem(clientName).goToItemDetails(clientName); listingPage.searchItem(clientName).goToItemDetails(clientName);
authenticationTab.goToTab(); authenticationTab.goToTab();
authenticationTab.setPolicy("DISABLED").saveSettings();
masthead.checkNotificationMessage("Resource successfully updated");
}); });
it("Should create a resource", () => { it("Should create a resource", () => {

View file

@ -36,11 +36,21 @@ export default class AuthenticationTab {
return this; return this;
} }
setPolicy(policyName: string) {
cy.findByTestId(policyName).click();
return this;
}
save() { save() {
cy.findByTestId("save").click(); cy.findByTestId("save").click();
return this; return this;
} }
saveSettings() {
cy.findByTestId("authenticationSettingsSave").click();
return this;
}
pressCancel() { pressCancel() {
cy.findAllByTestId("cancel").click(); cy.findAllByTestId("cancel").click();
return this; return this;

View file

@ -361,7 +361,7 @@ export default function ClientDetails() {
/> />
<PageSection variant="light" className="pf-u-p-0"> <PageSection variant="light" className="pf-u-p-0">
<FormProvider {...form}> <FormProvider {...form}>
<KeycloakTabs data-testid="client-tabs" isBox> <KeycloakTabs data-testid="client-tabs" isBox mountOnEnter>
<Tab <Tab
id="settings" id="settings"
eventKey="settings" eventKey="settings"
@ -467,6 +467,8 @@ export default function ClientDetails() {
<Tabs <Tabs
activeKey={authorizationSubTab} activeKey={authorizationSubTab}
onSelect={(_, key) => setAuthorizationSubTab(key as number)} onSelect={(_, key) => setAuthorizationSubTab(key as number)}
mountOnEnter
unmountOnExit
> >
<Tab <Tab
id="settings" id="settings"

View file

@ -115,7 +115,7 @@ export default function ResourceDetails() {
AlertVariant.success AlertVariant.success
); );
} catch (error) { } catch (error) {
addError("client:resourceSaveError", error); addError("clients:resourceSaveError", error);
} }
}; };

View file

@ -2,6 +2,7 @@ import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { import {
AlertVariant,
Button, Button,
Divider, Divider,
FormGroup, FormGroup,
@ -18,6 +19,7 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
import { SaveReset } from "../advanced/SaveReset"; import { SaveReset } from "../advanced/SaveReset";
import { ImportDialog } from "./ImportDialog"; import { ImportDialog } from "./ImportDialog";
import useToggle from "../../utils/useToggle"; import useToggle from "../../utils/useToggle";
import { useAlerts } from "../../components/alert/Alerts";
const POLICY_ENFORCEMENT_MODES = [ const POLICY_ENFORCEMENT_MODES = [
"ENFORCING", "ENFORCING",
@ -31,11 +33,13 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
const [resource, setResource] = useState<ResourceServerRepresentation>(); const [resource, setResource] = useState<ResourceServerRepresentation>();
const [importDialog, toggleImportDialog] = useToggle(); const [importDialog, toggleImportDialog] = useToggle();
const { control, reset } = useForm<ResourceServerRepresentation>({ const { control, reset, handleSubmit } =
useForm<ResourceServerRepresentation>({
shouldUnregister: false, shouldUnregister: false,
}); });
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const { addAlert, addError } = useAlerts();
useFetch( useFetch(
() => adminClient.clients.getResourceServer({ id: clientId }), () => adminClient.clients.getResourceServer({ id: clientId }),
@ -46,8 +50,26 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
[] []
); );
const importResource = () => { const importResource = async (value: ResourceServerRepresentation) => {
//different PR try {
await adminClient.clients.importResource({ id: clientId }, value);
addAlert(t("importResourceSuccess"), AlertVariant.success);
reset({ ...value });
} catch (error) {
addError("clients:importResourceError", error);
}
};
const save = async (resource: ResourceServerRepresentation) => {
try {
await adminClient.clients.updateResourceServer(
{ id: clientId },
resource
);
addAlert(t("updateResourceSuccess"), AlertVariant.success);
} catch (error) {
addError("clients:resourceSaveError", error);
}
}; };
if (!resource) { if (!resource) {
@ -174,10 +196,8 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
/> />
</FormGroup> </FormGroup>
<SaveReset <SaveReset
name="settings" name="authenticationSettings"
save={(): void => { save={() => handleSubmit(save)()}
// another PR
}}
reset={() => reset(resource)} reset={() => reset(resource)}
/> />
</FormAccess> </FormAccess>

View file

@ -64,6 +64,8 @@ export default {
importResources: "The following settings and data will be imported:", importResources: "The following settings and data will be imported:",
importWarning: importWarning:
"The data and settings imported above may overwrite the data and settings that already exist.", "The data and settings imported above may overwrite the data and settings that already exist.",
importResourceSuccess: "The resource was successfully imported",
importResourceError: "Could not import the resource due to {{error}}",
createResource: "Create resource", createResource: "Create resource",
createResourceBasedPermission: "Create resource-based permission", createResourceBasedPermission: "Create resource-based permission",
displayName: "Display name", displayName: "Display name",