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