commit 265df6d48c5bffceeb17c56f6f00710963ba5a00
parent 0ac37ab65a4f04f028f7c91a0493dd964463f9ee
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 22 May 2017 17:29:56 -0400
Skip edit check if skipAll is passed to object save
Diffstat:
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
@@ -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
@@ -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 () {