mirror of
https://github.com/keycloak/keycloak.git
synced 2025-12-16 20:15:46 -06:00
Make it possible to check for permissions when deciding if a feature is enabled or not (#42909)
Do not query organizations if manage-realm is not granted Closes #41418 Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
@@ -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",
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user