Skip edit check if skipAll is passed to object save

This commit is contained in:
Dan Stillman 2017-05-22 17:29:56 -04:00
parent 0ac37ab65a
commit 265df6d48c
2 changed files with 51 additions and 10 deletions

View file

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

View file

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