Add basic subuser listing for servers
This commit is contained in:
parent
de464d35a2
commit
543884876f
14 changed files with 310 additions and 4 deletions
|
@ -3,6 +3,7 @@ import { action, Action, createContextStore, thunk, Thunk } from 'easy-peasy';
|
|||
import socket, { SocketStore } from './socket';
|
||||
import { ServerDatabase } from '@/api/server/getServerDatabases';
|
||||
import files, { ServerFileStore } from '@/state/server/files';
|
||||
import subusers, { ServerSubuserStore } from '@/state/server/subusers';
|
||||
|
||||
export type ServerStatus = 'offline' | 'starting' | 'stopping' | 'running';
|
||||
|
||||
|
@ -56,6 +57,7 @@ const databases: ServerDatabaseStore = {
|
|||
|
||||
export interface ServerStore {
|
||||
server: ServerDataStore;
|
||||
subusers: ServerSubuserStore;
|
||||
databases: ServerDatabaseStore;
|
||||
files: ServerFileStore;
|
||||
socket: SocketStore;
|
||||
|
@ -69,9 +71,14 @@ export const ServerContext = createContextStore<ServerStore>({
|
|||
status,
|
||||
databases,
|
||||
files,
|
||||
subusers,
|
||||
clearServerState: action(state => {
|
||||
state.server.data = undefined;
|
||||
state.databases.items = [];
|
||||
state.subusers.data = [];
|
||||
|
||||
state.files.directory = '/';
|
||||
state.files.contents = [];
|
||||
|
||||
if (state.socket.instance) {
|
||||
state.socket.instance.removeAllListeners();
|
||||
|
|
43
resources/scripts/state/server/subusers.ts
Normal file
43
resources/scripts/state/server/subusers.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { action, Action, thunk, Thunk } from 'easy-peasy';
|
||||
import getServerSubusers from '@/api/server/users/getServerSubusers';
|
||||
|
||||
export type SubuserPermission = string;
|
||||
|
||||
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) => {
|
||||
state.data = [...state.data, payload];
|
||||
}),
|
||||
|
||||
getSubusers: thunk(async (actions, payload) => {
|
||||
const subusers = await getServerSubusers(payload);
|
||||
|
||||
actions.setSubusers(subusers);
|
||||
}),
|
||||
};
|
||||
|
||||
export default subusers;
|
Reference in a new issue