From e37e72357a6598ea6095d1742bfc576f7b252fa9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 19 Dec 2024 07:31:59 +1100 Subject: [PATCH] Cleanup old settings (#8709) * Use LABEL_ENABLE and REPORT_ENABLE settings in PUI * Cleanup base.html - Should reduce db hits slightly * Remove defunct homepage settings * Cleanup old settings * Adjust unit test --- docs/docs/settings/global.md | 2 - .../InvenTree/common/setting/system.py | 14 --- src/backend/InvenTree/common/setting/user.py | 114 ------------------ src/backend/InvenTree/common/tests.py | 2 +- src/backend/InvenTree/templates/base.html | 6 - .../components/buttons/PrintingActions.tsx | 22 +++- .../pages/Index/Settings/SystemSettings.tsx | 2 - .../src/pages/Index/Settings/UserSettings.tsx | 33 ----- 8 files changed, 18 insertions(+), 177 deletions(-) diff --git a/docs/docs/settings/global.md b/docs/docs/settings/global.md index 241ac74f0d..6b7ff3b213 100644 --- a/docs/docs/settings/global.md +++ b/docs/docs/settings/global.md @@ -31,9 +31,7 @@ Configuration of basic server settings: {{ globalsetting("INVENTREE_DOWNLOAD_FROM_URL") }} {{ globalsetting("INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE") }} {{ globalsetting("INVENTREE_DOWNLOAD_FROM_URL_USER_AGENT") }} -{{ globalsetting("INVENTREE_REQUIRE_CONFIRM") }} {{ globalsetting("INVENTREE_STRICT_URLS") }} -{{ globalsetting("INVENTREE_TREE_DEPTH") }} {{ globalsetting("INVENTREE_BACKUP_ENABLE") }} {{ globalsetting("INVENTREE_BACKUP_DAYS") }} {{ globalsetting("INVENTREE_DELETE_TASKS_DAYS") }} diff --git a/src/backend/InvenTree/common/setting/system.py b/src/backend/InvenTree/common/setting/system.py index 2775d9e741..d25dc2689c 100644 --- a/src/backend/InvenTree/common/setting/system.py +++ b/src/backend/InvenTree/common/setting/system.py @@ -253,20 +253,6 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = { 'validator': bool, 'default': True, }, - 'INVENTREE_REQUIRE_CONFIRM': { - 'name': _('Require confirm'), - 'description': _('Require explicit user confirmation for certain action.'), - 'validator': bool, - 'default': True, - }, - 'INVENTREE_TREE_DEPTH': { - 'name': _('Tree Depth'), - 'description': _( - 'Default tree depth for treeview. Deeper levels can be lazy loaded as they are needed.' - ), - 'default': 1, - 'validator': [int, MinValueValidator(0)], - }, 'INVENTREE_UPDATE_CHECK_INTERVAL': { 'name': _('Update Check Interval'), 'description': _('How often to check for updates (set to zero to disable)'), diff --git a/src/backend/InvenTree/common/setting/user.py b/src/backend/InvenTree/common/setting/user.py index 107716d035..3466eed252 100644 --- a/src/backend/InvenTree/common/setting/user.py +++ b/src/backend/InvenTree/common/setting/user.py @@ -19,120 +19,6 @@ def label_printer_options(): USER_SETTINGS: dict[str, InvenTreeSettingsKeyType] = { - 'HOMEPAGE_HIDE_INACTIVE': { - 'name': _('Hide inactive parts'), - 'description': _('Hide inactive parts in results displayed on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_PART_STARRED': { - 'name': _('Show subscribed parts'), - 'description': _('Show subscribed parts on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_CATEGORY_STARRED': { - 'name': _('Show subscribed categories'), - 'description': _('Show subscribed part categories on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_PART_LATEST': { - 'name': _('Show latest parts'), - 'description': _('Show latest parts on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_BOM_REQUIRES_VALIDATION': { - 'name': _('Show invalid BOMs'), - 'description': _('Show BOMs that await validation on the homepage'), - 'default': False, - 'validator': bool, - }, - 'HOMEPAGE_STOCK_RECENT': { - 'name': _('Show recent stock changes'), - 'description': _('Show recently changed stock items on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_STOCK_LOW': { - 'name': _('Show low stock'), - 'description': _('Show low stock items on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_SHOW_STOCK_DEPLETED': { - 'name': _('Show depleted stock'), - 'description': _('Show depleted stock items on the homepage'), - 'default': False, - 'validator': bool, - }, - 'HOMEPAGE_BUILD_STOCK_NEEDED': { - 'name': _('Show needed stock'), - 'description': _('Show stock items needed for builds on the homepage'), - 'default': False, - 'validator': bool, - }, - 'HOMEPAGE_STOCK_EXPIRED': { - 'name': _('Show expired stock'), - 'description': _('Show expired stock items on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_STOCK_STALE': { - 'name': _('Show stale stock'), - 'description': _('Show stale stock items on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_BUILD_PENDING': { - 'name': _('Show pending builds'), - 'description': _('Show pending builds on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_BUILD_OVERDUE': { - 'name': _('Show overdue builds'), - 'description': _('Show overdue builds on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_PO_OUTSTANDING': { - 'name': _('Show outstanding POs'), - 'description': _('Show outstanding POs on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_PO_OVERDUE': { - 'name': _('Show overdue POs'), - 'description': _('Show overdue POs on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_SO_OUTSTANDING': { - 'name': _('Show outstanding SOs'), - 'description': _('Show outstanding SOs on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_SO_OVERDUE': { - 'name': _('Show overdue SOs'), - 'description': _('Show overdue SOs on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_SO_SHIPMENTS_PENDING': { - 'name': _('Show pending SO shipments'), - 'description': _('Show pending SO shipments on the homepage'), - 'default': True, - 'validator': bool, - }, - 'HOMEPAGE_NEWS': { - 'name': _('Show News'), - 'description': _('Show news on the homepage'), - 'default': False, - 'validator': bool, - }, 'LABEL_INLINE': { 'name': _('Inline label display'), 'description': _( diff --git a/src/backend/InvenTree/common/tests.py b/src/backend/InvenTree/common/tests.py index 74c0dddb95..2b6a0233cc 100644 --- a/src/backend/InvenTree/common/tests.py +++ b/src/backend/InvenTree/common/tests.py @@ -628,7 +628,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase): def test_user_setting_init(self): """Test we can retrieve a setting which has not yet been initialized.""" - key = 'HOMEPAGE_PART_LATEST' + key = 'LABEL_INLINE' # Ensure it does not actually exist in the database self.assertFalse(InvenTreeUserSetting.objects.filter(key=key).exists()) diff --git a/src/backend/InvenTree/templates/base.html b/src/backend/InvenTree/templates/base.html index 60f8243812..65231c341d 100644 --- a/src/backend/InvenTree/templates/base.html +++ b/src/backend/InvenTree/templates/base.html @@ -2,14 +2,8 @@ {% load i18n %} {% load inventree_extras %} -{% plugins_enabled as plugins_enabled %} -{% settings_value 'BARCODE_ENABLE' as barcodes %} -{% settings_value 'RETURNORDER_ENABLED' as return_order_enabled %} -{% settings_value "REPORT_ENABLE" as report_enabled %} {% settings_value "SERVER_RESTART_REQUIRED" as server_restart_required %} {% settings_value "_PENDING_MIGRATIONS" as pending_migrations %} -{% settings_value "LABEL_ENABLE" as labels_enabled %} -{% inventree_show_about user as show_about %} diff --git a/src/frontend/src/components/buttons/PrintingActions.tsx b/src/frontend/src/components/buttons/PrintingActions.tsx index aef0eb4d0f..27c037d044 100644 --- a/src/frontend/src/components/buttons/PrintingActions.tsx +++ b/src/frontend/src/components/buttons/PrintingActions.tsx @@ -11,7 +11,10 @@ import { extractAvailableFields } from '../../functions/forms'; import { generateUrl } from '../../functions/urls'; import { useCreateApiFormModal } from '../../hooks/UseForm'; import { apiUrl } from '../../states/ApiState'; -import { useUserSettingsState } from '../../states/SettingsState'; +import { + useGlobalSettingsState, + useUserSettingsState +} from '../../states/SettingsState'; import type { ApiFormFieldSet } from '../forms/fields/ApiFormField'; import { ActionDropdown } from '../items/ActionDropdown'; @@ -29,14 +32,23 @@ export function PrintingActions({ modelType?: ModelType; }) { const userSettings = useUserSettingsState(); + const globalSettings = useGlobalSettingsState(); const enabled = useMemo(() => items.length > 0, [items]); const [pluginKey, setPluginKey] = useState(''); + const labelPrintingEnabled = useMemo(() => { + return enableLabels && globalSettings.isSet('LABEL_ENABLE'); + }, [enableLabels, globalSettings]); + + const reportPrintingEnabled = useMemo(() => { + return enableReports && globalSettings.isSet('REPORT_ENABLE'); + }, [enableReports, globalSettings]); + // Fetch available printing fields via OPTIONS request const printingFields = useQuery({ - enabled: enableLabels, + enabled: labelPrintingEnabled, queryKey: ['printingFields', modelType, pluginKey], gcTime: 500, queryFn: () => @@ -162,7 +174,7 @@ export function PrintingActions({ return null; } - if (!enableLabels && !enableReports) { + if (!labelPrintingEnabled && !reportPrintingEnabled) { return null; } @@ -180,13 +192,13 @@ export function PrintingActions({ name: t`Print Labels`, icon: , onClick: () => labelModal.open(), - hidden: !enableLabels + hidden: !labelPrintingEnabled }, { name: t`Print Reports`, icon: , onClick: () => reportModal.open(), - hidden: !enableReports + hidden: !reportPrintingEnabled } ]} /> diff --git a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx index d4a512973b..74a7d34b9d 100644 --- a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx +++ b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx @@ -50,9 +50,7 @@ export default function SystemSettings() { 'INVENTREE_DOWNLOAD_FROM_URL', 'INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 'INVENTREE_DOWNLOAD_FROM_URL_USER_AGENT', - 'INVENTREE_REQUIRE_CONFIRM', 'INVENTREE_STRICT_URLS', - 'INVENTREE_TREE_DEPTH', 'INVENTREE_BACKUP_ENABLE', 'INVENTREE_BACKUP_DAYS', 'INVENTREE_DELETE_TASKS_DAYS', diff --git a/src/frontend/src/pages/Index/Settings/UserSettings.tsx b/src/frontend/src/pages/Index/Settings/UserSettings.tsx index cc106e9bcf..0147e9b603 100644 --- a/src/frontend/src/pages/Index/Settings/UserSettings.tsx +++ b/src/frontend/src/pages/Index/Settings/UserSettings.tsx @@ -3,7 +3,6 @@ import { Skeleton, Stack } from '@mantine/core'; import { IconBellCog, IconDeviceDesktop, - IconDeviceDesktopAnalytics, IconFileAnalytics, IconLock, IconSearch, @@ -43,38 +42,6 @@ export default function UserSettings() { icon: , content: }, - { - name: 'dashboard', - label: t`Dashboard`, - icon: , - content: ( - - ) - }, { name: 'display', label: t`Display Options`,