Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
2a95f092
Unverified
Commit
2a95f092
authored
Oct 31, 2018
by
Robert Knight
Committed by
GitHub
Oct 31, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #799 from hypothesis/add-service-groups-config-option
Add service.groups setting to filter groups
parents
6783b96d
ac3e3e4d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
0 deletions
+56
-0
config.rst
docs/publishers/config.rst
+9
-0
groups.js
src/sidebar/services/groups.js
+7
-0
groups-test.js
src/sidebar/services/test/groups-test.js
+40
-0
No files found.
docs/publishers/config.rst
View file @
2a95f092
...
@@ -186,6 +186,15 @@ loads.
...
@@ -186,6 +186,15 @@ loads.
group. The image should be suitable for display at 16x16px and the
group. The image should be suitable for display at 16x16px and the
recommended format is SVG.
recommended format is SVG.
.. option:: groups
``String[]|null``. An array of group IDs. If provided, the list of groups
fetched from the API will be filtered against this list so that the user
can only select from these groups.
This can be useful in contexts where it is important that annotations
are made in a particular group.
.. option:: onLoginRequest
.. option:: onLoginRequest
``function``. A JavaScript function that the Hypothesis client will
``function``. A JavaScript function that the Hypothesis client will
...
...
src/sidebar/services/groups.js
View file @
2a95f092
...
@@ -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
);
...
...
src/sidebar/services/test/groups-test.js
View file @
2a95f092
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment