From a76675dd4d4110fad11a8016e66bd2fda186d147 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 21 Oct 2026 07:00:21 +1100 Subject: [PATCH] Update pricing role checks (#893) * Update pricing role checks Ref: https://github.com/inventree/InvenTree/pull/13034 * Update release notes --- assets/release_notes.md | 2 +- lib/api.dart | 10 ++++++++++ lib/inventree/part.dart | 12 +++++++++++- lib/widget/part/part_detail.dart | 7 +++---- test/api_test.dart | 3 +++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index 4f6aa7ee..79774b10 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -3,7 +3,7 @@ - Supports new multi-note API for model instances - Implement rendering for HTML note content - +- Adds support for separate "pricing" permission set ## 0.25.2 - September 2026 --- diff --git a/lib/api.dart b/lib/api.dart index 286ea389..0836724b 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -349,6 +349,16 @@ class InvenTreeAPI { // Ref: https://github.com/inventree/InvenTree/pull/11971 bool get supportsMultiNotes => apiVersion >= 537; + // Does the server support the "pricing" user role? + // (Pricing endpoints also moved to the /api/pricing/ namespace) + // Ref: https://github.com/inventree/InvenTree/pull/13034 + bool get supportsPricingRole => apiVersion >= 561; + + // Can the current user view part pricing information? + // Older servers do not have a separate "pricing" role, so no check is performed + bool get canViewPricing => + !supportsPricingRole || checkRole("pricing", "view"); + // Cached list of plugins (refreshed when we connect to the server) List _plugins = []; diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 18c49cc2..27929b35 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -237,8 +237,18 @@ class InvenTreePart extends InvenTreeModel { // Request pricing data for this part Future getPricing() async { + final api = InvenTreeAPI(); + + if (!api.canViewPricing) { + return null; + } + + final String url = api.supportsPricingRole + ? "/api/pricing/part/${pk}/" + : "/api/part/${pk}/pricing/"; + try { - final response = await InvenTreeAPI().get("/api/part/${pk}/pricing/"); + final response = await api.get(url); if (response.isValid()) { final pricingData = response.data; diff --git a/lib/widget/part/part_detail.dart b/lib/widget/part/part_detail.dart index 1259c524..16dec043 100644 --- a/lib/widget/part/part_detail.dart +++ b/lib/widget/part/part_detail.dart @@ -158,10 +158,9 @@ class _PartDisplayState extends RefreshableState { false, ); - showPricing = await InvenTreeSettingsManager().getBool( - INV_PART_SHOW_PRICING, - true, - ); + showPricing = + api.canViewPricing && + await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PRICING, true); showBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true); allowLabelPrinting = await InvenTreeSettingsManager().getBool( INV_ENABLE_LABEL_PRINTING, diff --git a/test/api_test.dart b/test/api_test.dart index 3bd5cdb1..515bad80 100644 --- a/test/api_test.dart +++ b/test/api_test.dart @@ -138,6 +138,9 @@ void main() { assert(!api.checkRole("part", "weirdpermission")); assert(api.checkRole("blah", "bloo")); + // Pricing role (or legacy server with no pricing role) + assert(api.canViewPricing); + debugContains("Received token from server"); debugContains("showSnackIcon: 'Connected to Server'"); });