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:
parent
97641e51cb
commit
a473a0b07f
6 changed files with 48 additions and 15 deletions
|
@ -45,11 +45,7 @@ describe("Clients SAML tests", () => {
|
|||
});
|
||||
|
||||
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.wait("@load");
|
||||
|
||||
cy.findByTestId("forceNameIdFormat").click({
|
||||
force: true,
|
||||
|
@ -142,6 +138,9 @@ describe("Clients SAML tests", () => {
|
|||
it("Should update the resource server settings", () => {
|
||||
listingPage.searchItem(clientName).goToItemDetails(clientName);
|
||||
authenticationTab.goToTab();
|
||||
authenticationTab.setPolicy("DISABLED").saveSettings();
|
||||
|
||||
masthead.checkNotificationMessage("Resource successfully updated");
|
||||
});
|
||||
|
||||
it("Should create a resource", () => {
|
||||
|
|
|
@ -36,11 +36,21 @@ export default class AuthenticationTab {
|
|||
return this;
|
||||
}
|
||||
|
||||
setPolicy(policyName: string) {
|
||||
cy.findByTestId(policyName).click();
|
||||
return this;
|
||||
}
|
||||
|
||||
save() {
|
||||
cy.findByTestId("save").click();
|
||||
return this;
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
cy.findByTestId("authenticationSettingsSave").click();
|
||||
return this;
|
||||
}
|
||||
|
||||
pressCancel() {
|
||||
cy.findAllByTestId("cancel").click();
|
||||
return this;
|
||||
|
|
|
@ -361,7 +361,7 @@ export default function ClientDetails() {
|
|||
/>
|
||||
<PageSection variant="light" className="pf-u-p-0">
|
||||
<FormProvider {...form}>
|
||||
<KeycloakTabs data-testid="client-tabs" isBox>
|
||||
<KeycloakTabs data-testid="client-tabs" isBox mountOnEnter>
|
||||
<Tab
|
||||
id="settings"
|
||||
eventKey="settings"
|
||||
|
@ -467,6 +467,8 @@ export default function ClientDetails() {
|
|||
<Tabs
|
||||
activeKey={authorizationSubTab}
|
||||
onSelect={(_, key) => setAuthorizationSubTab(key as number)}
|
||||
mountOnEnter
|
||||
unmountOnExit
|
||||
>
|
||||
<Tab
|
||||
id="settings"
|
||||
|
|
|
@ -115,7 +115,7 @@ export default function ResourceDetails() {
|
|||
AlertVariant.success
|
||||
);
|
||||
} catch (error) {
|
||||
addError("client:resourceSaveError", error);
|
||||
addError("clients:resourceSaveError", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import React, { useState } from "react";
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import {
|
||||
AlertVariant,
|
||||
Button,
|
||||
Divider,
|
||||
FormGroup,
|
||||
|
@ -18,6 +19,7 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|||
import { SaveReset } from "../advanced/SaveReset";
|
||||
import { ImportDialog } from "./ImportDialog";
|
||||
import useToggle from "../../utils/useToggle";
|
||||
import { useAlerts } from "../../components/alert/Alerts";
|
||||
|
||||
const POLICY_ENFORCEMENT_MODES = [
|
||||
"ENFORCING",
|
||||
|
@ -31,11 +33,13 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
|
|||
const [resource, setResource] = useState<ResourceServerRepresentation>();
|
||||
const [importDialog, toggleImportDialog] = useToggle();
|
||||
|
||||
const { control, reset } = useForm<ResourceServerRepresentation>({
|
||||
const { control, reset, handleSubmit } =
|
||||
useForm<ResourceServerRepresentation>({
|
||||
shouldUnregister: false,
|
||||
});
|
||||
|
||||
const adminClient = useAdminClient();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
|
||||
useFetch(
|
||||
() => adminClient.clients.getResourceServer({ id: clientId }),
|
||||
|
@ -46,8 +50,26 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
|
|||
[]
|
||||
);
|
||||
|
||||
const importResource = () => {
|
||||
//different PR
|
||||
const importResource = async (value: ResourceServerRepresentation) => {
|
||||
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) {
|
||||
|
@ -174,10 +196,8 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
|
|||
/>
|
||||
</FormGroup>
|
||||
<SaveReset
|
||||
name="settings"
|
||||
save={(): void => {
|
||||
// another PR
|
||||
}}
|
||||
name="authenticationSettings"
|
||||
save={() => handleSubmit(save)()}
|
||||
reset={() => reset(resource)}
|
||||
/>
|
||||
</FormAccess>
|
||||
|
|
|
@ -64,6 +64,8 @@ export default {
|
|||
importResources: "The following settings and data will be imported:",
|
||||
importWarning:
|
||||
"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",
|
||||
createResourceBasedPermission: "Create resource-based permission",
|
||||
displayName: "Display name",
|
||||
|
|
Loading…
Reference in a new issue