commit 92ec1324dc4c9517d9e2ce1ba2e3e330f848a0ea
parent 98cd96eb011f8ba04d7b3325b49759f91038268f
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 12 May 2016 02:21:18 -0400
Add a debug flag to prompt or throw on an attempted sync upload
extensions.zotero.sync.debugUploadPolicy = {1, 2}
1 to prompt, 2 to throw
This can be used to test sync functionality without altering the server
state unexpectedly. When prompting, the request body, if any, is logged
to debug output.
Diffstat:
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/sync/syncAPIClient.js b/chrome/content/zotero/xpcom/sync/syncAPIClient.js
@@ -36,6 +36,7 @@ Zotero.Sync.APIClient = function (options) {
this.apiVersion = options.apiVersion;
this.apiKey = options.apiKey;
this.caller = options.caller;
+ this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy');
this.failureDelayIntervals = [2500, 5000, 10000, 20000, 40000, 60000, 120000, 240000, 300000];
this.failureDelayMax = 60 * 60 * 1000; // 1 hour
@@ -573,6 +574,23 @@ Zotero.Sync.APIClient.prototype = {
if (!this.apiKey && !options.noAPIKey) {
throw new Error('API key not set');
}
+
+ if (Zotero.HTTP.isWriteMethod(method) && this.debugUploadPolicy) {
+ // Confirm uploads when extensions.zotero.sync.debugUploadPolicy is 1
+ if (this.debugUploadPolicy === 1) {
+ if (options.body) {
+ Zotero.debug(options.body);
+ }
+ if (!Services.prompt.confirm(null, "Allow Upload?", `Allow ${method} to ${uri}?`)) {
+ throw new Error(method + " request denied");
+ }
+ }
+ // Deny uploads when extensions.zotero.sync.debugUploadPolicy is 2
+ else if (this.debugUploadPolicy === 2) {
+ throw new Error(`Can't make ${method} request in read-only mode`);
+ }
+ }
+
let opts = {}
Object.assign(opts, options);
opts.headers = this.getHeaders(options.headers);
diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js
@@ -64,7 +64,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
var _currentLastSyncLabel;
var _errors = [];
-
this.getAPIClient = function (options = {}) {
return new Zotero.Sync.APIClient({
baseURL: this.baseURL,
@@ -113,7 +112,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
}
this.updateIcons('animate');
-
+
let client = this.getAPIClient({ apiKey });
let keyInfo = yield this.checkAccess(client, options);