2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-30 00:21:34 +00:00

Check user permissions for dashboard items (#10047)

Ref: https://github.com/inventree/InvenTree/discussions/10046
This commit is contained in:
Oliver
2025-07-20 20:02:07 +10:00
committed by GitHub
parent 69ca942dfc
commit dbf11d4b01
3 changed files with 15 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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[] {

View File

@@ -140,6 +140,7 @@ export default function QueryCountDashboardWidget({
title: title,
description: description,
enabled: enabled,
modelType: modelType,
minWidth: 2,
minHeight: 1,
render: () => (