Commit ee116d60 authored by Hannah Stepanek's avatar Hannah Stepanek Committed by Robert Knight

Add service.groups setting to filter groups

parent 6783b96d
...@@ -48,6 +48,13 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses ...@@ -48,6 +48,13 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
* @return {Promise<Group[]>} * @return {Promise<Group[]>}
*/ */
function filterGroups(groups, isLoggedIn, directLinkedAnnotationId) { function filterGroups(groups, isLoggedIn, directLinkedAnnotationId) {
// If service groups are specified only return those.
// If a service group doesn't exist in the list of groups don't return it.
if (svc && svc.groups) {
const focusedGroups = groups.filter(g => svc.groups.includes(g.id));
return Promise.resolve(focusedGroups);
}
// Logged-in users always see the "Public" group. // Logged-in users always see the "Public" group.
if (isLoggedIn) { if (isLoggedIn) {
return Promise.resolve(groups); return Promise.resolve(groups);
......
...@@ -253,6 +253,46 @@ describe('groups', function() { ...@@ -253,6 +253,46 @@ describe('groups', function() {
}); });
}); });
}); });
[{
description: 'shows service groups',
services: [{ groups: ['abc123']}],
expected: ['abc123'],
},{
description: 'only shows service groups that exist',
services: [{ groups: ['abc123', 'no_exist']}],
expected: ['abc123'],
},{
description: 'shows no groups if no service groups exist',
services: [{ groups: ['no_exist']}],
expected: [],
},{
description: 'shows all groups if service is null',
services: null,
expected: ['__world__', 'abc123'],
},{
description: 'shows all groups if service groups does not exist',
services: [{}],
expected: ['__world__', 'abc123'],
}].forEach(({ description, services, expected }) => {
it(description, () => {
fakeSettings.services = services;
const svc = service();
// Create groups response from server.
const groups = [{ name: 'Public', id: '__world__' }, { name: 'ABC', id: 'abc123'}];
fakeApi.groups.list.returns(Promise.resolve({
token: '1234',
data: groups,
}));
return svc.load().then(groups => {
let displayedGroups = groups.map(g => g.id);
assert.deepEqual(displayedGroups, expected);
});
});
});
}); });
describe('#get', function() { describe('#get', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment