Skip to content

Commit 52879c0

Browse files
Bug fixes (#637)
* Fix formatting * Handle case where server does not provide permissions information * Enhanced URL checks * Enhanced check * Fix for error dialog * Bump version information
1 parent 762d1ae commit 52879c0

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

assets/release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 0.18.1 - April 2025
2+
---
3+
- Fix bug associated with handling invalid URLs
4+
15
### 0.18.0 - April 2025
26
---
37
- Adds ability to create new companies from the app

lib/api.dart

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -287,65 +287,67 @@ class InvenTreeAPI {
287287
int get apiVersion => (serverInfo["apiVersion"] ?? 1) as int;
288288

289289
// Consolidated search request API v102 or newer
290-
bool get supportsConsolidatedSearch =>apiVersion >= 102;
290+
bool get supportsConsolidatedSearch => apiVersion >= 102;
291291

292292
// ReturnOrder supports API v104 or newer
293-
bool get supportsReturnOrders =>apiVersion >= 104;
293+
bool get supportsReturnOrders => apiVersion >= 104;
294294

295295
// "Contact" model exposed to API
296-
bool get supportsContactModel =>apiVersion >= 104;
296+
bool get supportsContactModel => apiVersion >= 104;
297297

298298
// Status label endpoints API v105 or newer
299-
bool get supportsStatusLabelEndpoints =>apiVersion >= 105;
299+
bool get supportsStatusLabelEndpoints => apiVersion >= 105;
300300

301301
// Regex search API v106 or newer
302-
bool get supportsRegexSearch =>apiVersion >= 106;
302+
bool get supportsRegexSearch => apiVersion >= 106;
303303

304304
// Order barcodes API v107 or newer
305-
bool get supportsOrderBarcodes =>apiVersion >= 107;
305+
bool get supportsOrderBarcodes => apiVersion >= 107;
306306

307307
// Project codes require v109 or newer
308-
bool get supportsProjectCodes =>apiVersion >= 109;
308+
bool get supportsProjectCodes => apiVersion >= 109;
309309

310310
// Does the server support extra fields on stock adjustment actions?
311-
bool get supportsStockAdjustExtraFields =>apiVersion >= 133;
311+
bool get supportsStockAdjustExtraFields => apiVersion >= 133;
312312

313313
// Does the server support receiving items against a PO using barcodes?
314-
bool get supportsBarcodePOReceiveEndpoint =>apiVersion >= 139;
314+
bool get supportsBarcodePOReceiveEndpoint => apiVersion >= 139;
315315

316316
// Does the server support adding line items to a PO using barcodes?
317-
bool get supportsBarcodePOAddLineEndpoint =>apiVersion >= 153;
317+
bool get supportsBarcodePOAddLineEndpoint => apiVersion >= 153;
318318

319319
// Does the server support allocating stock to sales order using barcodes?
320-
bool get supportsBarcodeSOAllocateEndpoint =>apiVersion >= 160;
320+
bool get supportsBarcodeSOAllocateEndpoint => apiVersion >= 160;
321321

322322
// Does the server support the "modern" test results API
323323
// Ref: https://github.com/inventree/InvenTree/pull/6430/
324-
bool get supportsModernTestResults =>apiVersion >= 169;
324+
bool get supportsModernTestResults => apiVersion >= 169;
325325

326326
// Does the server support "null" top-level filtering for PartCategory and StockLocation endpoints?
327-
bool get supportsNullTopLevelFiltering =>apiVersion < 174;
327+
bool get supportsNullTopLevelFiltering => apiVersion < 174;
328328

329329
// Does the server support "active" status on Company and SupplierPart API endpoints?
330-
bool get supportsCompanyActiveStatus =>apiVersion >= 189;
330+
bool get supportsCompanyActiveStatus => apiVersion >= 189;
331331

332332
// Does the server support the "modern" (consolidated) label printing API?
333-
bool get supportsModernLabelPrinting =>apiVersion >= 201;
333+
bool get supportsModernLabelPrinting => apiVersion >= 201;
334334

335335
// Does the server support the "modern" (consolidated) attachment API?
336336
// Ref: https://github.com/inventree/InvenTree/pull/7420
337-
bool get supportsModernAttachments =>apiVersion >= 207;
337+
bool get supportsModernAttachments => apiVersion >= 207;
338+
339+
bool get supportsUserPermissions => apiVersion >= 207;
338340

339341
// Does the server support the "destination" field on the PurchaseOrder model?
340342
// Ref: https://github.com/inventree/InvenTree/pull/8403
341-
bool get supportsPurchaseOrderDestination =>apiVersion >= 276;
343+
bool get supportsPurchaseOrderDestination => apiVersion >= 276;
342344

343345
// Does the server support the "start_date" field for orders?
344346
// Ref: https://github.com/inventree/InvenTree/pull/8966
345-
bool get supportsStartDate =>apiVersion >= 306;
347+
bool get supportsStartDate => apiVersion >= 306;
346348

347349
// Supports separate search against "supplier" / "customer" / "manufacturer"
348-
bool get supportsSplitCompanySearch =>apiVersion >= 315;
350+
bool get supportsSplitCompanySearch => apiVersion >= 315;
349351

350352
// Cached list of plugins (refreshed when we connect to the server)
351353
List<InvenTreePlugin> _plugins = [];
@@ -725,7 +727,12 @@ class InvenTreeAPI {
725727
}
726728

727729
roles = (data["roles"] ?? {}) as Map<String, dynamic>;
728-
permissions = (data["permissions"] ?? {}) as Map<String, dynamic>;
730+
731+
if (supportsUserPermissions && data.containsKey("permissions")) {
732+
permissions = (data["permissions"] ?? {}) as Map<String, dynamic>;
733+
} else {
734+
permissions = {};
735+
}
729736

730737
return true;
731738
}
@@ -1194,6 +1201,15 @@ class InvenTreeAPI {
11941201

11951202
var _url = makeApiUrl(url);
11961203

1204+
if (_url.isEmpty) {
1205+
showServerError(
1206+
url,
1207+
L10().invalidHost,
1208+
L10().invalidHostDetails
1209+
);
1210+
return null;
1211+
}
1212+
11971213
// Add any required query parameters to the URL using ?key=value notation
11981214
if (urlParams.isNotEmpty) {
11991215
String query = "?";
@@ -1210,13 +1226,12 @@ class InvenTreeAPI {
12101226

12111227
Uri? _uri = Uri.tryParse(_url);
12121228

1213-
if (_uri == null) {
1214-
showServerError(url, L10().invalidHost, L10().invalidHostDetails);
1215-
return null;
1216-
}
1217-
1218-
if (_uri.host.isEmpty) {
1219-
showServerError(url, L10().invalidHost, L10().invalidHostDetails);
1229+
if (_uri == null || _uri.host.isEmpty) {
1230+
showServerError(
1231+
_url,
1232+
L10().invalidHost,
1233+
L10().invalidHostDetails
1234+
);
12201235
return null;
12211236
}
12221237

lib/widget/dialogs.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,15 @@ Future<void> showServerError(String url, String title, String description) async
228228
playAudioFile("sounds/server_error.mp3");
229229
}
230230

231+
description += "\nURL: $url";
232+
231233
showSnackIcon(
232234
title,
233235
success: false,
234236
actionText: L10().details,
235237
onAction: () {
236238
showErrorDialog(
237-
L10().serverError,
239+
title,
238240
description: description,
239241
icon: TablerIcons.server
240242
);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: inventree
22
description: InvenTree stock management
33

4-
version: 0.18.0+97
4+
version: 0.18.1+98
55

66
environment:
77
sdk: ">=2.19.5 <3.13.0"

0 commit comments

Comments
 (0)