Hide certain elements on the page if client is a realm (#1245)

This commit is contained in:
Jon Koops 2021-09-28 17:14:49 +02:00 committed by GitHub
parent cfe83c769b
commit b9d1dbff4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 44 deletions

View file

@ -226,4 +226,36 @@ describe("Clients test", function () {
); );
}); });
}); });
describe("Realm client", () => {
const clientName = "master-realm";
beforeEach(() => {
keycloakBefore();
loginPage.logIn();
sidebarPage.goToClients();
listingPage.searchItem(clientName).goToItemDetails(clientName);
});
it("displays the correct tabs", () => {
cy.findByTestId("client-tabs")
.find("#pf-tab-settings-settings")
.should("exist");
cy.findByTestId("client-tabs")
.find("#pf-tab-roles-roles")
.should("exist");
cy.findByTestId("client-tabs")
.find("#pf-tab-advanced-advanced")
.should("exist");
cy.findByTestId("client-tabs").find("li").should("have.length", 3);
});
it("hides the delete action", () => {
cy.findByTestId("action-dropdown").click();
cy.findByTestId("delete-client").should("not.exist");
});
});
}); });

View file

@ -53,6 +53,8 @@ import { ClientScopes } from "./scopes/ClientScopes";
import { EvaluateScopes } from "./scopes/EvaluateScopes"; import { EvaluateScopes } from "./scopes/EvaluateScopes";
import { ServiceAccount } from "./service-account/ServiceAccount"; import { ServiceAccount } from "./service-account/ServiceAccount";
const isRealmClient = (client: ClientRepresentation) => !client.protocol;
type ClientDetailHeaderProps = { type ClientDetailHeaderProps = {
onChange: (value: boolean) => void; onChange: (value: boolean) => void;
value: boolean; value: boolean;
@ -97,6 +99,27 @@ const ClientDetailHeader = ({
return [{ text }]; return [{ text }];
}, [client]); }, [client]);
const dropdownItems = [
<DropdownItem key="download" onClick={() => toggleDownloadDialog()}>
{t("downloadAdapterConfig")}
</DropdownItem>,
<DropdownItem key="export" onClick={() => exportClient(client)}>
{t("common:export")}
</DropdownItem>,
...(!isRealmClient(client)
? [
<Divider key="divider" />,
<DropdownItem
data-testid="delete-client"
key="delete"
onClick={() => toggleDeleteDialog()}
>
{t("common:delete")}
</DropdownItem>,
]
: []),
];
return ( return (
<> <>
<DisableConfirm /> <DisableConfirm />
@ -106,18 +129,7 @@ const ClientDetailHeader = ({
badges={badges} badges={badges}
divider={false} divider={false}
helpTextKey="clients-help:enableDisable" helpTextKey="clients-help:enableDisable"
dropdownItems={[ dropdownItems={dropdownItems}
<DropdownItem key="download" onClick={() => toggleDownloadDialog()}>
{t("downloadAdapterConfig")}
</DropdownItem>,
<DropdownItem key="export" onClick={() => exportClient(client)}>
{t("common:export")}
</DropdownItem>,
<Divider key="divider" />,
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
{t("common:delete")}
</DropdownItem>,
]}
isEnabled={value} isEnabled={value}
onToggle={(value) => { onToggle={(value) => {
if (!value) { if (!value) {
@ -262,6 +274,7 @@ export const ClientDetails = () => {
</div> </div>
); );
} }
return ( return (
<> <>
<ConfirmDialogModal <ConfirmDialogModal
@ -306,7 +319,7 @@ export const ClientDetails = () => {
/> />
<PageSection variant="light" className="pf-u-p-0"> <PageSection variant="light" className="pf-u-p-0">
<FormProvider {...form}> <FormProvider {...form}>
<KeycloakTabs isBox> <KeycloakTabs data-testid="client-tabs" isBox>
<Tab <Tab
id="settings" id="settings"
eventKey="settings" eventKey="settings"
@ -317,7 +330,7 @@ export const ClientDetails = () => {
reset={() => setupForm(client)} reset={() => setupForm(client)}
/> />
</Tab> </Tab>
{!client.publicClient && ( {!client.publicClient && !isRealmClient(client) && (
<Tab <Tab
id="keys" id="keys"
eventKey="keys" eventKey="keys"
@ -326,7 +339,7 @@ export const ClientDetails = () => {
<Keys clientId={clientId} save={() => save()} /> <Keys clientId={clientId} save={() => save()} />
</Tab> </Tab>
)} )}
{!client.publicClient && ( {!client.publicClient && !isRealmClient(client) && (
<Tab <Tab
id="credentials" id="credentials"
eventKey="credentials" eventKey="credentials"
@ -346,6 +359,7 @@ export const ClientDetails = () => {
messageBundle="clients" messageBundle="clients"
/> />
</Tab> </Tab>
{!isRealmClient(client) && (
<Tab <Tab
id="clientScopes" id="clientScopes"
eventKey="clientScopes" eventKey="clientScopes"
@ -377,6 +391,7 @@ export const ClientDetails = () => {
</Tab> </Tab>
</Tabs> </Tabs>
</Tab> </Tab>
)}
{client!.serviceAccountsEnabled && ( {client!.serviceAccountsEnabled && (
<Tab <Tab
id="serviceAccount" id="serviceAccount"