Prevent items in group libraries from being added to My Publications

And remove existing group items that have been added
This commit is contained in:
Dan Stillman 2017-05-04 21:18:44 -04:00
parent 3561864542
commit 2eef1702e0
5 changed files with 35 additions and 24 deletions

View file

@ -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");

View file

@ -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

View file

@ -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);

View file

@ -1,4 +1,4 @@
-- 94
-- 95
-- Copyright (c) 2009 Center for History and New Media
-- George Mason University, Fairfax, Virginia, USA

View file

@ -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 () {