mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +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
@@ -355,6 +355,32 @@ export class SubscriptionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the subscriptions of a link against the permissions of a user,
|
||||
* removing those the user no longer has permission for.
|
||||
* Used when the permissions of a user changes.
|
||||
* @param link - Link to check the subscriptions of.
|
||||
* @param user - User the link is authenticated as.
|
||||
*/
|
||||
checkLinkPermissions(link: Link, user: IUser) {
|
||||
for (const [eventName, eventData] of this._events) {
|
||||
for (const [addressIndex, subscriber] of eventData.subscriptions) {
|
||||
if (subscriber.link !== link) {
|
||||
continue;
|
||||
}
|
||||
const request = new SubscriptionRequest(eventName, "subscribe", 0, subscriber.filters);
|
||||
const message = new MessageRequest(
|
||||
0, subscriber.address, new Address(Address.controller, 0), "SubscriptionRequest", request.toJSON(),
|
||||
);
|
||||
try {
|
||||
SubscriptionRequest.permission(user, message);
|
||||
} catch {
|
||||
eventData.subscriptions.delete(addressIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming subscription requests on a link
|
||||
* @param link - Link message was received on
|
||||
|
||||
Reference in new issue
Block a user