2019-11-03 20:20:11 +00:00
|
|
|
import { action, Action, thunk, Thunk } from 'easy-peasy';
|
|
|
|
import getServerSubusers from '@/api/server/users/getServerSubusers';
|
|
|
|
|
2019-11-04 01:37:06 +00:00
|
|
|
export type SubuserPermission =
|
|
|
|
'websocket.*' |
|
|
|
|
'control.console' | 'control.start' | 'control.stop' | 'control.restart' | 'control.kill' |
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ServerSubuserStore {
|
|
|
|
data: Subuser[];
|
|
|
|
setSubusers: Action<ServerSubuserStore, Subuser[]>;
|
|
|
|
appendSubuser: Action<ServerSubuserStore, Subuser>;
|
|
|
|
getSubusers: Thunk<ServerSubuserStore, string, any, {}, Promise<void>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const subusers: ServerSubuserStore = {
|
|
|
|
data: [],
|
|
|
|
|
|
|
|
setSubusers: action((state, payload) => {
|
|
|
|
state.data = payload;
|
|
|
|
}),
|
|
|
|
|
|
|
|
appendSubuser: action((state, payload) => {
|
2019-11-04 01:37:06 +00:00
|
|
|
state.data = [ ...state.data, payload ];
|
2019-11-03 20:20:11 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
getSubusers: thunk(async (actions, payload) => {
|
|
|
|
const subusers = await getServerSubusers(payload);
|
|
|
|
|
|
|
|
actions.setSubusers(subusers);
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default subusers;
|