From 88184b341bb897761dbd1c29e73c5b0f06ce1f77 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 24 Feb 2017 00:10:06 -0500 Subject: [PATCH] Setting a library's 'editable' to false should do same for 'filesEditable' --- chrome/content/zotero/xpcom/data/library.js | 7 +++++++ test/tests/libraryTest.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js index 1e576c9787..70e69b943f 100644 --- a/chrome/content/zotero/xpcom/data/library.js +++ b/chrome/content/zotero/xpcom/data/library.js @@ -250,13 +250,20 @@ Zotero.Library.prototype._set = function(prop, val) { throw new Error('Cannot create library of type "' + val + '"'); } break; + case '_libraryEditable': case '_libraryFilesEditable': if (['user', 'publications'].indexOf(this._libraryType) != -1) { throw new Error('Cannot change ' + prop + ' for ' + this._libraryType + ' library'); } val = !!val; + + // Setting 'editable' to false should also set 'filesEditable' to false + if (prop == '_libraryEditable' && !val) { + this._set('_libraryFilesEditable', false); + } break; + case '_libraryVersion': var newVal = Number.parseInt(val, 10); if (newVal != val) { diff --git a/test/tests/libraryTest.js b/test/tests/libraryTest.js index 5c2f91810d..b648cee0c0 100644 --- a/test/tests/libraryTest.js +++ b/test/tests/libraryTest.js @@ -81,6 +81,17 @@ describe("Zotero.Library", function() { assert.isFalse(Zotero.Libraries.isEditable(library.libraryID), "sets editable in cache to false"); assert.equal((yield Zotero.DB.valueQueryAsync("SELECT editable FROM libraries WHERE libraryID=?", library.libraryID)), 0) }); + + it("should also set filesEditable to false", function* () { + let library = yield createGroup({ editable: true, filesEditable: true }); + assert.isTrue(library.filesEditable); + + library.editable = false; + yield library.saveTx(); + assert.isFalse(library.filesEditable); + assert.equal((yield Zotero.DB.valueQueryAsync("SELECT filesEditable FROM libraries WHERE libraryID=?", library.libraryID)), 0) + }); + it("should not be settable for user and publications libraries", function* () { let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID); assert.throws(function() {library.editable = false}, /^Cannot change _libraryEditable for user library$/, "does not allow setting user library as not editable");