Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(rbac): hide features in main menu based on rbac scopes (#785)

Marc Klingen6489d2f27e02
diff --git a/src/components/layouts/layout.tsx b/src/components/layouts/layout.tsx
index c5b118582f..9fc636b22d 100644
--- a/src/components/layouts/layout.tsx
+++ b/src/components/layouts/layout.tsx
@@ -23,6 +23,7 @@ import Head from "next/head";
import { env } from "@/src/env.mjs";
import { LangfuseLogo } from "@/src/components/LangfuseLogo";
import { Spinner } from "@/src/components/layouts/spinner";
+import { hasAccess } from "@/src/features/rbac/utils/checkAccess";
const userNavigation = [
{
@@ -58,6 +59,11 @@ export default function Layout(props: PropsWithChildren) {
enableExperimentalFeatures ||
session.data?.user?.featureFlags[featureFlag],
)
+ .filter(
+ ({ rbacScope }) =>
+ rbacScope === undefined ||
+ (projectId && hasAccess({ projectId, scope: rbacScope, session })),
+ )
.map(({ pathname, ...rest }) => ({
pathname,
href: pathname.replace("[projectId]", projectId ?? ""),
diff --git a/src/components/layouts/routes.ts b/src/components/layouts/routes.ts
index d05569d027..e58ff0e4f6 100644
--- a/src/components/layouts/routes.ts
+++ b/src/components/layouts/routes.ts
@@ -1,4 +1,5 @@
import { type Flag } from "@/src/features/feature-flags/types";
+import { type Scope } from "@/src/features/rbac/constants/roleAccessRights";
import {
Database,
LayoutDashboard,
@@ -19,6 +20,7 @@ export const ROUTES: Array<{
icon: LucideIcon;
featureFlag?: Flag;
label?: string;
+ rbacScope?: Scope;
}> = [
{
name: "Dashboard",
@@ -55,6 +57,7 @@ export const ROUTES: Array<{
pathname: "/project/[projectId]/prompts",
icon: PenSquareIcon,
label: "Beta",
+ rbacScope: "prompts:read",
},
{
name: "Datasets",
diff --git a/src/features/rbac/utils/checkAccess.ts b/src/features/rbac/utils/checkAccess.ts
index 241088f4c9..e171f4beaf 100644
--- a/src/features/rbac/utils/checkAccess.ts
+++ b/src/features/rbac/utils/checkAccess.ts
@@ -34,7 +34,8 @@ export const useHasAccess = (p: { projectId: string; scope: Scope }) => {
return hasAccess({ session, ...p });
};
-function hasAccess(p: HasAccessParams): boolean {
+// For use in UI components as function, if session is already available
+export function hasAccess(p: HasAccessParams): boolean {
const role: MembershipRole | undefined =
"role" in p
? // MembershipRole