Fix copying of standalone attachments between libraries

Regression in f684984b07 (maybe a race condition)
This commit is contained in:
Dan Stillman 2022-08-13 02:00:24 -04:00
parent 30197a09d2
commit 344a10421a
2 changed files with 19 additions and 1 deletions

View file

@ -1615,7 +1615,7 @@ var CollectionTree = class CollectionTree extends LibraryTree {
return false;
}
let newAttachment = Zotero.Attachments.copyAttachmentToLibrary(item, targetLibraryID);
let newAttachment = await Zotero.Attachments.copyAttachmentToLibrary(item, targetLibraryID);
if (options.annotations) {
await Zotero.Items.copyChildItems(item, newAttachment);
}

View file

@ -891,6 +891,24 @@ describe("Zotero.CollectionTree", function() {
return group.eraseTx();
});
it("should copy a standalone attachment to a group", async function () {
await Zotero.Users.setCurrentUserID(1);
await Zotero.Users.setName(1, 'Name 1');
await Zotero.Users.setName(12345, 'Name 2');
var group = await createGroup();
var item = await importPDFAttachment();
var ids = (await onDrop('item', 'L' + group.libraryID, [item.id])).ids;
var newItem = Zotero.Items.get(ids[0]);
assert.equal(newItem.libraryID, group.libraryID);
assert.isTrue(newItem.isPDFAttachment());
return group.eraseTx();
});
it("should not copy an item or its attachment to a group twice", function* () {
var group = yield getGroup();