mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
API now requires minimum API version, not minimum server version
- A lot simpler to implement and undestand!
This commit is contained in:
parent
7f69c1d6d4
commit
59a2c004d9
54
lib/api.dart
54
lib/api.dart
@ -26,42 +26,8 @@ import 'package:one_context/one_context.dart';
|
||||
|
||||
class InvenTreeAPI {
|
||||
|
||||
// Minimum supported InvenTree server version is
|
||||
static const List<int> MIN_SUPPORTED_VERSION = [0, 1, 5];
|
||||
|
||||
String get _requiredVersionString => "${MIN_SUPPORTED_VERSION[0]}.${MIN_SUPPORTED_VERSION[1]}.${MIN_SUPPORTED_VERSION[2]}";
|
||||
|
||||
bool _checkServerVersion(String version) {
|
||||
|
||||
// Provided version string should be of the format "x.y.z [...]"
|
||||
List<String> versionSplit = version.split(' ').first.split('.');
|
||||
|
||||
// Extract the version number <major>.<minor>.<sub> from the string
|
||||
if (versionSplit.length != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cast the server version to an explicit integer
|
||||
int server_version_code = 0;
|
||||
|
||||
print("server version: ${version}");
|
||||
|
||||
server_version_code += (int.tryParse(versionSplit[0]) ?? 0) * 100 * 100;
|
||||
server_version_code += (int.tryParse(versionSplit[1]) ?? 0) * 100;
|
||||
server_version_code += (int.tryParse(versionSplit[2]));
|
||||
|
||||
print("server version code: ${server_version_code}");
|
||||
|
||||
int required_version_code = 0;
|
||||
|
||||
required_version_code += MIN_SUPPORTED_VERSION[0] * 100 * 100;
|
||||
required_version_code += MIN_SUPPORTED_VERSION[1] * 100;
|
||||
required_version_code += MIN_SUPPORTED_VERSION[2];
|
||||
|
||||
print("required version code: ${required_version_code}");
|
||||
|
||||
return server_version_code >= required_version_code;
|
||||
}
|
||||
// Minimum required API version for server
|
||||
static const _minApiVersion = 2;
|
||||
|
||||
// Endpoint for requesting an API token
|
||||
static const _URL_GET_TOKEN = "user/token/";
|
||||
@ -252,11 +218,19 @@ class InvenTreeAPI {
|
||||
|
||||
// Default API version is 1 if not provided
|
||||
_apiVersion = data['apiVersion'] as int ?? 1;
|
||||
// Check that the remote server version is *new* enough
|
||||
if (!_checkServerVersion(_version)) {
|
||||
|
||||
if (_apiVersion < _minApiVersion) {
|
||||
|
||||
BuildContext ctx = OneContext().context;
|
||||
|
||||
String message = I18N.of(ctx).serverApiVersion + ": ${_apiVersion}";
|
||||
|
||||
message += "\n";
|
||||
message += I18N.of(ctx).serverApiRequired + ": ${_minApiVersion}";
|
||||
|
||||
showServerError(
|
||||
I18N.of(OneContext().context).serverOld,
|
||||
"\n\nServer Version: ${_version}\n\nRequired version: ${_requiredVersionString}"
|
||||
message
|
||||
);
|
||||
|
||||
return false;
|
||||
@ -384,6 +358,7 @@ class InvenTreeAPI {
|
||||
|
||||
try {
|
||||
var data = json.decode(response.body);
|
||||
|
||||
if (data.containsKey('roles')) {
|
||||
// Save a local copy of the user roles
|
||||
roles = data['roles'];
|
||||
@ -397,7 +372,6 @@ class InvenTreeAPI {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
bool checkPermission(String role, String permission) {
|
||||
/*
|
||||
* Check if the user has the given role.permission assigned
|
||||
|
14
pubspec.lock
14
pubspec.lock
@ -273,6 +273,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.6"
|
||||
infinite_scroll_pagination:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: infinite_scroll_pagination
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -488,6 +495,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.99"
|
||||
sliver_tools:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sliver_tools
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.10+1"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -38,6 +38,7 @@ dependencies:
|
||||
path_provider: ^1.6.27 # Local file storage
|
||||
sembast: ^2.4.9 # NoSQL data storage
|
||||
one_context: ^0.5.0 # Dialogs without requiring context
|
||||
infinite_scroll_pagination: ^2.3.0 # Let the server do all the work!
|
||||
path:
|
||||
|
||||
dev_dependencies:
|
||||
|
Loading…
x
Reference in New Issue
Block a user