Hide User Reg tab if you don't have permissions (#32021)
Fixes #31920 Signed-off-by: Stan Silvert <ssilvert@redhat.com>
This commit is contained in:
parent
d4991ce56f
commit
35fbcf5af8
2 changed files with 74 additions and 60 deletions
|
@ -31,6 +31,7 @@ import { useRealm } from "../context/realm-context/RealmContext";
|
|||
import { toUserFederation } from "../user-federation/routes/UserFederation";
|
||||
import { useFetch } from "../utils/useFetch";
|
||||
import useToggle from "../utils/useToggle";
|
||||
import { useAccess } from "../context/access/Access";
|
||||
|
||||
export const DefaultsGroupsTab = () => {
|
||||
const { adminClient } = useAdminClient();
|
||||
|
@ -50,6 +51,9 @@ export const DefaultsGroupsTab = () => {
|
|||
const { addAlert, addError } = useAlerts();
|
||||
const { enabled } = useHelp();
|
||||
|
||||
const { hasAccess } = useAccess();
|
||||
const canAddOrRemoveGroups = hasAccess("view-users", "manage-realm");
|
||||
|
||||
useFetch(
|
||||
() => adminClient.realms.getDefaultGroups({ realm }),
|
||||
(groups) => {
|
||||
|
@ -160,59 +164,65 @@ export const DefaultsGroupsTab = () => {
|
|||
ariaLabelKey="defaultGroups"
|
||||
searchPlaceholderKey="searchForGroups"
|
||||
toolbarItem={
|
||||
<>
|
||||
<ToolbarItem>
|
||||
<Button
|
||||
data-testid="openCreateGroupModal"
|
||||
variant="primary"
|
||||
onClick={toggleGroupPicker}
|
||||
>
|
||||
{t("addGroups")}
|
||||
</Button>
|
||||
</ToolbarItem>
|
||||
<ToolbarItem>
|
||||
<Dropdown
|
||||
onOpenChange={toggleKebab}
|
||||
toggle={(ref) => (
|
||||
<MenuToggle
|
||||
ref={ref}
|
||||
isExpanded={isKebabOpen}
|
||||
variant="plain"
|
||||
onClick={toggleKebab}
|
||||
isDisabled={selectedRows!.length === 0}
|
||||
>
|
||||
<EllipsisVIcon />
|
||||
</MenuToggle>
|
||||
)}
|
||||
isOpen={isKebabOpen}
|
||||
shouldFocusToggleOnSelect
|
||||
>
|
||||
<DropdownList>
|
||||
<DropdownItem
|
||||
key="action"
|
||||
component="button"
|
||||
onClick={() => {
|
||||
toggleRemoveDialog();
|
||||
toggleKebab();
|
||||
}}
|
||||
>
|
||||
{t("remove")}
|
||||
</DropdownItem>
|
||||
</DropdownList>
|
||||
</Dropdown>
|
||||
</ToolbarItem>
|
||||
</>
|
||||
canAddOrRemoveGroups && (
|
||||
<>
|
||||
<ToolbarItem>
|
||||
<Button
|
||||
data-testid="openCreateGroupModal"
|
||||
variant="primary"
|
||||
onClick={toggleGroupPicker}
|
||||
>
|
||||
{t("addGroups")}
|
||||
</Button>
|
||||
</ToolbarItem>
|
||||
<ToolbarItem>
|
||||
<Dropdown
|
||||
onOpenChange={toggleKebab}
|
||||
toggle={(ref) => (
|
||||
<MenuToggle
|
||||
ref={ref}
|
||||
isExpanded={isKebabOpen}
|
||||
variant="plain"
|
||||
onClick={toggleKebab}
|
||||
isDisabled={selectedRows!.length === 0}
|
||||
>
|
||||
<EllipsisVIcon />
|
||||
</MenuToggle>
|
||||
)}
|
||||
isOpen={isKebabOpen}
|
||||
shouldFocusToggleOnSelect
|
||||
>
|
||||
<DropdownList>
|
||||
<DropdownItem
|
||||
key="action"
|
||||
component="button"
|
||||
onClick={() => {
|
||||
toggleRemoveDialog();
|
||||
toggleKebab();
|
||||
}}
|
||||
>
|
||||
{t("remove")}
|
||||
</DropdownItem>
|
||||
</DropdownList>
|
||||
</Dropdown>
|
||||
</ToolbarItem>
|
||||
</>
|
||||
)
|
||||
}
|
||||
actions={
|
||||
canAddOrRemoveGroups
|
||||
? [
|
||||
{
|
||||
title: t("remove"),
|
||||
onRowClick: (group) => {
|
||||
setSelectedRows([group]);
|
||||
toggleRemoveDialog();
|
||||
return Promise.resolve(false);
|
||||
},
|
||||
} as Action<GroupRepresentation>,
|
||||
]
|
||||
: []
|
||||
}
|
||||
actions={[
|
||||
{
|
||||
title: t("remove"),
|
||||
onRowClick: (group) => {
|
||||
setSelectedRows([group]);
|
||||
toggleRemoveDialog();
|
||||
return Promise.resolve(false);
|
||||
},
|
||||
} as Action<GroupRepresentation>,
|
||||
]}
|
||||
columns={[
|
||||
{
|
||||
name: "name",
|
||||
|
@ -239,7 +249,7 @@ export const DefaultsGroupsTab = () => {
|
|||
Add groups...
|
||||
</Trans>
|
||||
}
|
||||
primaryActionText={t("addGroups")}
|
||||
primaryActionText={canAddOrRemoveGroups ? t("addGroups") : ""}
|
||||
onPrimaryAction={toggleGroupPicker}
|
||||
/>
|
||||
}
|
||||
|
|
|
@ -291,6 +291,8 @@ export const RealmSettingsTabs = () => {
|
|||
const { hasAccess, hasSomeAccess } = useAccess();
|
||||
const canViewOrManageEvents =
|
||||
hasAccess("view-realm") && hasSomeAccess("view-events", "manage-events");
|
||||
const canViewUserRegistration =
|
||||
hasAccess("view-realm") && hasSomeAccess("view-clients", "manage-clients");
|
||||
|
||||
const useClientPoliciesTab = (tab: ClientPoliciesTab) =>
|
||||
useRoutableTab(
|
||||
|
@ -453,13 +455,15 @@ export const RealmSettingsTabs = () => {
|
|||
>
|
||||
<UserProfileTab setTableData={setTableData as any} />
|
||||
</Tab>
|
||||
<Tab
|
||||
title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
|
||||
data-testid="rs-userRegistration-tab"
|
||||
{...userRegistrationTab}
|
||||
>
|
||||
<UserRegistration />
|
||||
</Tab>
|
||||
{canViewUserRegistration && (
|
||||
<Tab
|
||||
title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
|
||||
data-testid="rs-userRegistration-tab"
|
||||
{...userRegistrationTab}
|
||||
>
|
||||
<UserRegistration />
|
||||
</Tab>
|
||||
)}
|
||||
</RoutableTabs>
|
||||
</PageSection>
|
||||
</>
|
||||
|
|
Loading…
Reference in a new issue