misc_pterodactyl-panel/resources/scripts/state/server/subusers.ts

82 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

import { action, Action } from 'easy-peasy';
2019-11-03 20:20:11 +00:00
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';
2019-11-03 20:20:11 +00:00
export interface Subuser {
uuid: string;
username: string;
email: string;
image: string;
twoFactorEnabled: boolean;
createdAt: Date;
permissions: SubuserPermission[];
can(permission: SubuserPermission): boolean;
2019-11-03 20:20:11 +00:00
}
export interface ServerSubuserStore {
data: Subuser[];
setSubusers: Action<ServerSubuserStore, Subuser[]>;
appendSubuser: Action<ServerSubuserStore, Subuser>;
removeSubuser: Action<ServerSubuserStore, string>;
2019-11-03 20:20:11 +00:00
}
const subusers: ServerSubuserStore = {
data: [],
setSubusers: action((state, payload) => {
state.data = payload;
}),
appendSubuser: action((state, payload) => {
2020-03-27 22:40:24 +00:00
let matched = false;
state.data = [
...state.data
.map((user) => {
2020-03-27 22:40:24 +00:00
if (user.uuid === payload.uuid) {
matched = true;
return payload;
}
return user;
})
.concat(matched ? [] : [payload]),
2020-03-27 22:40:24 +00:00
];
2019-11-03 20:20:11 +00:00
}),
removeSubuser: action((state, payload) => {
state.data = [...state.data.filter((user) => user.uuid !== payload)];
2019-11-03 20:20:11 +00:00
}),
};
export default subusers;