Hide permissions tabs when ADMIN_FINE_GRAINED_AUTHZ is disabled. (#3779)

This commit is contained in:
Stan Silvert 2022-11-17 05:18:52 -05:00 committed by GitHub
parent 481fb0da48
commit 612a8444d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 27 deletions

View file

@ -31,6 +31,7 @@ import { GroupRoleMapping } from "./GroupRoleMapping";
import helpUrls from "../help-urls"; import helpUrls from "../help-urls";
import { PermissionsTab } from "../components/permission-tab/PermissionTab"; import { PermissionsTab } from "../components/permission-tab/PermissionTab";
import { useAccess } from "../context/access/Access"; import { useAccess } from "../context/access/Access";
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import { GroupTree } from "./components/GroupTree"; import { GroupTree } from "./components/GroupTree";
import { DeleteGroup } from "./components/DeleteGroup"; import { DeleteGroup } from "./components/DeleteGroup";
import useToggle from "../utils/useToggle"; import useToggle from "../utils/useToggle";
@ -42,6 +43,8 @@ export default function GroupsSection() {
const { t } = useTranslation("groups"); const { t } = useTranslation("groups");
const [activeTab, setActiveTab] = useState(0); const [activeTab, setActiveTab] = useState(0);
const { profileInfo } = useServerInfo();
const { adminClient } = useAdminClient(); const { adminClient } = useAdminClient();
const { subGroups, setSubGroups, currentGroup } = useSubGroups(); const { subGroups, setSubGroups, currentGroup } = useSubGroups();
const { realm } = useRealm(); const { realm } = useRealm();
@ -57,11 +60,9 @@ export default function GroupsSection() {
const refresh = () => setKey(key + 1); const refresh = () => setKey(key + 1);
const { hasAccess } = useAccess(); const { hasAccess } = useAccess();
const canViewPermissions = hasAccess( const canViewPermissions =
"manage-authorization", !profileInfo?.disabledFeatures?.includes("ADMIN_FINE_GRAINED_AUTHZ") &&
"manage-users", hasAccess("manage-authorization", "manage-users", "manage-clients");
"manage-clients"
);
const canManageGroup = const canManageGroup =
hasAccess("manage-users") || currentGroup()?.access?.manage; hasAccess("manage-users") || currentGroup()?.access?.manage;
const canManageRoles = hasAccess("manage-users"); const canManageRoles = hasAccess("manage-users");

View file

@ -28,6 +28,7 @@ import { AdvancedSettings } from "./AdvancedSettings";
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
import { useAlerts } from "../../components/alert/Alerts"; import { useAlerts } from "../../components/alert/Alerts";
import { useRealm } from "../../context/realm-context/RealmContext"; import { useRealm } from "../../context/realm-context/RealmContext";
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
import { KeycloakTabs } from "../../components/keycloak-tabs/KeycloakTabs"; import { KeycloakTabs } from "../../components/keycloak-tabs/KeycloakTabs";
import { ExtendedNonDiscoverySettings } from "./ExtendedNonDiscoverySettings"; import { ExtendedNonDiscoverySettings } from "./ExtendedNonDiscoverySettings";
import { DiscoverySettings } from "./DiscoverySettings"; import { DiscoverySettings } from "./DiscoverySettings";
@ -120,6 +121,7 @@ export default function DetailSettings() {
const navigate = useNavigate(); const navigate = useNavigate();
const { realm } = useRealm(); const { realm } = useRealm();
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const { profileInfo } = useServerInfo();
const refresh = () => setKey(key + 1); const refresh = () => setKey(key + 1);
const MapperLink = ({ name, mapperId }: IdPWithMapperAttributes) => ( const MapperLink = ({ name, mapperId }: IdPWithMapperAttributes) => (
@ -444,14 +446,18 @@ export default function DetailSettings() {
]} ]}
/> />
</Tab> </Tab>
<Tab {!profileInfo?.disabledFeatures?.includes(
id="permissions" "ADMIN_FINE_GRAINED_AUTHZ"
data-testid="permissionsTab" ) && (
eventKey="permissions" <Tab
title={<TabTitleText>{t("common:permissions")}</TabTitleText>} id="permissions"
> data-testid="permissionsTab"
<PermissionsTab id={alias} type="identityProviders" /> eventKey="permissions"
</Tab> title={<TabTitleText>{t("common:permissions")}</TabTitleText>}
>
<PermissionsTab id={alias} type="identityProviders" />
</Tab>
)}
</KeycloakTabs> </KeycloakTabs>
</PageSection> </PageSection>
</FormProvider> </FormProvider>

View file

@ -15,6 +15,7 @@ import { omit } from "lodash-es";
import { useAlerts } from "../components/alert/Alerts"; import { useAlerts } from "../components/alert/Alerts";
import { useAdminClient, useFetch } from "../context/auth/AdminClient"; import { useAdminClient, useFetch } from "../context/auth/AdminClient";
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation"; import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation";
import { import {
AttributesForm, AttributesForm,
@ -61,6 +62,8 @@ export default function RealmRoleTabs() {
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const { profileInfo } = useServerInfo();
const refresh = () => { const refresh = () => {
setKey(key + 1); setKey(key + 1);
}; };
@ -415,12 +418,16 @@ export default function RealmRoleTabs() {
<UsersInRoleTab data-cy="users-in-role-tab" /> <UsersInRoleTab data-cy="users-in-role-tab" />
</Tab> </Tab>
)} )}
<Tab {!profileInfo?.disabledFeatures?.includes(
eventKey="permissions" "ADMIN_FINE_GRAINED_AUTHZ"
title={<TabTitleText>{t("common:permissions")}</TabTitleText>} ) && (
> <Tab
<PermissionsTab id={role.id} type="roles" /> eventKey="permissions"
</Tab> title={<TabTitleText>{t("common:permissions")}</TabTitleText>}
>
<PermissionsTab id={role.id} type="roles" />
</Tab>
)}
</KeycloakTabs> </KeycloakTabs>
)} )}
</PageSection> </PageSection>

View file

@ -34,6 +34,7 @@ import type { IRowData } from "@patternfly/react-table";
import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation"; import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation"; import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import { useAlerts } from "../components/alert/Alerts"; import { useAlerts } from "../components/alert/Alerts";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
@ -69,6 +70,7 @@ export default function UsersSection() {
const [realm, setRealm] = useState<RealmRepresentation | undefined>(); const [realm, setRealm] = useState<RealmRepresentation | undefined>();
const [kebabOpen, setKebabOpen] = useState(false); const [kebabOpen, setKebabOpen] = useState(false);
const [selectedRows, setSelectedRows] = useState<UserRepresentation[]>([]); const [selectedRows, setSelectedRows] = useState<UserRepresentation[]>([]);
const { profileInfo } = useServerInfo();
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const refresh = () => setKey(key + 1); const refresh = () => setKey(key + 1);
@ -411,14 +413,18 @@ export default function UsersSection() {
]} ]}
/> />
</Tab> </Tab>
<Tab {!profileInfo?.disabledFeatures?.includes(
id="permissions" "ADMIN_FINE_GRAINED_AUTHZ"
data-testid="permissionsTab" ) && (
title={<TabTitleText>{t("common:permissions")}</TabTitleText>} <Tab
{...route("permissions")} id="permissions"
> data-testid="permissionsTab"
<PermissionsTab type="users" /> title={<TabTitleText>{t("common:permissions")}</TabTitleText>}
</Tab> {...route("permissions")}
>
<PermissionsTab type="users" />
</Tab>
)}
</RoutableTabs> </RoutableTabs>
</PageSection> </PageSection>
</> </>