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
d3ddbe75
Commit
d3ddbe75
authored
Sep 04, 2017
by
Robert Knight
Committed by
GitHub
Sep 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #528 from hypothesis/use-leave-group-api
Use the `group.member.delete` API route to leave a group
parents
ca516d3a
a3b0c454
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
21 deletions
+50
-21
groups.js
src/sidebar/groups.js
+8
-10
store.js
src/sidebar/store.js
+5
-0
groups-test.js
src/sidebar/test/groups-test.js
+15
-11
store-test.js
src/sidebar/test/store-test.js
+22
-0
No files found.
src/sidebar/groups.js
View file @
d3ddbe75
...
...
@@ -16,7 +16,7 @@ var STORAGE_KEY = 'hypothesis.groups.focus';
var
events
=
require
(
'./events'
);
// @ngInject
function
groups
(
localStorage
,
serviceUrl
,
session
,
$rootScope
,
$http
)
{
function
groups
(
localStorage
,
serviceUrl
,
session
,
$rootScope
,
store
)
{
// 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
// that belong to this group, and any new annotations that the user creates
...
...
@@ -38,20 +38,18 @@ function groups(localStorage, serviceUrl, session, $rootScope, $http) {
return
null
;
}
/** Leave the group with the given ID.
/**
* Leave the group with the given ID.
* Returns a promise which resolves when the action completes.
*/
function
leave
(
id
)
{
var
response
=
$http
({
method
:
'POST'
,
url
:
serviceUrl
(
'groups.leave'
,
{
id
:
id
}),
});
// the groups list will be updated in response to a session state
// The groups list will be updated in response to a session state
// change notification from the server. We could improve the UX here
// by optimistically updating the session state
return
response
;
return
store
.
group
.
member
.
delete
({
pubid
:
id
,
user
:
'me'
,
});
}
...
...
src/sidebar/store.js
View file @
d3ddbe75
...
...
@@ -173,6 +173,11 @@ function store($http, $q, apiRoutes, auth) {
hide
:
apiCall
(
'annotation.hide'
),
unhide
:
apiCall
(
'annotation.unhide'
),
},
group
:
{
member
:
{
delete
:
apiCall
(
'group.member.delete'
),
},
},
profile
:
{
read
:
apiCall
(
'profile.read'
),
update
:
apiCall
(
'profile.update'
),
...
...
src/sidebar/test/groups-test.js
View file @
d3ddbe75
...
...
@@ -18,9 +18,9 @@ var sessionWithThreeGroups = function() {
describe
(
'groups'
,
function
()
{
var
fakeSession
;
var
fakeStore
;
var
fakeLocalStorage
;
var
fakeRootScope
;
var
fakeHttp
;
var
fakeServiceUrl
;
var
sandbox
;
...
...
@@ -43,7 +43,13 @@ describe('groups', function() {
}
},
};
fakeHttp
=
sandbox
.
stub
();
fakeStore
=
{
group
:
{
member
:
{
delete
:
sandbox
.
stub
().
returns
(
Promise
.
resolve
()),
},
},
};
fakeServiceUrl
=
sandbox
.
stub
();
});
...
...
@@ -53,7 +59,7 @@ describe('groups', function() {
function
service
()
{
return
groups
(
fakeLocalStorage
,
fakeServiceUrl
,
fakeSession
,
fakeRootScope
,
fake
Http
);
fakeRootScope
,
fake
Store
);
}
describe
(
'.all()'
,
function
()
{
...
...
@@ -171,15 +177,13 @@ describe('groups', function() {
});
describe
(
'.leave()'
,
function
()
{
it
(
'should call the
/groups/<id>/leave service
'
,
function
()
{
it
(
'should call the
group leave API
'
,
function
()
{
var
s
=
service
();
fakeServiceUrl
.
withArgs
(
'groups.leave'
,
{
id
:
'id2'
})
.
returns
(
'https://hyp.is/groups/leave'
);
s
.
leave
(
'id2'
);
assert
.
calledWithMatch
(
fakeHttp
,
{
url
:
'https://hyp.is/groups/leave'
,
method
:
'POST'
,
return
s
.
leave
(
'id2'
).
then
(()
=>
{
assert
.
calledWithMatch
(
fakeStore
.
group
.
member
.
delete
,
{
pubid
:
'id2'
,
user
:
'me'
,
});
});
});
});
...
...
src/sidebar/test/store-test.js
View file @
d3ddbe75
...
...
@@ -36,6 +36,14 @@ var routes = {
url
:
'http://example.com/api/annotations/:id/hide'
,
},
},
group
:
{
member
:
{
delete
:
{
method
:
'DELETE'
,
url
:
'http://example.com/api/groups/:pubid/members/:user'
,
},
},
},
search
:
{
method
:
'GET'
,
url
:
'http://example.com/api/search'
,
...
...
@@ -178,6 +186,20 @@ describe('sidebar.store', function () {
$httpBackend
.
flush
();
});
describe
(
'#group.member.delete'
,
()
=>
{
it
(
'removes current user from a group'
,
(
done
)
=>
{
store
.
group
.
member
.
delete
({
pubid
:
'an-id'
,
user
:
'me'
}).
then
(
function
()
{
done
();
});
$httpBackend
.
expectDELETE
(
'http://example.com/api/groups/an-id/members/me'
)
.
respond
(()
=>
{
return
[
204
,
{},
{}];
});
$httpBackend
.
flush
();
});
});
it
(
'removes internal properties before sending data to the server'
,
function
(
done
)
{
var
annotation
=
{
$highlight
:
true
,
...
...
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