From 01ba8dfc34972e77074555f7c950fd948e44b2f5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 20 Jul 2016 10:04:55 -0400 Subject: [PATCH] Don't show missing-group warning for skipped groups --- .../content/zotero/xpcom/sync/syncRunner.js | 28 ++++++++++------- test/tests/syncRunnerTest.js | 30 ++++++++++++++++++- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 6ad0eed57..079270c3d 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -293,6 +293,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { */ this.checkLibraries = Zotero.Promise.coroutine(function* (client, options, keyInfo, libraries = []) { var access = keyInfo.access; + var syncAllLibraries = !libraries || !libraries.length; // TODO: Ability to remove or disable editing of user library? @@ -336,13 +337,11 @@ Zotero.Sync.Runner_Module = function (options = {}) { let remoteGroupVersions = yield client.getGroupVersions(keyInfo.userID); let remoteGroupIDs = Object.keys(remoteGroupVersions).map(id => parseInt(id)); - Zotero.debug(remoteGroupVersions); + let skippedGroups = Zotero.Sync.Data.Local.getSkippedGroups(); // Remove skipped groups if (syncAllLibraries) { - let newGroups = Zotero.Utilities.arrayDiff( - remoteGroupIDs, Zotero.Sync.Data.Local.getSkippedGroups() - ); + let newGroups = Zotero.Utilities.arrayDiff(remoteGroupIDs, skippedGroups); Zotero.Utilities.arrayDiff(remoteGroupIDs, newGroups) .forEach(id => { delete remoteGroupVersions[id] }); remoteGroupIDs = newGroups; @@ -379,13 +378,20 @@ Zotero.Sync.Runner_Module = function (options = {}) { // Get local groups (all if syncing all libraries or just selected ones) that don't // exist remotely // TODO: Use explicit removals? - remotelyMissingGroups = Zotero.Utilities.arrayDiff( - syncAllLibraries - ? Zotero.Groups.getAll().map(g => g.id) - : libraries.filter(id => Zotero.Libraries.get(id).libraryType == 'group') - .map(id => Zotero.Groups.getGroupIDFromLibraryID(id)), - remoteGroupIDs - ).map(id => Zotero.Groups.get(id)); + let localGroups; + if (syncAllLibraries) { + localGroups = Zotero.Groups.getAll() + .map(g => g.id) + // Don't include skipped groups + .filter(id => skippedGroups.indexOf(id) == -1); + } + else { + localGroups = libraries + .filter(id => Zotero.Libraries.get(id).libraryType == 'group') + .map(id => Zotero.Groups.getGroupIDFromLibraryID(id)) + } + remotelyMissingGroups = Zotero.Utilities.arrayDiff(localGroups, remoteGroupIDs) + .map(id => Zotero.Groups.get(id)); } // No group access else { diff --git a/test/tests/syncRunnerTest.js b/test/tests/syncRunnerTest.js index 5c27fb849..1470bb3d6 100644 --- a/test/tests/syncRunnerTest.js +++ b/test/tests/syncRunnerTest.js @@ -249,7 +249,7 @@ describe("Zotero.Sync.Runner", function () { assert.sameMembers(libraries, [group1.libraryID]); }) - it("should filter out skipped libraries if library list not provided", function* () { + it("should filter out nonexistent 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}"]`); @@ -266,6 +266,34 @@ describe("Zotero.Sync.Runner", function () { var group = Zotero.Groups.get(unskippedGroupID); assert.lengthOf(libraries, 2); assert.sameMembers(libraries, [userLibraryID, group.libraryID]); + + assert.isFalse(Zotero.Groups.get(skippedGroupID)); + }); + + it("should filter out existing 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}"]`); + + var skippedGroup = yield createGroup({ + id: skippedGroupID, + version: responses.groups.memberGroup.json.version - 1 + }); + + 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]); + + assert.equal(skippedGroup.version, responses.groups.memberGroup.json.version - 1); }); it("shouldn't filter out skipped libraries if library list is provided", function* () {