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:
+15
-5
@@ -198,8 +198,8 @@ class InvenTreeAPI {
|
||||
bool _strictHttps = false;
|
||||
|
||||
// Endpoint for requesting an API token
|
||||
static const _URL_TOKEN = "user/token/";
|
||||
static const _URL_ROLES = "user/roles/";
|
||||
static const _URL_TOKEN = "user/me/token/";
|
||||
static const _URL_ROLES = "user/me/roles/";
|
||||
static const _URL_ME = "user/me/";
|
||||
|
||||
// Accessors for various url endpoints
|
||||
@@ -357,6 +357,10 @@ class InvenTreeAPI {
|
||||
// Ref: https://github.com/inventree/InvenTree/pull/10699
|
||||
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)
|
||||
List<InvenTreePlugin> _plugins = [];
|
||||
|
||||
@@ -588,9 +592,13 @@ class InvenTreeAPI {
|
||||
String authHeader =
|
||||
"Basic " + base64Encode(utf8.encode("${username}:${password}"));
|
||||
|
||||
String actualTokenUrl = supportsNewUserEndpoints
|
||||
? _URL_TOKEN
|
||||
: "user/token/";
|
||||
|
||||
// Perform request to get a token
|
||||
final response = await get(
|
||||
_URL_TOKEN,
|
||||
actualTokenUrl,
|
||||
params: {"name": platform_name},
|
||||
headers: {HttpHeaders.authorizationHeader: authHeader},
|
||||
);
|
||||
@@ -709,8 +717,10 @@ class InvenTreeAPI {
|
||||
roles.clear();
|
||||
|
||||
debug("API: Requesting user role data");
|
||||
|
||||
final response = await get(_URL_ROLES, expectedStatusCode: 200);
|
||||
String actualRoleUrl = supportsNewUserEndpoints
|
||||
? _URL_ROLES
|
||||
: "user/roles/";
|
||||
final response = await get(actualRoleUrl, expectedStatusCode: 200);
|
||||
|
||||
if (!response.successful()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user