feat(rbac): add roles and permissions
This commit is contained in:
parent
86a32a942c
commit
694b7bd09a
37 changed files with 2682 additions and 218 deletions
30
frontend/athena/components/common/Can.tsx
Normal file
30
frontend/athena/components/common/Can.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { hasAllPermissions, hasAnyPermission, hasPermission } from "@/lib/permissions";
|
||||
import type { CurrentUser, PermissionName } from "@/types/rbac";
|
||||
|
||||
type Props = {
|
||||
user: CurrentUser | null;
|
||||
permission?: PermissionName;
|
||||
any?: PermissionName[];
|
||||
all?: PermissionName[];
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export default function Can({ user, permission, any, all, children }: Props) {
|
||||
if (permission && !hasPermission(user, permission)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (any && !hasAnyPermission(user, any)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (all && !hasAllPermissions(user, all)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue