commit 2eef1702e0b0c959fb897ada874a300494ea214f
parent 35618645429b426adbb54262665bcf344bbaff2f
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 4 May 2017 21:18:44 -0400
Prevent items in group libraries from being added to My Publications
And remove existing group items that have been added
Diffstat:
5 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -1639,6 +1639,14 @@ Zotero.CollectionTreeView.prototype.canDropCheck = function (row, orient, dataTr
Zotero.debug("FeedItems cannot be added to My Publications");
return false;
}
+ if (item.inPublications) {
+ Zotero.debug("Item " + item.id + " already exists in My Publications");
+ continue;
+ }
+ if (treeRow.ref.libraryID != item.libraryID) {
+ Zotero.debug("Cross-library drag to My Publications not allowed");
+ continue;
+ }
skip = false;
continue;
}
@@ -1662,10 +1670,14 @@ Zotero.CollectionTreeView.prototype.canDropCheck = function (row, orient, dataTr
return false;
}
- // Allow drags to collections. Item collection membership is an asynchronous
- // check, so we do that on drop()
+ // Make sure there's at least one item that's not already in this destination
if (treeRow.isCollection()) {
+ if (treeRow.ref.hasItem(item.id)) {
+ Zotero.debug("Item " + item.id + " already exists in collection");
+ continue;
+ }
skip = false;
+ continue;
}
}
if (skip) {
@@ -1785,27 +1797,10 @@ Zotero.CollectionTreeView.prototype.canDropCheckAsync = Zotero.Promise.coroutine
continue;
}
- // Intra-library drag
-
- // Make sure there's at least one item that's not already in this destination
- if (treeRow.isCollection()) {
- if (treeRow.ref.hasItem(item.id)) {
- Zotero.debug("Item " + item.id + " already exists in collection");
- continue;
- }
- skip = false;
- continue;
- }
-
- // Make sure there's at least one item that's not already in My Publications
- if (treeRow.isPublications()) {
- if (item.inPublications) {
- Zotero.debug("Item " + item.id + " already exists in My Publications");
- continue;
- }
- skip = false;
- continue;
- }
+ // Intra-library drags have already been vetted by canDrop(). This 'break' should be
+ // changed to a 'continue' if any asynchronous checks that stop the drag are added above
+ skip = false;
+ break;
}
if (skip) {
Zotero.debug("Drag skipped");
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -1519,6 +1519,9 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
if (this.isAttachment() && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
throw new Error("Linked-file attachments cannot be added to My Publications");
}
+ if (Zotero.Libraries.get(this.libraryID).libraryType != 'user') {
+ throw new Error("Only items in user libraries can be added to My Publications");
+ }
}
// Trashed status
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -2416,6 +2416,10 @@ Zotero.Schema = new function(){
}
yield Zotero.DB.queryAsync("DELETE FROM publicationsItems WHERE itemID IN (SELECT itemID FROM items JOIN itemAttachments USING (itemID) WHERE linkMode=2)");
}
+
+ else if (i == 95) {
+ yield Zotero.DB.queryAsync("DELETE FROM publicationsItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE libraryID=1)");
+ }
}
yield _updateDBVersion('userdata', toVersion);
diff --git a/resource/schema/userdata.sql b/resource/schema/userdata.sql
@@ -1,4 +1,4 @@
--- 94
+-- 95
-- Copyright (c) 2009 Center for History and New Media
-- George Mason University, Fairfax, Virginia, USA
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -376,6 +376,15 @@ describe("Zotero.Item", function () {
assert.ok(e);
assert.include(e.message, "Linked-file attachments cannot be added to My Publications");
});
+
+ it("should be invalid for group library items", function* () {
+ var group = yield getGroup();
+ var item = yield createDataObject('item', { libraryID: group.libraryID });
+ item.inPublications = true;
+ var e = yield getPromiseError(item.saveTx());
+ assert.ok(e);
+ assert.equal(e.message, "Only items in user libraries can be added to My Publications");
+ });
});
describe("#parentID", function () {