Don't show missing-group warning for skipped groups

This commit is contained in:
Dan Stillman 2016-07-20 10:04:55 -04:00
parent 1bd058ed48
commit 01ba8dfc34
2 changed files with 46 additions and 12 deletions

View file

@ -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 {

View file

@ -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* () {