Fix for Network error attempting to view default realm roles without permissions (#31902)

* fix for issue #29211

Signed-off-by: Himanshi Gupta <higupta@redhat.com>

* fix for issue #29211

Signed-off-by: Himanshi Gupta <higupta@redhat.com>

---------

Signed-off-by: Himanshi Gupta <higupta@redhat.com>
This commit is contained in:
himanshi1099 2024-08-05 22:08:10 +05:30 committed by GitHub
parent 1e9f6bbb8c
commit 7cf9946040
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,8 +13,8 @@ import { useAlerts } from "@keycloak/keycloak-ui-shared";
import { useConfirmDialog } from "../confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../confirm-dialog/ConfirmDialog";
import { ListEmptyState } from "../list-empty-state/ListEmptyState"; import { ListEmptyState } from "../list-empty-state/ListEmptyState";
import { Action, KeycloakDataTable } from "../table-toolbar/KeycloakDataTable"; import { Action, KeycloakDataTable } from "../table-toolbar/KeycloakDataTable";
import "./RolesList.css"; import "./RolesList.css";
import { useAccess } from "../../context/access/Access";
type RoleDetailLinkProps = RoleRepresentation & { type RoleDetailLinkProps = RoleRepresentation & {
defaultRoleName?: string; defaultRoleName?: string;
@ -30,13 +30,21 @@ const RoleDetailLink = ({
}: RoleDetailLinkProps) => { }: RoleDetailLinkProps) => {
const { t } = useTranslation(messageBundle); const { t } = useTranslation(messageBundle);
const { realm } = useRealm(); const { realm } = useRealm();
const { hasAccess, hasSomeAccess } = useAccess();
const canViewUserRegistration =
hasAccess("view-realm") && hasSomeAccess("view-clients", "manage-clients");
return role.name !== defaultRoleName ? ( return role.name !== defaultRoleName ? (
<Link to={toDetail(role.id!)}>{role.name}</Link> <Link to={toDetail(role.id!)}>{role.name}</Link>
) : ( ) : (
<> <>
<Link to={toRealmSettings({ realm, tab: "user-registration" })}> {canViewUserRegistration ? (
{role.name}{" "} <Link to={toRealmSettings({ realm, tab: "user-registration" })}>
</Link> {role.name}
</Link>
) : (
<span>{role.name}</span>
)}
<HelpItem <HelpItem
helpText={t(`${messageBundle}:defaultRole`)} helpText={t(`${messageBundle}:defaultRole`)}
fieldLabelId="defaultRole" fieldLabelId="defaultRole"