diff --git a/src/frontend/src/components/dashboard/DashboardWidget.tsx b/src/frontend/src/components/dashboard/DashboardWidget.tsx index 0ac23e91e3..d56f733587 100644 --- a/src/frontend/src/components/dashboard/DashboardWidget.tsx +++ b/src/frontend/src/components/dashboard/DashboardWidget.tsx @@ -4,6 +4,7 @@ import { IconX } from '@tabler/icons-react'; import { Boundary } from '../Boundary'; +import type { ModelType } from '@lib/index'; import type { JSX } from 'react'; /** @@ -20,6 +21,7 @@ export interface DashboardWidgetProps { enabled?: boolean; minWidth?: number; minHeight?: number; + modelType?: ModelType; render: () => JSX.Element; visible?: () => boolean; } diff --git a/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx b/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx index 1772d9d788..4054aa7feb 100644 --- a/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx +++ b/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx @@ -2,6 +2,7 @@ import { t } from '@lingui/core/macro'; import { ModelType } from '@lib/enums/ModelType'; import { useGlobalSettingsState } from '../../states/SettingsStates'; +import { useUserState } from '../../states/UserState'; import type { DashboardWidgetProps } from './DashboardWidget'; import ColorToggleDashboardWidget from './widgets/ColorToggleWidget'; import GetStartedWidget from './widgets/GetStartedWidget'; @@ -14,9 +15,10 @@ import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget'; * @returns A list of built-in dashboard widgets which display the number of results for a particular query */ export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] { + const user = useUserState.getState(); const globalSettings = useGlobalSettingsState.getState(); - return [ + const widgets: DashboardWidgetProps[] = [ QueryCountDashboardWidget({ label: 'sub-prt', title: t`Subscribed Parts`, @@ -149,6 +151,15 @@ export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] { params: { assigned_to_me: true, outstanding: true } }) ]; + + // Filter widgets based on user permissions (if a modelType is defined) + return widgets.filter((widget: DashboardWidgetProps) => { + if (widget.modelType) { + return user.hasViewPermission(widget.modelType); + } else { + return true; + } + }); } export function BuiltinGettingStartedWidgets(): DashboardWidgetProps[] { diff --git a/src/frontend/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx b/src/frontend/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx index 58b7c95d5e..e0da07a1f5 100644 --- a/src/frontend/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx +++ b/src/frontend/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx @@ -140,6 +140,7 @@ export default function QueryCountDashboardWidget({ title: title, description: description, enabled: enabled, + modelType: modelType, minWidth: 2, minHeight: 1, render: () => (