forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermission.ts
More file actions
26 lines (24 loc) · 767 Bytes
/
permission.ts
File metadata and controls
26 lines (24 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { PermissionType } from '../types';
const permissions: PermissionType[] = [
'write_code',
'write_project',
'comment',
'read',
'none',
];
/**
* Whether the given permission is permitted compared to the required permission.
* We use a simple model for this, where if you have a top permission it will be considered
* that you have all other permissions. This same list is saved on the server, and this needs
* to keep in sync with that.
* @param permission Permission to test
* @param requiredPermission Required permission to pass the test
*/
export function hasPermission(
permission: PermissionType,
requiredPermission: PermissionType
) {
return (
permissions.indexOf(permission) <= permissions.indexOf(requiredPermission)
);
}