www

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

commit 9e6565fe0013fb6097d99138bf2483b031a4449f
parent b0f3a234d0a99e7d05fdabcf3497dd119aa6dd22
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 27 Jun 2016 16:42:55 -0400

Skip skipped groups when syncing

Except if a library list is passed to Zotero.Sync.Data.Runner.sync() (which
isn't done currently but will be in #1053)

Follow-up to #1033

Diffstat:
Mchrome/content/zotero/xpcom/sync/syncLocal.js | 26++++++++++++++++++++++++++
Mchrome/content/zotero/xpcom/sync/syncRunner.js | 17++++++++++++++++-
Mtest/tests/syncRunnerTest.js | 48++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -155,6 +155,32 @@ Zotero.Sync.Data.Local = { }), + getSkippedLibraries: function () { + return this._getSkippedLibrariesByPrefix("L"); + }, + + + getSkippedGroups: function () { + return this._getSkippedLibrariesByPrefix("G"); + }, + + + _getSkippedLibrariesByPrefix: function (prefix) { + var pref = 'sync.librariesToSkip'; + try { + var librariesToSkip = JSON.parse(Zotero.Prefs.get(pref) || '[]'); + return librariesToSkip + .filter(id => id.startsWith(prefix)) + .map(id => parseInt(id.substr(1))); + } + catch (e) { + Zotero.logError(e); + Zotero.Prefs.clear(pref); + return []; + } + }, + + /** * @return {nsILoginInfo|false} */ diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -80,7 +80,8 @@ Zotero.Sync.Runner_Module = function (options = {}) { * @param {Object} [options] * @param {Boolean} [options.background=false] Whether this is a background request, which * prevents some alerts from being shown - * @param {Integer[]} [options.libraries] IDs of libraries to sync + * @param {Integer[]} [options.libraries] IDs of libraries to sync; skipped libraries must + * be removed if unwanted * @param {Function} [options.onError] Function to pass errors to instead of * handling internally (used for testing) */ @@ -308,6 +309,10 @@ Zotero.Sync.Runner_Module = function (options = {}) { if (syncAllLibraries) { if (access.user && access.user.library) { libraries = [Zotero.Libraries.userLibraryID, Zotero.Libraries.publicationsLibraryID]; + // Remove skipped libraries + libraries = Zotero.Utilities.arrayDiff( + libraries, Zotero.Sync.Data.Local.getSkippedLibraries() + ); } } else { @@ -342,6 +347,16 @@ Zotero.Sync.Runner_Module = function (options = {}) { let remoteGroupIDs = Object.keys(remoteGroupVersions).map(id => parseInt(id)); Zotero.debug(remoteGroupVersions); + // Remove skipped groups + if (syncAllLibraries) { + let newGroups = Zotero.Utilities.arrayDiff( + remoteGroupIDs, Zotero.Sync.Data.Local.getSkippedGroups() + ); + Zotero.Utilities.arrayDiff(remoteGroupIDs, newGroups) + .forEach(id => { delete remoteGroupVersions[id] }); + remoteGroupIDs = newGroups; + } + for (let id in remoteGroupVersions) { id = parseInt(id); let group = Zotero.Groups.get(id); diff --git a/test/tests/syncRunnerTest.js b/test/tests/syncRunnerTest.js @@ -166,7 +166,13 @@ describe("Zotero.Sync.Runner", function () { }) describe("#checkLibraries()", function () { + beforeEach(function* () { + Zotero.Prefs.clear('sync.librariesToSkip'); + }); + afterEach(function* () { + Zotero.Prefs.clear('sync.librariesToSkip'); + var group = Zotero.Groups.get(responses.groups.ownerGroup.json.id); if (group) { yield group.eraseTx(); @@ -243,6 +249,48 @@ describe("Zotero.Sync.Runner", function () { assert.sameMembers(libraries, [group1.libraryID]); }) + it("should filter out skipped libraries if library list not provided", function* () { + var unskippedGroupID = responses.groups.ownerGroup.json.id; + var skippedGroupID = responses.groups.memberGroup.json.id; + Zotero.Prefs.set('sync.librariesToSkip', `["L4", "G${skippedGroupID}"]`); + + setResponse('userGroups.groupVersions'); + setResponse('groups.ownerGroup'); + setResponse('groups.memberGroup'); + var libraries = yield runner.checkLibraries( + runner.getAPIClient({ apiKey }), + false, + responses.keyInfo.fullAccess.json + ); + + var group = Zotero.Groups.get(unskippedGroupID); + assert.lengthOf(libraries, 2); + assert.sameMembers(libraries, [userLibraryID, group.libraryID]); + }); + + it("shouldn't filter out skipped libraries if library list is provided", function* () { + var groupData = responses.groups.memberGroup; + var group = yield createGroup({ + id: groupData.json.id, + version: groupData.json.version + }); + + Zotero.Prefs.set('sync.librariesToSkip', `["L4", "G${group.id}"]`); + + setResponse('userGroups.groupVersions'); + setResponse('groups.ownerGroup'); + setResponse('groups.memberGroup'); + var libraries = yield runner.checkLibraries( + runner.getAPIClient({ apiKey }), + false, + responses.keyInfo.fullAccess.json, + [userLibraryID, publicationsLibraryID, group.libraryID] + ); + + assert.lengthOf(libraries, 3); + assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID, group.libraryID]); + }); + it("should update outdated group metadata", function* () { // Create groups with same id as groups response but earlier versions var groupData1 = responses.groups.ownerGroup;