mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Refactor user and instance manager (#837)
* Refactor UserManager to use Datastore * Rename lib.User to UserDetails also adds to/fromUserDetails * Fix existing tests * Add user class tests * Add tests for finaliseUsers * Move HostDetails to own file with tests * Move InstanceDetails to its own file with tests * Rename HostInfo and add tests * Rename InstanceInfo and add tests - Also changes the names of the host properties related to instances - Also removes the need to specify the location of InstanceInfo * Make json round trip test validate schema * Add InstanceManager * Fix lint errors * Extra tests * Add final test coverage * Add one last test to InstanceManager * Response to comments * Use generator rather than return anonumous generator Co-authored-by: Hornwitser <github@hornwitser.no> * Fix lint issue with generator --------- Co-authored-by: Hornwitser <github@hornwitser.no>
This commit is contained in:
1 parent
5bea930d05
commit
2235294c59
60 files changed
+3371
-1227
No files matched your search
+13
-10
@@ -4,9 +4,7 @@ const http = require("http");
|
||||
const express = require("express");
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
const UserManager = require("@clusterio/controller/dist/node/src/UserManager").default;
|
||||
const ControllerUser = require("@clusterio/controller/dist/node/src/ControllerUser").default;
|
||||
const { User, UserManager, UserRecord, InstanceManager } = require("@clusterio/controller");
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
@@ -179,15 +177,20 @@ class MockController {
|
||||
]));
|
||||
|
||||
this.roles = new lib.SubscribableDatastore(roleProvider, roleProvider.value);
|
||||
this.roles.get(1).grantDefaultPermissions();
|
||||
this.roles.get(1).grantDefaultPermissions(); // Todo replace "core.admin" above with grantAdminPermissions
|
||||
|
||||
this.userManager = new UserManager(this.config, this.roles);
|
||||
this.userManager.users = new Map([
|
||||
["test", ControllerUser.fromJSON({ name: "test", roles: [0, 1] }, this.roles)],
|
||||
["player", ControllerUser.fromJSON({ name: "player", roles: [1] }, this.roles)],
|
||||
]);
|
||||
const userProvider = new lib.MemoryDatastoreProvider(new Map([
|
||||
["test", UserRecord.fromJSON({ name: "test", roles: [0, 1] })],
|
||||
["player", UserRecord.fromJSON({ name: "player", roles: [1] })],
|
||||
]));
|
||||
|
||||
this.users = new UserManager(
|
||||
new lib.SubscribableDatastore(userProvider, userProvider.value),
|
||||
this.roles, this.config
|
||||
);
|
||||
|
||||
this.instances = new InstanceManager(new lib.KeyValueDatastore(), this);
|
||||
|
||||
this.instances = new lib.KeyValueDatastore();
|
||||
this.hosts = new lib.KeyValueDatastore();
|
||||
this.handles = new Map();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user