mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Refactor User and Role into data classes (#531)
Use the JSON data class pattern for User, Role, and PlayerStats and move them into lib/src/data. This means that User is purely data now and can't reference role objects directly. To make it possible easily check permissions attached to roles and store data only visible on the controller on user objects a ControllerUser type is introduced which is linked with the UserManager and can therefore reference role objects directly. Resolves #525.
This commit is contained in:
1 parent
f802e6ba67
commit
e453a80155
37 files changed
+629
-613
No files matched your search
@@ -1034,7 +1034,7 @@ describe("Integration of Clusterio", function() {
|
||||
let tempRole = roles.find(role => role.name === "temp");
|
||||
assert.deepEqual(
|
||||
tempRole,
|
||||
new lib.RawRole(5, "temp", "A temp role", ["core.control.connect"])
|
||||
new lib.Role(5, "temp", "A temp role", new Set(["core.control.connect"]))
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1045,21 +1045,21 @@ describe("Integration of Clusterio", function() {
|
||||
await execCtl(`role edit temp ${args}`);
|
||||
let roles = await getControl().send(new lib.RoleListRequest());
|
||||
let newRole = roles.find(role => role.name === "new");
|
||||
assert.deepEqual(newRole, new lib.RawRole(5, "new", "A new role", []));
|
||||
assert.deepEqual(newRole, new lib.Role(5, "new", "A new role", new Set()));
|
||||
});
|
||||
it("should add permissions with --add-perms", async function() {
|
||||
let args = "--name new --add-perms core.host.list core.instance.list";
|
||||
await execCtl(`role edit new ${args}`);
|
||||
let roles = await getControl().send(new lib.RoleListRequest());
|
||||
let newRole = roles.find(role => role.name === "new");
|
||||
assert.deepEqual(newRole.permissions, ["core.host.list", "core.instance.list"]);
|
||||
assert.deepEqual(newRole.permissions, new Set(["core.host.list", "core.instance.list"]));
|
||||
});
|
||||
it("should remove permissions with --remove-perms", async function() {
|
||||
let args = "--name new --remove-perms core.host.list";
|
||||
await execCtl(`role edit new ${args}`);
|
||||
let roles = await getControl().send(new lib.RoleListRequest());
|
||||
let newRole = roles.find(role => role.name === "new");
|
||||
assert.deepEqual(newRole.permissions, ["core.instance.list"]);
|
||||
assert.deepEqual(newRole.permissions, new Set(["core.instance.list"]));
|
||||
});
|
||||
it("should grant default permissions with --grant-default", async function() {
|
||||
await execCtl("role edit new --grant-default");
|
||||
@@ -1126,7 +1126,7 @@ describe("Integration of Clusterio", function() {
|
||||
await execCtl('user set-roles temp "Cluster Admin"');
|
||||
let users = await getControl().send(new lib.UserListRequest());
|
||||
let tempUser = users.find(user => user.name === "temp");
|
||||
assert.deepEqual(tempUser.roles, [0]);
|
||||
assert.deepEqual(tempUser.roleIds, new Set([0]));
|
||||
assert.equal(getControl().userUpdates.length, 1);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user