2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00

Improvements for profile management

This commit is contained in:
Oliver Walters 2022-05-22 09:29:04 +10:00
parent 4e14bd077c
commit 53b69d9623
2 changed files with 32 additions and 7 deletions

View File

@ -106,13 +106,6 @@ class UserProfileDBManager {
return true;
}
/*
* Mark the particular profile as selected
*/
Future<void> selectProfile(int key) async {
await store.record("selected").put(await _db, key);
}
/*
* Update the selected profile in the database.
* The unique integer <key> is used to determine if the profile already exists.
@ -196,4 +189,32 @@ class UserProfileDBManager {
return profileList;
}
/*
* Mark the particular profile as selected
*/
Future<void> selectProfile(int key) async {
await store.record("selected").put(await _db, key);
}
/*
* Look-up and select a profile by name.
* Return true if the profile was selected
*/
Future<bool> selectProfileByName(String name) async {
var profiles = await getAllProfiles();
for (var prf in profiles) {
if (prf.name == name) {
int key = prf.key ?? -1;
if (key >= 0) {
await selectProfile(key);
return true;
}
}
}
return false;
}
}

View File

@ -41,6 +41,10 @@ void main() {
await UserProfileDBManager().updateProfile(prf);
}
// Ensure the profile is selected
assert(! await UserProfileDBManager().selectProfileByName("Missing Profile"));
assert(await UserProfileDBManager().selectProfileByName("Test Profile"));
});
group("Login Tests:", () {