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:
Hornwitser authored and GitHub committed 2023-12-02 01:41:43 +01:00
1 parent f802e6ba67
commit e453a80155
37 files changed
+629 -613

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
import { Type, Static } from "@sinclair/typebox";
import PlayerStats from "../PlayerStats";
import PlayerStats from "./PlayerStats";
import { JsonString, StringEnum, jsonArray } from "./composites";
import { RawConfig } from "../config";
import type { User } from "../users";
import type { IControllerUser } from "./User";
import type { MessageRequest } from "./messages_core";
import { CollectorResultSerialized } from "../prometheus";
@@ -433,7 +433,7 @@ export class InstanceTransferSaveRequest {
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = ["controller", "host"] as const;
static permission(user: User, message: MessageRequest) {
static permission(user: IControllerUser, message: MessageRequest) {
user.checkPermission("core.instance.save.transfer");
if (typeof message.data === "object" && message.data !== null) {
const data = message.data as { copy: boolean, sourceName: string, targetName: string };