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
93b51390
Commit
93b51390
authored
Mar 13, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate permissions to TypeScript
parent
a6a89b6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
36 deletions
+33
-36
permissions.ts
src/sidebar/helpers/permissions.ts
+33
-36
No files found.
src/sidebar/helpers/permissions.
j
s
→
src/sidebar/helpers/permissions.
t
s
View file @
93b51390
...
...
@@ -6,16 +6,18 @@
*
* Principals are strings of the form `type:id` where `type` is `'acct'` (for a
* specific user) or `'group'` (for a group).
*
* @typedef Permissions
* @prop {string[]} read - List of principals that can read the annotation
* @prop {string[]} update - List of principals that can edit the annotation
* @prop {string[]} delete - List of principals that can delete the
* annotation
*/
/** @param {string|null} savedLevel */
function
defaultLevel
(
savedLevel
)
{
type
Permissions
=
{
/** List of principals that can read the annotation */
read
:
string
[];
/** List of principals that can edit the annotation */
update
:
string
[];
/** List of principals that can delete the annotation */
delete
:
string
[];
};
function
defaultLevel
(
savedLevel
:
string
|
null
):
string
{
switch
(
savedLevel
)
{
case
'private'
:
case
'shared'
:
...
...
@@ -30,10 +32,9 @@ function defaultLevel(savedLevel) {
*
* A private annotation is one which is readable only by its author.
*
* @param {string} userid - User ID of the author
* @return {Permissions}
* @param userid - User ID of the author
*/
export
function
privatePermissions
(
userid
)
{
export
function
privatePermissions
(
userid
:
string
):
Permissions
{
return
{
read
:
[
userid
],
update
:
[
userid
],
...
...
@@ -45,26 +46,29 @@ export function privatePermissions(userid) {
* Return the permissions for an annotation that is shared with the given
* group.
*
* @param {string} userid - User ID of the author
* @param {string} groupid - ID of the group the annotation is being
* shared with
* @return {Permissions}
* @param userid - User ID of the author
* @param groupid - ID of the group the annotation is being shared with
*/
export
function
sharedPermissions
(
userid
,
groupid
)
{
export
function
sharedPermissions
(
userid
:
string
,
groupid
:
string
):
Permissions
{
return
Object
.
assign
(
privatePermissions
(
userid
),
{
read
:
[
'group:'
+
groupid
],
});
}
/**
* Return the default permissions for an annotation in a given group.
*
* @param {string} userid - User ID of the author
* @param {string} groupid - ID of the group the annotation is being shared
* with
* @param {string|null} savedLevel
* @return {Permissions}
* @param userid - User ID of the author
* @param groupid - ID of the group the annotation is being shared with
*/
export
function
defaultPermissions
(
userid
,
groupid
,
savedLevel
)
{
export
function
defaultPermissions
(
userid
:
string
,
groupid
:
string
,
savedLevel
:
string
|
null
):
Permissions
{
if
(
defaultLevel
(
savedLevel
)
===
'private'
&&
userid
)
{
return
privatePermissions
(
userid
);
}
else
{
...
...
@@ -75,11 +79,8 @@ export function defaultPermissions(userid, groupid, savedLevel) {
/**
* Return true if an annotation with the given permissions is shared with any
* group.
*
* @param {Permissions} perms
* @return {boolean}
*/
export
function
isShared
(
perms
)
{
export
function
isShared
(
perms
:
Permissions
):
boolean
{
return
perms
.
read
.
some
(
principal
=>
{
return
principal
.
indexOf
(
'group:'
)
===
0
;
});
...
...
@@ -87,22 +88,18 @@ export function isShared(perms) {
/**
* Return true if an annotation with the given permissions is private.
*
* @param {Permissions} perms
* @return {boolean}
*/
export
function
isPrivate
(
perms
)
{
export
function
isPrivate
(
perms
:
Permissions
):
boolean
{
return
!
isShared
(
perms
);
}
/**
* Return true if a user can perform the given `action` on an annotation.
*
* @param {Permissions} perms
* @param {'update'|'delete'} action
* @param {string|null} userid
* @return {boolean}
*/
export
function
permits
(
perms
,
action
,
userid
)
{
export
function
permits
(
perms
:
Permissions
,
action
:
'update'
|
'delete'
,
userid
:
string
|
null
):
boolean
{
return
perms
[
action
].
indexOf
(
userid
||
''
)
!==
-
1
;
}
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