2
0
mirror of https://github.com/inventree/inventree-app.git synced 2026-06-10 08:27:15 +00:00

use new user-self endpoints (#822)

* report new user-self endpoints

* swich default around and fix roles

* run format
This commit is contained in:
Matthias Mair
2026-05-22 01:45:07 +02:00
committed by GitHub
parent 8d05dc1c9f
commit 9d28ae92d7
+15 -5
View File
@@ -198,8 +198,8 @@ class InvenTreeAPI {
bool _strictHttps = false; bool _strictHttps = false;
// Endpoint for requesting an API token // Endpoint for requesting an API token
static const _URL_TOKEN = "user/token/"; static const _URL_TOKEN = "user/me/token/";
static const _URL_ROLES = "user/roles/"; static const _URL_ROLES = "user/me/roles/";
static const _URL_ME = "user/me/"; static const _URL_ME = "user/me/";
// Accessors for various url endpoints // Accessors for various url endpoints
@@ -357,6 +357,10 @@ class InvenTreeAPI {
// Ref: https://github.com/inventree/InvenTree/pull/10699 // Ref: https://github.com/inventree/InvenTree/pull/10699
bool get supportsModernParameters => apiVersion >= 429; bool get supportsModernParameters => apiVersion >= 429;
// Does the server use the new "user/me/" endpoints?
// Ref: https://github.com/inventree/InvenTree/pull/11963
bool get supportsNewUserEndpoints => apiVersion >= 490;
// Cached list of plugins (refreshed when we connect to the server) // Cached list of plugins (refreshed when we connect to the server)
List<InvenTreePlugin> _plugins = []; List<InvenTreePlugin> _plugins = [];
@@ -588,9 +592,13 @@ class InvenTreeAPI {
String authHeader = String authHeader =
"Basic " + base64Encode(utf8.encode("${username}:${password}")); "Basic " + base64Encode(utf8.encode("${username}:${password}"));
String actualTokenUrl = supportsNewUserEndpoints
? _URL_TOKEN
: "user/token/";
// Perform request to get a token // Perform request to get a token
final response = await get( final response = await get(
_URL_TOKEN, actualTokenUrl,
params: {"name": platform_name}, params: {"name": platform_name},
headers: {HttpHeaders.authorizationHeader: authHeader}, headers: {HttpHeaders.authorizationHeader: authHeader},
); );
@@ -709,8 +717,10 @@ class InvenTreeAPI {
roles.clear(); roles.clear();
debug("API: Requesting user role data"); debug("API: Requesting user role data");
String actualRoleUrl = supportsNewUserEndpoints
final response = await get(_URL_ROLES, expectedStatusCode: 200); ? _URL_ROLES
: "user/roles/";
final response = await get(actualRoleUrl, expectedStatusCode: 200);
if (!response.successful()) { if (!response.successful()) {
return false; return false;