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:
Stan Silvert 2024-08-14 03:49:48 -04:00 committed by GitHub
parent d4991ce56f
commit 35fbcf5af8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 74 additions and 60 deletions

View file

@ -31,6 +31,7 @@ import { useRealm } from "../context/realm-context/RealmContext";
import { toUserFederation } from "../user-federation/routes/UserFederation"; import { toUserFederation } from "../user-federation/routes/UserFederation";
import { useFetch } from "../utils/useFetch"; import { useFetch } from "../utils/useFetch";
import useToggle from "../utils/useToggle"; import useToggle from "../utils/useToggle";
import { useAccess } from "../context/access/Access";
export const DefaultsGroupsTab = () => { export const DefaultsGroupsTab = () => {
const { adminClient } = useAdminClient(); const { adminClient } = useAdminClient();
@ -50,6 +51,9 @@ export const DefaultsGroupsTab = () => {
const { addAlert, addError } = useAlerts(); const { addAlert, addError } = useAlerts();
const { enabled } = useHelp(); const { enabled } = useHelp();
const { hasAccess } = useAccess();
const canAddOrRemoveGroups = hasAccess("view-users", "manage-realm");
useFetch( useFetch(
() => adminClient.realms.getDefaultGroups({ realm }), () => adminClient.realms.getDefaultGroups({ realm }),
(groups) => { (groups) => {
@ -160,6 +164,7 @@ export const DefaultsGroupsTab = () => {
ariaLabelKey="defaultGroups" ariaLabelKey="defaultGroups"
searchPlaceholderKey="searchForGroups" searchPlaceholderKey="searchForGroups"
toolbarItem={ toolbarItem={
canAddOrRemoveGroups && (
<> <>
<ToolbarItem> <ToolbarItem>
<Button <Button
@ -202,8 +207,11 @@ export const DefaultsGroupsTab = () => {
</Dropdown> </Dropdown>
</ToolbarItem> </ToolbarItem>
</> </>
)
} }
actions={[ actions={
canAddOrRemoveGroups
? [
{ {
title: t("remove"), title: t("remove"),
onRowClick: (group) => { onRowClick: (group) => {
@ -212,7 +220,9 @@ export const DefaultsGroupsTab = () => {
return Promise.resolve(false); return Promise.resolve(false);
}, },
} as Action<GroupRepresentation>, } as Action<GroupRepresentation>,
]} ]
: []
}
columns={[ columns={[
{ {
name: "name", name: "name",
@ -239,7 +249,7 @@ export const DefaultsGroupsTab = () => {
Add groups... Add groups...
</Trans> </Trans>
} }
primaryActionText={t("addGroups")} primaryActionText={canAddOrRemoveGroups ? t("addGroups") : ""}
onPrimaryAction={toggleGroupPicker} onPrimaryAction={toggleGroupPicker}
/> />
} }

View file

@ -291,6 +291,8 @@ export const RealmSettingsTabs = () => {
const { hasAccess, hasSomeAccess } = useAccess(); const { hasAccess, hasSomeAccess } = useAccess();
const canViewOrManageEvents = const canViewOrManageEvents =
hasAccess("view-realm") && hasSomeAccess("view-events", "manage-events"); hasAccess("view-realm") && hasSomeAccess("view-events", "manage-events");
const canViewUserRegistration =
hasAccess("view-realm") && hasSomeAccess("view-clients", "manage-clients");
const useClientPoliciesTab = (tab: ClientPoliciesTab) => const useClientPoliciesTab = (tab: ClientPoliciesTab) =>
useRoutableTab( useRoutableTab(
@ -453,6 +455,7 @@ export const RealmSettingsTabs = () => {
> >
<UserProfileTab setTableData={setTableData as any} /> <UserProfileTab setTableData={setTableData as any} />
</Tab> </Tab>
{canViewUserRegistration && (
<Tab <Tab
title={<TabTitleText>{t("userRegistration")}</TabTitleText>} title={<TabTitleText>{t("userRegistration")}</TabTitleText>}
data-testid="rs-userRegistration-tab" data-testid="rs-userRegistration-tab"
@ -460,6 +463,7 @@ export const RealmSettingsTabs = () => {
> >
<UserRegistration /> <UserRegistration />
</Tab> </Tab>
)}
</RoutableTabs> </RoutableTabs>
</PageSection> </PageSection>
</> </>