Skip to content

Commit dbf11d4

Browse files
Check user permissions for dashboard items (#10047)
Ref: #10046
1 parent 69ca942 commit dbf11d4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/frontend/src/components/dashboard/DashboardWidget.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IconX } from '@tabler/icons-react';
44

55
import { Boundary } from '../Boundary';
66

7+
import type { ModelType } from '@lib/index';
78
import type { JSX } from 'react';
89

910
/**
@@ -20,6 +21,7 @@ export interface DashboardWidgetProps {
2021
enabled?: boolean;
2122
minWidth?: number;
2223
minHeight?: number;
24+
modelType?: ModelType;
2325
render: () => JSX.Element;
2426
visible?: () => boolean;
2527
}

src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { t } from '@lingui/core/macro';
22

33
import { ModelType } from '@lib/enums/ModelType';
44
import { useGlobalSettingsState } from '../../states/SettingsStates';
5+
import { useUserState } from '../../states/UserState';
56
import type { DashboardWidgetProps } from './DashboardWidget';
67
import ColorToggleDashboardWidget from './widgets/ColorToggleWidget';
78
import GetStartedWidget from './widgets/GetStartedWidget';
@@ -14,9 +15,10 @@ import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget';
1415
* @returns A list of built-in dashboard widgets which display the number of results for a particular query
1516
*/
1617
export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] {
18+
const user = useUserState.getState();
1719
const globalSettings = useGlobalSettingsState.getState();
1820

19-
return [
21+
const widgets: DashboardWidgetProps[] = [
2022
QueryCountDashboardWidget({
2123
label: 'sub-prt',
2224
title: t`Subscribed Parts`,
@@ -149,6 +151,15 @@ export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] {
149151
params: { assigned_to_me: true, outstanding: true }
150152
})
151153
];
154+
155+
// Filter widgets based on user permissions (if a modelType is defined)
156+
return widgets.filter((widget: DashboardWidgetProps) => {
157+
if (widget.modelType) {
158+
return user.hasViewPermission(widget.modelType);
159+
} else {
160+
return true;
161+
}
162+
});
152163
}
153164

154165
export function BuiltinGettingStartedWidgets(): DashboardWidgetProps[] {

src/frontend/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default function QueryCountDashboardWidget({
140140
title: title,
141141
description: description,
142142
enabled: enabled,
143+
modelType: modelType,
143144
minWidth: 2,
144145
minHeight: 1,
145146
render: () => (

0 commit comments

Comments
 (0)