1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Server: Fixed deleting a note that has been shared

This commit is contained in:
Laurent Cozic 2021-05-16 12:42:58 +02:00
parent e156ee1b58
commit 489995daef
2 changed files with 21 additions and 15 deletions

View File

@ -84,4 +84,20 @@ describe('ShareModel', function() {
expect(share1.id).toBe(share2.id);
});
test('should delete a note that has been shared', async function() {
const { user: user1 } = await createUserAndSession(1);
await createItemTree(user1.id, '', {
'000000000000000000000000000000F1': {
'00000000000000000000000000000001': null,
},
});
await models().share().shareNote(user1, '00000000000000000000000000000001');
const noteItem = await models().item().loadByJopId(user1.id, '00000000000000000000000000000001');
await models().item().delete(noteItem.id);
expect(await models().item().load(noteItem.id)).toBeFalsy();
});
});

View File

@ -1,4 +1,4 @@
import { Item, Share, ShareUser, ShareUserStatus, User, Uuid } from '../db';
import { Item, Share, ShareType, ShareUser, ShareUserStatus, User, Uuid } from '../db';
import { ErrorForbidden, ErrorNotFound } from '../utils/errors';
import BaseModel, { AclAction, DeleteOptions } from './BaseModel';
@ -123,23 +123,13 @@ export default class ShareUserModel extends BaseModel<ShareUser> {
return this.save({ ...shareUser, status });
});
// const item = await this.models().item().load(share.item_id);
// return this.withTransaction<Item>(async () => {
// await this.save({ ...shareUser, status });
// if (status === ShareUserStatus.Accepted) {
// if (share.type === ShareType.JoplinRootFolder) {
// // await this.models().item().shareJoplinFolderAndContent(share.id, share.owner_id, userId, item.jop_id);
// } else if (share.type === ShareType.App) {
// await this.models().userItem().add(userId, share.item_id, share.id);
// }
// }
// });
}
public async deleteByShare(share: Share): Promise<void> {
// Notes that are shared by link do not have associated ShareUser items,
// so there's nothing to do.
if (share.type !== ShareType.JoplinRootFolder) return;
const shareUsers = await this.byShareId(share.id, null);
await this.withTransaction(async () => {