Skip to content

Commit

Permalink
Disallow inPublications for linked-file attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Apr 27, 2017
1 parent d715197 commit 9bd01af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions chrome/content/zotero/xpcom/data/item.js
Expand Up @@ -1513,8 +1513,13 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
}
}

if (this._inPublications && !this.isRegularItem() && !parentItemID) {
throw new Error("Top-level attachments and notes cannot be added to My Publications");
if (this._inPublications) {
if (!this.isRegularItem() && !parentItemID) {
throw new Error("Top-level attachments and notes cannot be added to My Publications");
}
if (this.isAttachment() && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
throw new Error("Linked-file attachments cannot be added to My Publications");
}
}

// Trashed status
Expand Down
14 changes: 13 additions & 1 deletion test/tests/itemTest.js
Expand Up @@ -363,7 +363,19 @@ describe("Zotero.Item", function () {
"SELECT COUNT(*) FROM publicationsItems WHERE itemID=?", item.id)),
0
);
})
});

it("should be invalid for linked-file attachments", function* () {
var item = yield createDataObject('item', { inPublications: true });
var attachment = yield Zotero.Attachments.linkFromFile({
file: OS.Path.join(getTestDataDirectory().path, 'test.png'),
parentItemID: item.id
});
attachment.inPublications = true;
var e = yield getPromiseError(attachment.saveTx());
assert.ok(e);
assert.include(e.message, "Linked-file attachments cannot be added to My Publications");
});
});

describe("#parentID", function () {
Expand Down

0 comments on commit 9bd01af

Please sign in to comment.