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
c300a7a8
Commit
c300a7a8
authored
Nov 18, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not allow leaving __world__ group
parent
e80f6941
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
7 deletions
+47
-7
groups.ts
src/sidebar/helpers/groups.ts
+8
-2
groups-test.js
src/sidebar/helpers/test/groups-test.js
+34
-0
groups.ts
src/sidebar/services/groups.ts
+5
-5
No files found.
src/sidebar/helpers/groups.ts
View file @
c300a7a8
...
...
@@ -18,6 +18,8 @@ function allowLeavingGroups(settings: SidebarSettings): boolean {
return
!!
config
.
allowLeavingGroups
;
}
export
const
PUBLIC_GROUP_ID
=
'__world__'
;
/**
* Combine groups from multiple api calls together to form a unique list of groups.
* Add an isMember property to each group indicating whether the logged in user is a member.
...
...
@@ -34,7 +36,7 @@ export function combineGroups(
uri
:
string
|
null
,
settings
:
SidebarSettings
,
)
{
const
worldGroup
=
featuredGroups
.
find
(
g
=>
g
.
id
===
'__world__'
);
const
worldGroup
=
featuredGroups
.
find
(
g
=>
g
.
id
===
PUBLIC_GROUP_ID
);
if
(
worldGroup
)
{
userGroups
.
unshift
(
worldGroup
);
}
...
...
@@ -50,7 +52,11 @@ export function combineGroups(
// Set flag indicating whether user can leave group.
for
(
const
group
of
groups
)
{
group
.
canLeave
=
allowLeavingGroups
(
settings
)
&&
group
.
isMember
;
group
.
canLeave
=
allowLeavingGroups
(
settings
)
&&
group
.
isMember
&&
// People should not be able to leave the "Public" group.
group
.
id
!==
PUBLIC_GROUP_ID
;
}
// Add isScopedToUri property indicating whether a group is within scope
...
...
src/sidebar/helpers/test/groups-test.js
View file @
c300a7a8
...
...
@@ -97,6 +97,40 @@ describe('sidebar/helpers/groups', () => {
},
);
it
(
'sets `canLeave` to false for the `__world__` group'
,
()
=>
{
const
userGroups
=
[
{
id
:
'__world__'
,
name
:
'Public'
,
type
:
'open'
},
{
id
:
'groupa'
,
name
:
'GroupA'
,
type
:
'private'
},
{
id
:
'groupc'
,
name
:
'GroupC'
,
type
:
'open'
},
{
id
:
'groupd'
,
name
:
'GroupD'
,
type
:
'restricted'
},
];
const
groups
=
combineGroups
(
userGroups
,
[],
'https://foo.com/bar'
);
const
expected
=
[
{
id
:
'__world__'
,
canLeave
:
false
,
},
{
id
:
'groupa'
,
canLeave
:
true
,
},
{
id
:
'groupc'
,
canLeave
:
true
,
},
{
id
:
'groupd'
,
canLeave
:
true
,
},
];
for
(
const
{
id
,
canLeave
}
of
expected
)
{
const
group
=
groups
.
find
(
g
=>
g
.
id
===
id
);
assert
.
strictEqual
(
group
.
canLeave
,
canLeave
);
}
});
it
(
'combines groups from both lists uniquely'
,
()
=>
{
const
userGroups
=
[
{
id
:
'groupa'
,
name
:
'GroupA'
},
...
...
src/sidebar/services/groups.ts
View file @
c300a7a8
...
...
@@ -7,7 +7,7 @@ import type { SidebarSettings } from '../../types/config';
import
type
{
Service
}
from
'../../types/config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
import
{
isReply
}
from
'../helpers/annotation-metadata'
;
import
{
combineGroups
}
from
'../helpers/groups'
;
import
{
combineGroups
,
PUBLIC_GROUP_ID
}
from
'../helpers/groups'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
{
awaitStateChange
}
from
'../store/util'
;
import
{
watch
}
from
'../util/watch'
;
...
...
@@ -121,7 +121,7 @@ export class GroupsService {
// If the main document URL has no groups associated with it, always show
// the "Public" group.
const
pageHasAssociatedGroups
=
groups
.
some
(
g
=>
g
.
id
!==
'__world__'
&&
g
.
isScopedToUri
,
g
=>
g
.
id
!==
PUBLIC_GROUP_ID
&&
g
.
isScopedToUri
,
);
if
(
!
pageHasAssociatedGroups
)
{
return
groups
;
...
...
@@ -130,14 +130,14 @@ export class GroupsService {
// If directLinkedGroup or directLinkedAnnotationGroupId is the "Public" group,
// always return groups.
if
(
directLinkedGroupId
===
'__world__'
||
directLinkedAnnotationGroupId
===
'__world__'
directLinkedGroupId
===
PUBLIC_GROUP_ID
||
directLinkedAnnotationGroupId
===
PUBLIC_GROUP_ID
)
{
return
groups
;
}
// Return non-world groups.
return
groups
.
filter
(
g
=>
g
.
id
!==
'__world__'
);
return
groups
.
filter
(
g
=>
g
.
id
!==
PUBLIC_GROUP_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