feat: restrict guest doctor access in clinic context by updating role-based routing and sidebar menu

This commit is contained in:
hamed
2026-06-19 21:08:32 +03:30
parent b686cd1e7d
commit 0624a08e62
5 changed files with 147 additions and 11 deletions
+17 -2
View File
@@ -40,7 +40,22 @@ type Section = { label: string; items: SectionItem[] };
function buildSections(
primaryRole: string | null,
dbUuid: string | null,
scope: string | null,
): Section[] {
// پزشکِ مهمان در محیط کلینیک (scope=clinic): فقط داشبورد و نوبت‌های خودش؛
// ابزارهای مدیریتی مطب/کلینیک نمایش داده نمی‌شوند.
if (primaryRole === "doctor" && scope === "clinic") {
return [
{
label: "عمومی",
items: [
{ to: "/admin/dashboard", icon: ChartBarIcon, label: "داشبورد" },
{ to: "/admin/appointments", icon: CalendarDaysIcon, label: "نوبت‌های من" },
],
},
];
}
if (primaryRole === "admin") {
return [
{
@@ -366,12 +381,12 @@ interface Props {
export default function Sidebar({ mobileOpen: _m, onMobileClose: _c }: Props) {
const sidebarOpen = useUiStore((s) => s.sidebarOpen);
const { logout, primaryRole, userName, availableContexts, dbUuid } =
const { logout, primaryRole, userName, availableContexts, dbUuid, context } =
useAuthStore();
const { hasFeature } = useSubscription();
const navigate = useNavigate();
const sections = buildSections(primaryRole, dbUuid);
const sections = buildSections(primaryRole, dbUuid, context?.scope ?? null);
const initials = (userName ?? "U").charAt(0).toUpperCase();
return (