fix: Admins should be able to add and remove themselves from collections

This commit is contained in:
Tom Moor
2023-05-04 21:52:59 -04:00
parent 0504e91aa6
commit ac8946f0c5
7 changed files with 30 additions and 18 deletions

View File

@@ -377,15 +377,29 @@ class WebsocketProvider extends React.Component<Props> {
// or otherwise just remove any membership state we have for that user.
this.socket.on(
"collections.remove_user",
action((event: WebsocketCollectionUserEvent) => {
async (event: WebsocketCollectionUserEvent) => {
if (auth.user && event.userId === auth.user.id) {
collections.remove(event.collectionId);
memberships.removeCollectionMemberships(event.collectionId);
// check if we still have access to the collection
try {
await collections.fetch(event.collectionId, {
force: true,
});
} catch (err) {
if (
err instanceof AuthorizationError ||
err instanceof NotFoundError
) {
collections.remove(event.collectionId);
memberships.remove(`${event.userId}-${event.collectionId}`);
return;
}
}
documents.removeCollectionDocuments(event.collectionId);
} else {
memberships.remove(`${event.userId}-${event.collectionId}`);
}
})
}
);
this.socket.on(