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
de7043b4
Unverified
Commit
de7043b4
authored
Feb 12, 2019
by
Robert Knight
Committed by
GitHub
Feb 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #943 from hypothesis/fix-isloggedin-bug
Use token instead of store.profile to calc isLoggedIn
parents
2ea51788
f55b5ae9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
18 deletions
+46
-18
groups.js
src/sidebar/services/groups.js
+14
-7
groups-test.js
src/sidebar/services/test/groups-test.js
+32
-11
No files found.
src/sidebar/services/groups.js
View file @
de7043b4
...
...
@@ -27,6 +27,7 @@ function groups(
serviceUrl
,
session
,
settings
,
auth
,
features
)
{
const
svc
=
serviceConfig
(
settings
);
...
...
@@ -158,17 +159,23 @@ function groups(
};
const
profileGroupsApi
=
api
.
profile
.
groups
.
read
(
profileParams
);
const
listGroupsApi
=
api
.
groups
.
list
(
params
);
return
Promise
.
all
([
profileGroupsApi
,
listGroupsApi
]).
then
(
([
myGroups
,
featuredGroups
])
=>
combineGroups
(
myGroups
,
featuredGroups
)
);
return
Promise
.
all
([
profileGroupsApi
,
listGroupsApi
,
auth
.
tokenGetter
(),
]).
then
(([
myGroups
,
featuredGroups
,
token
])
=>
[
combineGroups
(
myGroups
,
featuredGroups
),
token
,
]);
}
else
{
// Fetch groups from the API.
return
api
.
groups
.
list
(
params
);
return
api
.
groups
.
list
(
params
,
null
,
{
includeMetadata
:
true
})
.
then
(({
data
,
token
})
=>
[
data
,
token
]);
}
})
.
then
(
groups
=>
{
const
isLoggedIn
=
store
.
profile
().
userid
!==
null
;
.
then
(
([
groups
,
token
])
=>
{
const
isLoggedIn
=
token
!==
null
;
const
directLinkedAnnotation
=
settings
.
annotations
;
return
filterGroups
(
groups
,
isLoggedIn
,
directLinkedAnnotation
);
})
...
...
src/sidebar/services/test/groups-test.js
View file @
de7043b4
...
...
@@ -36,6 +36,7 @@ const dummyGroups = [
];
describe
(
'groups'
,
function
()
{
let
fakeAuth
;
let
fakeFeatures
;
let
fakeStore
;
let
fakeIsSidebar
;
...
...
@@ -48,6 +49,9 @@ describe('groups', function() {
let
sandbox
;
beforeEach
(
function
()
{
fakeAuth
=
{
tokenGetter
:
sinon
.
stub
().
returns
(
'1234'
),
};
fakeFeatures
=
{
flagEnabled
:
sinon
.
stub
().
returns
(
false
),
};
...
...
@@ -58,7 +62,6 @@ describe('groups', function() {
searchUris
:
[
'http://example.org'
],
focusedGroup
:
null
,
groups
:
[],
profile
:
sinon
.
stub
().
returns
({
userid
:
'userid'
}),
},
{
focusGroup
:
sinon
.
stub
(),
...
...
@@ -79,9 +82,6 @@ describe('groups', function() {
},
}
);
fakeStore
.
profile
=
()
=>
{
return
{
userid
:
'userid'
};
};
fakeSession
=
sessionWithThreeGroups
();
fakeIsSidebar
=
true
;
fakeLocalStorage
=
{
...
...
@@ -114,7 +114,12 @@ describe('groups', function() {
},
},
groups
:
{
list
:
sandbox
.
stub
().
returns
(
Promise
.
resolve
(
dummyGroups
)),
list
:
sandbox
.
stub
().
returns
(
Promise
.
resolve
({
data
:
dummyGroups
,
token
:
'1234'
,
})
),
},
profile
:
{
groups
:
{
...
...
@@ -140,6 +145,7 @@ describe('groups', function() {
fakeServiceUrl
,
fakeSession
,
fakeSettings
,
fakeAuth
,
fakeFeatures
);
}
...
...
@@ -189,6 +195,9 @@ describe('groups', function() {
it
(
'sends `expand` parameter when community-groups feature flag is enabled'
,
function
()
{
const
svc
=
service
();
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
([{
id
:
'groupa'
,
name
:
'GroupA'
}])
);
fakeFeatures
.
flagEnabled
.
withArgs
(
'community_groups'
).
returns
(
true
);
return
svc
.
load
().
then
(()
=>
{
...
...
@@ -268,7 +277,12 @@ describe('groups', function() {
it
(
'injects a defalt organization if group is missing an organization'
,
function
()
{
const
svc
=
service
();
const
groups
=
[{
id
:
'39r39f'
,
name
:
'Ding Dong!'
}];
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
groups
));
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
({
token
:
'1234'
,
data
:
groups
,
})
);
return
svc
.
load
().
then
(
groups
=>
{
assert
.
isObject
(
groups
[
0
].
organization
);
assert
.
hasAllKeys
(
groups
[
0
].
organization
,
[
'id'
,
'logo'
]);
...
...
@@ -303,10 +317,12 @@ describe('groups', function() {
groups
.
push
({
name
:
'BioPub'
,
id
:
'biopub'
});
}
fakeStore
.
profile
=
()
=>
{
return
{
userid
:
loggedIn
?
'userid'
:
null
};
};
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
groups
));
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
({
token
:
loggedIn
?
'1234'
:
null
,
data
:
groups
,
})
);
return
svc
.
load
().
then
(
groups
=>
{
const
publicGroupShown
=
groups
.
some
(
g
=>
g
.
id
===
'__world__'
);
...
...
@@ -359,7 +375,12 @@ describe('groups', function() {
{
name
:
'DEF'
,
id
:
'def456'
,
groupid
:
null
},
];
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
groups
));
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
({
token
:
'1234'
,
data
:
groups
,
})
);
return
svc
.
load
().
then
(
groups
=>
{
let
displayedGroups
=
groups
.
map
(
g
=>
g
.
id
);
...
...
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