From 05fef08a6378a7dde1ca8320e268f7a2d8323517 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 28 Oct 2013 23:35:28 -0400 Subject: [PATCH] Store inter-group linked-item relations with target, not source, library User may not have write access to source library --- chrome/content/zotero/xpcom/attachments.js | 2 +- chrome/content/zotero/xpcom/collectionTreeView.js | 4 ++-- chrome/content/zotero/xpcom/data/item.js | 7 ++++--- chrome/content/zotero/xpcom/data/relation.js | 2 ++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index f789e125b..8e74bb819 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -1251,7 +1251,7 @@ Zotero.Attachments = new function(){ Zotero.File.copyDirectory(dir, newDir); } - attachment.addLinkedItem(newAttachment); + newAttachment.addLinkedItem(attachment); return newAttachment.id; } diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 9f506b9fc..e74e5fb68 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -1429,7 +1429,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient) //var newItem = Zotero.Items.get(id); // Record link - item.addLinkedItem(newItem); + newItem.addLinkedItem(item); var newID = id; if (item.isNote()) { @@ -1452,7 +1452,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient) newNote.setSource(newItem.id); newNote.save(); - note.addLinkedItem(newNote); + newNote.addLinkedItem(note); } } diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 70fe345ed..2a7df206d 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4006,9 +4006,10 @@ Zotero.Item.prototype.addLinkedItem = function (item) { return false; } - // If both group libraries, store relation with source group. - // Otherwise, store with personal library. - var libraryID = (this.libraryID && item.libraryID) ? this.libraryID : null; + // If one of the items is a personal library, store relation with that. + // Otherwise, use current item's library (which in calling code is the + // new, copied item). + var libraryID = (!this.libraryID || !item.libraryID) ? null : this.libraryID; Zotero.Relations.add(libraryID, url1, predicate, url2); } diff --git a/chrome/content/zotero/xpcom/data/relation.js b/chrome/content/zotero/xpcom/data/relation.js index 4e4f14c6f..32a3eee37 100644 --- a/chrome/content/zotero/xpcom/data/relation.js +++ b/chrome/content/zotero/xpcom/data/relation.js @@ -158,6 +158,8 @@ Zotero.Relation.prototype.save = function () { throw ("Missing object in Zotero.Relation.save()"); } + Zotero.Relations.editCheck(this); + var sql = "INSERT INTO relations " + "(libraryID, subject, predicate, object, clientDateModified) " + "VALUES (?, ?, ?, ?, ?)";