Skip to content

Commit 5432087

Browse files
committed
Make it possible to check for permissions when deciding if a feature is enabled or not
Do not query organizations if manage-realm is not granted Closes #41418 Signed-off-by: Pedro Igor <[email protected]>
1 parent de6a1de commit 5432087

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

js/apps/admin-ui/src/utils/useIsFeatureEnabled.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
2+
import { useAccess } from "../context/access/Access";
23

34
export enum Feature {
45
AdminFineGrainedAuthz = "ADMIN_FINE_GRAINED_AUTHZ",
@@ -20,13 +21,23 @@ export enum Feature {
2021

2122
export default function useIsFeatureEnabled() {
2223
const { features } = useServerInfo();
24+
const { hasAccess } = useAccess();
25+
26+
const hasFeatureAccess = (feature: Feature) => {
27+
switch (feature) {
28+
case Feature.Organizations:
29+
return hasAccess("manage-realm");
30+
default:
31+
return true;
32+
}
33+
};
2334

2435
return function isFeatureEnabled(feature: Feature) {
2536
if (!features) {
2637
return false;
2738
}
2839
return features
29-
.filter((f) => f.enabled)
40+
.filter((f) => f.enabled && hasFeatureAccess(f.name as Feature))
3041
.map((f) => f.name)
3142
.includes(feature);
3243
};

0 commit comments

Comments
 (0)