mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Improve checks for API user permissions
This commit is contained in:
parent
c8fa6bd992
commit
21e7a976ee
1
.github/workflows/ci.yaml
vendored
1
.github/workflows/ci.yaml
vendored
@ -60,6 +60,7 @@ jobs:
|
||||
invoke import-fixtures
|
||||
invoke server -a 127.0.0.1:12345 &
|
||||
invoke wait
|
||||
sleep 30
|
||||
- name: Unit Tests
|
||||
run: |
|
||||
flutter test --coverage
|
||||
|
@ -497,7 +497,7 @@ class InvenTreeAPI {
|
||||
/*
|
||||
* Request the user roles (permissions) from the InvenTree server
|
||||
*/
|
||||
Future<void> getUserRoles() async {
|
||||
Future<bool> getUserRoles() async {
|
||||
|
||||
roles.clear();
|
||||
|
||||
@ -511,7 +511,7 @@ class InvenTreeAPI {
|
||||
final response = await get(_URL_GET_ROLES, expectedStatusCode: 200);
|
||||
|
||||
if (!response.successful()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = response.asMap();
|
||||
@ -519,6 +519,10 @@ class InvenTreeAPI {
|
||||
if (data.containsKey("roles")) {
|
||||
// Save a local copy of the user roles
|
||||
roles = (response.data["roles"] ?? {}) as Map<String, dynamic>;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,10 +129,13 @@ void main() {
|
||||
assert(api.supportsNotifications);
|
||||
assert(api.supportsPoReceive);
|
||||
|
||||
// Ensure we can request (and receive) user roles
|
||||
assert(await api.getUserRoles());
|
||||
|
||||
// Check available permissions
|
||||
assert(api.checkPermission("part", "change"));
|
||||
assert(api.checkPermission("stocklocation", "delete"));
|
||||
assert(api.checkPermission("part", "weirdpermission"));
|
||||
assert(!api.checkPermission("part", "weirdpermission"));
|
||||
assert(api.checkPermission("blah", "bloo"));
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user