1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Chore: Sync fuzzer: Fix incorrect expected state after removing the last user from a share (#13061)

This commit is contained in:
Henry Heino
2025-08-27 12:03:17 -07:00
committed by GitHub
parent 56fd5d828f
commit 424cc96d36
5 changed files with 68 additions and 19 deletions

View File

@@ -1,12 +1,15 @@
import { strict as assert } from 'assert';
import { ActionableClient, FolderData, FuzzContext, ItemId, NoteData, ShareOptions, TreeItem, assertIsFolder, isFolder } from './types';
import type Client from './Client';
import FolderRecord from './model/FolderRecord';
interface ClientData {
childIds: ItemId[];
}
interface ClientInfo {
email: string;
}
class ActionTracker {
private idToItem_: Map<ItemId, TreeItem> = new Map();
private tree_: Map<string, ClientData> = new Map();
@@ -87,7 +90,7 @@ class ActionTracker {
}
}
public track(client: { email: string }) {
public track(client: ClientInfo) {
const clientId = client.email;
// If the client's remote account already exists, continue using it:
if (!this.tree_.has(clientId)) {
@@ -271,6 +274,23 @@ class ActionTracker {
}
};
const removeFromShare = (id: ItemId, shareWith: ClientInfo) => {
const targetItem = this.idToItem_.get(id);
assertIsFolder(targetItem);
assert.ok(targetItem.isSharedWith(shareWith.email), `Folder ${id} should be shared with ${shareWith.email}`);
const otherSubTree = this.tree_.get(shareWith.email);
this.tree_.set(shareWith.email, {
...otherSubTree,
childIds: otherSubTree.childIds.filter(childId => childId !== id),
});
this.idToItem_.set(id, targetItem.withRemovedFromShare(shareWith.email));
this.checkRep_();
};
const tracker: ActionableClient = {
createNote: (data: NoteData) => {
assertWriteable(data.parentId);
@@ -311,6 +331,7 @@ class ActionTracker {
childIds: getChildIds(data.id),
sharedWith: [],
ownedByEmail: clientId,
isShared: false,
}));
addChild(data.parentId, data.id);
@@ -330,7 +351,7 @@ class ActionTracker {
this.checkRep_();
return Promise.resolve();
},
shareFolder: (id: ItemId, shareWith: Client, options: ShareOptions) => {
shareFolder: (id: ItemId, shareWith: ClientInfo, options: ShareOptions) => {
const itemToShare = this.idToItem_.get(id);
assertIsFolder(itemToShare);
@@ -354,19 +375,16 @@ class ActionTracker {
this.checkRep_();
return Promise.resolve();
},
removeFromShare: (id: ItemId, shareWith: Client) => {
removeFromShare: (id, client) => Promise.resolve(removeFromShare(id, client)),
deleteAssociatedShare: (id: ItemId) => {
const targetItem = this.idToItem_.get(id);
assertIsFolder(targetItem);
assert.ok(targetItem.isSharedWith(shareWith.email), `Folder ${id} should be shared with ${shareWith.label}`);
for (const recipient of targetItem.shareRecipients) {
removeFromShare(id, { email: recipient });
}
const otherSubTree = this.tree_.get(shareWith.email);
this.tree_.set(shareWith.email, {
...otherSubTree,
childIds: otherSubTree.childIds.filter(childId => childId !== id),
});
this.idToItem_.set(id, targetItem.withUnshared(shareWith.email));
this.idToItem_.set(id, targetItem.withUnshared());
this.checkRep_();
return Promise.resolve();