From 265df6d48c5bffceeb17c56f6f00710963ba5a00 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 22 May 2017 17:29:56 -0400 Subject: [PATCH] Skip edit check if skipAll is passed to object save --- .../content/zotero/xpcom/data/dataObject.js | 20 ++++----- test/tests/dataObjectTest.js | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index cbb76c93c9..c625098985 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -801,16 +801,6 @@ Zotero.DataObject.prototype.save = Zotero.Promise.coroutine(function* (options = env.options.tx = true; } - var proceed = yield this._initSave(env); - if (!proceed) return false; - - if (env.isNew) { - Zotero.debug('Saving data for new ' + this._objectType + ' to database', 4); - } - else { - Zotero.debug('Updating database with new ' + this._objectType + ' data', 4); - } - if (env.options.skipAll) { [ 'skipDateModifiedUpdate', @@ -822,6 +812,16 @@ Zotero.DataObject.prototype.save = Zotero.Promise.coroutine(function* (options = ].forEach(x => env.options[x] = true); } + var proceed = yield this._initSave(env); + if (!proceed) return false; + + if (env.isNew) { + Zotero.debug('Saving data for new ' + this._objectType + ' to database', 4); + } + else { + Zotero.debug('Updating database with new ' + this._objectType + ' data', 4); + } + try { if (Zotero.DataObject.prototype._finalizeSave == this._finalizeSave) { throw new Error("_finalizeSave not implemented for Zotero." + this._ObjectType); diff --git a/test/tests/dataObjectTest.js b/test/tests/dataObjectTest.js index bee3aaae15..eab9324ab8 100644 --- a/test/tests/dataObjectTest.js +++ b/test/tests/dataObjectTest.js @@ -263,6 +263,47 @@ describe("Zotero.DataObject", function() { assert.isFalse(obj.hasChanged()); } }) + + describe("Edit Check", function () { + var group; + + before(function* () { + group = yield createGroup({ + editable: false + }); + }); + + it("should disallow saving to read-only libraries", function* () { + let item = createUnsavedDataObject('item', { libraryID: group.libraryID }); + var e = yield getPromiseError(item.saveTx()); + assert.ok(e); + assert.include(e.message, "read-only"); + }); + + it("should allow saving if skipEditCheck is passed", function* () { + let item = createUnsavedDataObject('item', { libraryID: group.libraryID }); + var e = yield getPromiseError(item.saveTx({ + skipEditCheck: true + })); + assert.isFalse(e); + }); + + it("should allow saving if skipAll is passed", function* () { + let item = createUnsavedDataObject('item', { libraryID: group.libraryID }); + var e = yield getPromiseError(item.saveTx({ + skipAll: true + })); + assert.isFalse(e); + }); + }); + + describe("Options", function () { + describe("#skipAll", function () { + it("should include edit check", function* () { + + }); + }); + }); }) describe("#erase()", function () {