From 30cefca18ef595caca32aa004ee52c405628cece Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 20 May 2020 08:45:37 -0400 Subject: [PATCH] Fix cross-library collection dragging from read-only library This has apparently always been broken. --- .../zotero/xpcom/collectionTreeView.js | 2 +- test/tests/collectionTreeViewTest.js | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 211e05b9af..19248dc042 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -2093,7 +2093,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r var collectionID = yield newCollection.save(); // Record link - yield c.addLinkedCollection(newCollection); + yield newCollection.addLinkedCollection(c); // Recursively copy subcollections if (desc.children.length) { diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js index 8faa6baf0f..52432caa2a 100644 --- a/test/tests/collectionTreeViewTest.js +++ b/test/tests/collectionTreeViewTest.js @@ -868,6 +868,26 @@ describe("Zotero.CollectionTreeView", function() { assert.isFalse(yield canDrop('item', 'L' + group.libraryID, [item.id])); }) + it("should copy an item from a read-only group to an editable group", async function () { + var group1 = await createGroup(); + var item = await createDataObject('item', { libraryID: group1.libraryID }); + group1.editable = false; + await group1.saveTx(); + var group2 = await createGroup(); + + await cv.selectLibrary(group1.libraryID); + await waitForItemsLoad(win); + + await drop('item', 'L' + group2.libraryID, [item.id]); + + assert.isFalse(await item.getLinkedItem(group2.libraryID)); + // New collection should link back to original + assert.ok(await item.getLinkedItem(group2.libraryID, true)); + + await group1.eraseTx(); + await group2.eraseTx(); + }); + it("should remove a linked, trashed item in a group from the trash and collections", function* () { var group = yield getGroup(); var collection = yield createDataObject('collection', { libraryID: group.libraryID }); @@ -1122,6 +1142,32 @@ describe("Zotero.CollectionTreeView", function() { assert.isFalse(newCollectionA.hasItem(newItemB)); assert.isFalse(newCollectionB.hasItem(newItemA)); }) + + it("should copy a collection from a read-only group to another group", async function () { + var group1 = await createGroup(); + var collection = await createDataObject('collection', { libraryID: group1.libraryID }); + var item = await createDataObject('item', { libraryID: group1.libraryID, collections: [collection.id] }); + group1.editable = false; + await group1.saveTx(); + + var group2 = await getGroup(); + + await cv.selectCollection(collection.id); + await waitForItemsLoad(win); + + await drop('collection', 'L' + group2.libraryID, [collection.id]); + + assert.isFalse(await collection.getLinkedCollection(group2.libraryID)); + // New collection should link back to original + assert.ok(await collection.getLinkedCollection(group2.libraryID, true)); + + assert.isFalse(await item.getLinkedItem(group2.libraryID)); + // New item should link back to original + assert.ok(await item.getLinkedItem(group2.libraryID, true)); + + await group1.eraseTx(); + await group2.eraseTx(); + }); })