Unverified Commit af0b206b authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #676 from hypothesis/pass-authority-when-fetching-groups

Pass "authority" query param when fetching groups list
parents 218177ad c5436e3d
...@@ -15,9 +15,11 @@ var STORAGE_KEY = 'hypothesis.groups.focus'; ...@@ -15,9 +15,11 @@ var STORAGE_KEY = 'hypothesis.groups.focus';
var events = require('./events'); var events = require('./events');
var { awaitStateChange } = require('./util/state-util'); var { awaitStateChange } = require('./util/state-util');
var serviceConfig = require('./service-config');
// @ngInject // @ngInject
function groups(annotationUI, isSidebar, localStorage, serviceUrl, session, $rootScope, store) { function groups(annotationUI, isSidebar, localStorage, serviceUrl, session,
settings, $rootScope, store) {
// The currently focused group. This is the group that's shown as selected in // The currently focused group. This is the group that's shown as selected in
// the groups dropdown, the annotations displayed are filtered to only ones // the groups dropdown, the annotations displayed are filtered to only ones
// that belong to this group, and any new annotations that the user creates // that belong to this group, and any new annotations that the user creates
...@@ -26,6 +28,9 @@ function groups(annotationUI, isSidebar, localStorage, serviceUrl, session, $roo ...@@ -26,6 +28,9 @@ function groups(annotationUI, isSidebar, localStorage, serviceUrl, session, $roo
var groups = []; var groups = [];
var documentUri; var documentUri;
var svc = serviceConfig(settings);
var authority = svc ? svc.authority : null;
function getDocumentUriForGroupSearch() { function getDocumentUriForGroupSearch() {
function mainUri() { function mainUri() {
var uris = annotationUI.searchUris(); var uris = annotationUI.searchUris();
...@@ -54,6 +59,9 @@ function groups(annotationUI, isSidebar, localStorage, serviceUrl, session, $roo ...@@ -54,6 +59,9 @@ function groups(annotationUI, isSidebar, localStorage, serviceUrl, session, $roo
} }
return uri.then(uri => { return uri.then(uri => {
var params = {}; var params = {};
if (authority) {
params.authority = authority;
}
if (uri) { if (uri) {
params.document_uri = uri; params.document_uri = uri;
} }
......
...@@ -16,6 +16,7 @@ describe('groups', function() { ...@@ -16,6 +16,7 @@ describe('groups', function() {
var fakeAnnotationUI; var fakeAnnotationUI;
var fakeIsSidebar; var fakeIsSidebar;
var fakeSession; var fakeSession;
var fakeSettings;
var fakeStore; var fakeStore;
var fakeLocalStorage; var fakeLocalStorage;
var fakeRootScope; var fakeRootScope;
...@@ -68,6 +69,7 @@ describe('groups', function() { ...@@ -68,6 +69,7 @@ describe('groups', function() {
}, },
}; };
fakeServiceUrl = sandbox.stub(); fakeServiceUrl = sandbox.stub();
fakeSettings = {};
}); });
afterEach(function () { afterEach(function () {
...@@ -76,7 +78,7 @@ describe('groups', function() { ...@@ -76,7 +78,7 @@ describe('groups', function() {
function service() { function service() {
return groups(fakeAnnotationUI, fakeIsSidebar, fakeLocalStorage, fakeServiceUrl, fakeSession, return groups(fakeAnnotationUI, fakeIsSidebar, fakeLocalStorage, fakeServiceUrl, fakeSession,
fakeRootScope, fakeStore); fakeSettings, fakeRootScope, fakeStore);
} }
describe('#all()', function() { describe('#all()', function() {
...@@ -155,6 +157,14 @@ describe('groups', function() { ...@@ -155,6 +157,14 @@ describe('groups', function() {
}); });
}); });
}); });
it('passes authority argument when using a third-party authority', () => {
fakeSettings.services = [{ authority: 'publisher.org' }];
var svc = service();
return svc.load().then(() => {
assert.calledWith(fakeStore.groups.list, sinon.match({ authority: 'publisher.org' }));
});
});
}); });
describe('#get() method', function() { describe('#get() method', 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