Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]>
  • Loading branch information
pedroigor committed Aug 22, 2025
commit 54320878867e45eaecb15bec2c21bdacf653c780
13 changes: 12 additions & 1 deletion js/apps/admin-ui/src/utils/useIsFeatureEnabled.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
import { useAccess } from "../context/access/Access";

export enum Feature {
AdminFineGrainedAuthz = "ADMIN_FINE_GRAINED_AUTHZ",
Expand All @@ -20,13 +21,23 @@ export enum Feature {

export default function useIsFeatureEnabled() {
const { features } = useServerInfo();
const { hasAccess } = useAccess();

const hasFeatureAccess = (feature: Feature) => {
switch (feature) {
case Feature.Organizations:
return hasAccess("manage-realm");
default:
return true;
}
};

return function isFeatureEnabled(feature: Feature) {
if (!features) {
return false;
}
return features
.filter((f) => f.enabled)
.filter((f) => f.enabled && hasFeatureAccess(f.name as Feature))
.map((f) => f.name)
.includes(feature);
};
Expand Down
Loading