mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
Merge pull request #1056 from bbassie/fix/subscription-permission-revoke
Drop subscriptions when a user loses permission for them
This commit is contained in:
6 files changed
+188
-17
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type winston from "winston";
|
||||
import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
|
||||
import type { ControllerArgs } from "../controller.js";
|
||||
import type ControlConnection from "./ControlConnection.js";
|
||||
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
||||
import type { Static } from "@sinclair/typebox";
|
||||
import finalhandler from "finalhandler";
|
||||
@@ -1087,17 +1088,24 @@ export default class Controller {
|
||||
userPermissionsUpdated(user: Readonly<User>) {
|
||||
for (let controlConnection of this.wsServer.controlConnections.values()) {
|
||||
if (controlConnection.user === user) {
|
||||
controlConnection.send(
|
||||
new lib.AccountUpdateEvent([...user.roles].map(r => ({
|
||||
name: r.name,
|
||||
id: r.id,
|
||||
permissions: [...r.permissions],
|
||||
})))
|
||||
);
|
||||
this._controlPermissionsUpdated(controlConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_controlPermissionsUpdated(controlConnection: ControlConnection) {
|
||||
const user = controlConnection.user;
|
||||
this.subscriptions.checkLinkPermissions(controlConnection, user);
|
||||
controlConnection.checkLogPermission();
|
||||
controlConnection.send(
|
||||
new lib.AccountUpdateEvent([...user.roles].map(r => ({
|
||||
name: r.name,
|
||||
id: r.id,
|
||||
permissions: [...r.permissions],
|
||||
})))
|
||||
);
|
||||
}
|
||||
|
||||
rolesUpdated(roles: lib.Role[]) {
|
||||
this.subscriptions.broadcast(new lib.RoleUpdatesEvent(roles));
|
||||
this.hooks.rolesUpdated.invoke(roles);
|
||||
@@ -1105,15 +1113,7 @@ export default class Controller {
|
||||
for (const role of roles) {
|
||||
for (let controlConnection of this.wsServer.controlConnections.values()) {
|
||||
if (controlConnection.user.roles.has(role)) {
|
||||
controlConnection.send(
|
||||
new lib.AccountUpdateEvent(
|
||||
[...controlConnection.user.roles].map(r => ({
|
||||
name: r.name,
|
||||
id: r.id,
|
||||
permissions: [...r.permissions],
|
||||
}))
|
||||
)
|
||||
);
|
||||
this._controlPermissionsUpdated(controlConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user