From d7449b4d78faaafcbb8855b34a7687c3f2b6a1d2 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 13 Jul 2023 19:50:36 -0400 Subject: [PATCH] Fix merging of group attachments with annotations created by another user https://forums.zotero.org/discussion/106197/merge-in-group-library-fails-despite-having-edit-permissions --- chrome/content/zotero/xpcom/data/items.js | 17 +++++++++++++---- test/tests/itemsTest.js | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 8bb34febd8..de59e35a04 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -946,10 +946,12 @@ Zotero.Items = function() { * * @param {Zotero.Item} fromItem * @param {Zotero.Item} toItem - * @param {Boolean} includeTrashed + * @param {Object} options + * @param {Boolean} [includeTrashed=false] + * @param {Boolean} [skipEditCheck=false] * @return {Promise} */ - this.moveChildItems = async function (fromItem, toItem, includeTrashed = false) { + this.moveChildItems = async function (fromItem, toItem, { includeTrashed = false, skipEditCheck = false } = {}) { Zotero.DB.requireTransaction(); // Annotations on files @@ -961,7 +963,7 @@ Zotero.Items = function() { continue; } annotation.parentItemID = toItem.id; - await annotation.save(); + await annotation.save({ skipEditCheck }); } } @@ -1071,7 +1073,14 @@ Zotero.Items = function() { let doMerge = async (fromAttachment, toAttachment) => { mergedMasterAttachments.add(toAttachment.id); - await this.moveChildItems(fromAttachment, toAttachment, true); + await this.moveChildItems( + fromAttachment, + toAttachment, + { + includeTrashed: true, + skipEditCheck: true + } + ); await this._moveEmbeddedNote(fromAttachment, toAttachment); await this._moveRelations(fromAttachment, toAttachment); diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js index 0cb4faa272..a815983125 100644 --- a/test/tests/itemsTest.js +++ b/test/tests/itemsTest.js @@ -628,7 +628,27 @@ describe("Zotero.Items", function () { assert.notInclude(annotation2Note.getNote(), attachment2.key); assert.include(annotation2Note.getNote(), attachment1.key); }); - + + it("should merge attachments in group library with annotation created by another user", async function () { + var otherUserID = 92624235; + await Zotero.Users.setName(otherUserID, 'merged-annotation-user'); + + let group = await createGroup(); + let item1 = await createDataObject('item', { libraryID: group.libraryID }); + let attachment1 = await importPDFAttachment(item1); + let annotation1 = await createAnnotation('note', attachment1); + + let item2 = item1.clone(); + await item2.saveTx(); + let attachment2 = await importPDFAttachment(item2); + let annotation2 = await createAnnotation('highlight', attachment2, { createdByUserID: otherUserID }); + + await Zotero.Items.merge(item1, [item2]); + + assert.equal(annotation2.parentItemID, attachment1.id); + assert.equal(annotation2.createdByUserID, otherUserID); + }); + it("should update all item keys when moving notes", async function () { let attachmentFilenames = [ 'recognizePDF_test_arXiv.pdf',