www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit f68ee60524e6e20686c63895c481754bede772d6
parent 008321bb8984485ade04d928b65ab65ed2183579
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  5 Sep 2016 03:59:42 -0400

Follow-ups to getAPIKey() changes in 008321bb89

Addresses #1086

Diffstat:
Mchrome/content/zotero/preferences/preferences_sync.js | 4++--
Mchrome/content/zotero/xpcom/sync/syncLocal.js | 7+++++--
Mchrome/content/zotero/xpcom/sync/syncRunner.js | 12+++++++++---
Mtest/tests/preferences_syncTest.js | 10+++++-----
Mtest/tests/syncLocalTest.js | 6+++---
5 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/chrome/content/zotero/preferences/preferences_sync.js b/chrome/content/zotero/preferences/preferences_sync.js @@ -32,7 +32,7 @@ Zotero_Preferences.Sync = { this.updateStorageSettingsUI(); var username = Zotero.Users.getCurrentUsername() || Zotero.Prefs.get('sync.server.username') || " "; - var apiKey = Zotero.Sync.Data.Local.getAPIKey(); + var apiKey = yield Zotero.Sync.Data.Local.getAPIKey(); this.displayFields(apiKey ? username : ""); var pass = Zotero.Sync.Runner.getStorageController('webdav').password; @@ -286,7 +286,7 @@ Zotero_Preferences.Sync = { var loadingLabel = Zotero.getString("zotero.preferences.sync.librariesToSync.loadingLibraries"); addRow(loadingLabel, "loading", false, false); - var apiKey = Zotero.Sync.Data.Local.getAPIKey(); + var apiKey = yield Zotero.Sync.Data.Local.getAPIKey(); var client = Zotero.Sync.Runner.getAPIClient({apiKey}); var groups = []; try { diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -42,13 +42,16 @@ Zotero.Sync.Data.Local = { }), - getAPIKey: function () { + /** + * @return {Promise} + */ + getAPIKey: Zotero.Promise.method(function () { var login = this._getAPIKeyLoginInfo(); return login ? login.password // Fallback to old username/password : this._getAPIKeyFromLogin(); - }, + }), setAPIKey: function (apiKey) { diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -33,7 +33,13 @@ if (!Zotero.Sync) { Zotero.Sync.Runner_Module = function (options = {}) { const stopOnError = false; - Zotero.defineProperty(this, 'enabled', { get: () => _apiKey || Zotero.Sync.Data.Local.getAPIKey() }); + Zotero.defineProperty(this, 'enabled', { + get: () => { + if (_apiKey) return true; + var username = Zotero.Prefs.get('sync.server.username'); + return username && Zotero.Sync.Data.Local.getLegacyPassword(username); + } + }); Zotero.defineProperty(this, 'syncInProgress', { get: () => _syncInProgress }); Zotero.defineProperty(this, 'lastSyncStatus', { get: () => _lastSyncStatus }); @@ -1267,7 +1273,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { this.deleteAPIKey = Zotero.Promise.coroutine(function* (){ - var apiKey = Zotero.Sync.Data.Local.getAPIKey(); + var apiKey = yield Zotero.Sync.Data.Local.getAPIKey(); var client = this.getAPIClient({apiKey}); Zotero.Sync.Data.Local.setAPIKey(); yield client.deleteAPIKey(); @@ -1313,7 +1319,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { } - var _getAPIKey = Zotero.Promise.coroutine(function* () { + var _getAPIKey = Zotero.Promise.method(function () { // Set as .apiKey on Runner in tests or set in login manager return _apiKey || Zotero.Sync.Data.Local.getAPIKey() }) diff --git a/test/tests/preferences_syncTest.js b/test/tests/preferences_syncTest.js @@ -69,7 +69,7 @@ describe("Sync Preferences", function () { getAPIKeyFromCredentialsStub.resolves(apiResponse); yield setCredentials("Username", "correctPassword"); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); assert.equal(doc.getElementById('sync-unauthorized').getAttribute('hidden'), 'true'); }); @@ -79,7 +79,7 @@ describe("Sync Preferences", function () { yield setCredentials("Username", "incorrectPassword"); assert.isTrue(Zotero.alert.called); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(), ""); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), ""); assert.equal(doc.getElementById('sync-authorized').getAttribute('hidden'), 'true'); }); @@ -87,12 +87,12 @@ describe("Sync Preferences", function () { it("should delete API key and display auth form when 'Unlink Account' clicked", function* () { getAPIKeyFromCredentialsStub.resolves(apiResponse); yield setCredentials("Username", "correctPassword"); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); yield win.Zotero_Preferences.Sync.unlinkAccount(false); assert.isTrue(deleteAPIKey.called); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(), ""); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), ""); assert.equal(doc.getElementById('sync-authorized').getAttribute('hidden'), 'true'); }); @@ -103,7 +103,7 @@ describe("Sync Preferences", function () { waitForDialog(null, 'cancel'); yield win.Zotero_Preferences.Sync.unlinkAccount(); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey); assert.equal(doc.getElementById('sync-unauthorized').getAttribute('hidden'), 'true'); }); diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js @@ -6,9 +6,9 @@ describe("Zotero.Sync.Data.Local", function() { var apiKey1 = Zotero.Utilities.randomString(24); var apiKey2 = Zotero.Utilities.randomString(24); Zotero.Sync.Data.Local.setAPIKey(apiKey1); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey1), apiKey1); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey1), apiKey1); Zotero.Sync.Data.Local.setAPIKey(apiKey2); - assert.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey2), apiKey2); + yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey2), apiKey2); }) @@ -16,7 +16,7 @@ describe("Zotero.Sync.Data.Local", function() { var apiKey = Zotero.Utilities.randomString(24); Zotero.Sync.Data.Local.setAPIKey(apiKey); Zotero.Sync.Data.Local.setAPIKey(""); - assert.strictEqual(Zotero.Sync.Data.Local.getAPIKey(apiKey), ""); + yield assert.eventually.strictEqual(Zotero.Sync.Data.Local.getAPIKey(apiKey), ""); }) })