diff --git a/chrome/content/zotero/xpcom/sync/syncAPIClient.js b/chrome/content/zotero/xpcom/sync/syncAPIClient.js index 8a8bfb840c..40b7dab50b 100644 --- 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 index e02921bb52..250ee1a81e 100644 --- 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);