Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 43 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | function SharingACL (acl_permission) { |
||
2 | this.permission = acl_permission; |
||
3 | } |
||
4 | |||
5 | SharingACL.prototype.permissions = { |
||
6 | READ: 0x01, |
||
7 | WRITE: 0x02, |
||
8 | FILES: 0x04, |
||
9 | HISTORY: 0x08, |
||
10 | OWNER: 0x80, |
||
11 | }; |
||
12 | /** |
||
13 | * Checks if a user has the given permission/s |
||
14 | * @param permission |
||
15 | * @returns {boolean} |
||
16 | */ |
||
17 | SharingACL.prototype.hasPermission = function (permission) { |
||
18 | return permission === (this.permission & permission); |
||
19 | }; |
||
20 | |||
21 | /** |
||
22 | * Adds a permission to a user, leaving any other permissions intact |
||
23 | * @param permission |
||
24 | */ |
||
25 | SharingACL.prototype.addPermission = function (permission) { |
||
26 | this.permission = this.permission | permission; |
||
27 | }; |
||
28 | |||
29 | /** |
||
30 | * Removes a given permission from the item, leaving any other intact |
||
31 | * @param permission |
||
32 | */ |
||
33 | SharingACL.prototype.removePermission = function (permission) { |
||
34 | this.permission = this.permission & ~permission; |
||
35 | }; |
||
36 | |||
37 | SharingACL.prototype.togglePermission = function (permission) { |
||
38 | this.permission ^= permission; |
||
39 | }; |
||
40 | |||
41 | SharingACL.prototype.getAccessLevel = function () { |
||
42 | return this.permission; |
||
43 | }; |