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,6 +164,7 @@ export const DefaultsGroupsTab = () => {
|
|||
ariaLabelKey="defaultGroups"
|
||||
searchPlaceholderKey="searchForGroups"
|
||||
toolbarItem={
|
||||
canAddOrRemoveGroups && (
|
||||
<>
|
||||
<ToolbarItem>
|
||||
<Button
|
||||
|
@ -202,8 +207,11 @@ export const DefaultsGroupsTab = () => {
|
|||
</Dropdown>
|
||||
</ToolbarItem>
|
||||
</>
|
||||
)
|
||||
}
|
||||
actions={[
|
||||
actions={
|
||||
canAddOrRemoveGroups
|
||||
? [
|
||||
{
|
||||
title: t("remove"),
|
||||
onRowClick: (group) => {
|
||||
|
@ -212,7 +220,9 @@ export const DefaultsGroupsTab = () => {
|
|||
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,6 +455,7 @@ export const RealmSettingsTabs = () => {
|
|||
>
|
||||
<UserProfileTab setTableData={setTableData as any} />
|
||||
</Tab>
|
||||
{canViewUserRegistration && (
|
||||
<Tab
|
||||
title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
|
||||
data-testid="rs-userRegistration-tab"
|
||||
|
@ -460,6 +463,7 @@ export const RealmSettingsTabs = () => {
|
|||
>
|
||||
<UserRegistration />
|
||||
</Tab>
|
||||
)}
|
||||
</RoutableTabs>
|
||||
</PageSection>
|
||||
</>
|
||||
|
|
Loading…
Reference in a new issue