Don't show items with annotated attachments after moving to trash

https://forums.zotero.org/discussion/100775/deleted-items-keep-reappearing-in-my-library

Regression from c3ee588bf
This commit is contained in:
Dan Stillman 2022-11-28 04:30:22 -05:00
parent ca1f83e9c9
commit 76f2f0c783
2 changed files with 46 additions and 8 deletions

View file

@ -1101,16 +1101,24 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
// Exclude deleted items (and their child items) by default
let not = deleted ? "" : "NOT ";
let op = deleted ? "OR" : "AND";
sql += " WHERE ("
+ `itemID ${not} IN (SELECT itemID FROM deletedItems) `
+ `${op} itemID ${not}IN (SELECT itemID FROM itemNotes `
sql += ` WHERE (itemID ${not} IN (`
// Deleted items
+ "SELECT itemID FROM deletedItems "
// Child notes of deleted items
+ "UNION SELECT itemID FROM itemNotes "
+ "WHERE parentItemID IS NOT NULL AND "
+ "parentItemID IN (SELECT itemID FROM deletedItems)) "
+ `${op} itemID ${not}IN (SELECT itemID FROM itemAttachments `
+ "parentItemID IN (SELECT itemID FROM deletedItems) "
// Child attachments of deleted items
+ "UNION SELECT itemID FROM itemAttachments "
+ "WHERE parentItemID IS NOT NULL AND "
+ "parentItemID IN (SELECT itemID FROM deletedItems))"
+ ")";
+ "parentItemID IN (SELECT itemID FROM deletedItems)"
// Annotations of deleted attachments
+ "UNION SELECT itemID FROM itemAnnotations "
+ "WHERE parentItemID IN (SELECT itemID FROM deletedItems)"
// Annotations of attachments of deleted items
+ "UNION SELECT itemID FROM itemAnnotations "
+ "WHERE parentItemID IN (SELECT itemID FROM itemAttachments WHERE parentItemID IN (SELECT itemID FROM deletedItems))"
+ "))";
if (noChildren){
sql += " AND (itemID NOT IN (SELECT itemID FROM itemNotes "

View file

@ -610,6 +610,36 @@ describe("Zotero.Search", function() {
});
});
});
describe("deleted", function () {
describe("if not present", function () {
it("should not match regular items in trash with annotated child attachments", async function () {
var item = await createDataObject('item');
item.deleted = true;
await item.saveTx();
var attachment = await importPDFAttachment(item);
await createAnnotation('highlight', attachment);
var s = new Zotero.Search();
s.libraryID = userLibraryID;
var matches = await s.search();
assert.notInclude(matches, attachment.id);
});
it("should not match regular items with annotated child attachments in trash", async function () {
var item = await createDataObject('item');
var attachment = await importPDFAttachment(item);
attachment.deleted = true;
await attachment.saveTx();
await createAnnotation('highlight', attachment);
var s = new Zotero.Search();
s.libraryID = userLibraryID;
var matches = await s.search();
assert.notInclude(matches, attachment.id);
});
});
});
});
});