forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubusers.ts
More file actions
81 lines (70 loc) · 1.88 KB
/
subusers.ts
File metadata and controls
81 lines (70 loc) · 1.88 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { action, Action } from 'easy-peasy';
export type SubuserPermission =
| 'websocket.connect'
| 'control.console'
| 'control.start'
| 'control.stop'
| 'control.restart'
| 'user.create'
| 'user.read'
| 'user.update'
| 'user.delete'
| 'file.create'
| 'file.read'
| 'file.update'
| 'file.delete'
| 'file.archive'
| 'file.sftp'
| 'allocation.read'
| 'allocation.update'
| 'startup.read'
| 'startup.update'
| 'database.create'
| 'database.read'
| 'database.update'
| 'database.delete'
| 'database.view_password'
| 'schedule.create'
| 'schedule.read'
| 'schedule.update'
| 'schedule.delete';
export interface Subuser {
uuid: string;
username: string;
email: string;
image: string;
twoFactorEnabled: boolean;
createdAt: Date;
permissions: SubuserPermission[];
can(permission: SubuserPermission): boolean;
}
export interface ServerSubuserStore {
data: Subuser[];
setSubusers: Action<ServerSubuserStore, Subuser[]>;
appendSubuser: Action<ServerSubuserStore, Subuser>;
removeSubuser: Action<ServerSubuserStore, string>;
}
const subusers: ServerSubuserStore = {
data: [],
setSubusers: action((state, payload) => {
state.data = payload;
}),
appendSubuser: action((state, payload) => {
let matched = false;
state.data = [
...state.data
.map((user) => {
if (user.uuid === payload.uuid) {
matched = true;
return payload;
}
return user;
})
.concat(matched ? [] : [payload]),
];
}),
removeSubuser: action((state, payload) => {
state.data = [...state.data.filter((user) => user.uuid !== payload)];
}),
};
export default subusers;