continue go stuff
This commit is contained in:
parent
2ebcf0a8c4
commit
39860c84e6
102
src/actions.tsx
102
src/actions.tsx
@ -2,12 +2,12 @@ import { ActionInfo } from "./common"
|
||||
|
||||
export const Permission = {
|
||||
Start: 1,
|
||||
Stop: 1 << 2,
|
||||
Browse: 1 << 3,
|
||||
Create: 1 << 4,
|
||||
Delete: 1 << 5,
|
||||
RunCommand: 1 << 6,
|
||||
Admin: 1 << 7,
|
||||
Stop: 1 << 1,
|
||||
Browse: 1 << 2,
|
||||
Create: 1 << 3,
|
||||
Delete: 1 << 4,
|
||||
RunCommand: 1 << 5,
|
||||
Admin: 1 << 6,
|
||||
}
|
||||
|
||||
const definitions = {
|
||||
@ -27,22 +27,6 @@ const definitions = {
|
||||
],
|
||||
title: "ChangeUserRequest"
|
||||
},
|
||||
CreateServer: {
|
||||
properties: {
|
||||
image_id: {
|
||||
type: "string",
|
||||
title: "Image Id",
|
||||
fetch_display_path: "display_name",
|
||||
fetch_key_path: "id_",
|
||||
fetch_url: "/images"
|
||||
}
|
||||
},
|
||||
type: "object",
|
||||
required: [
|
||||
"image_id"
|
||||
],
|
||||
title: "CreateServer"
|
||||
},
|
||||
CreateUserRequest: {
|
||||
properties: {
|
||||
username: {
|
||||
@ -284,19 +268,6 @@ const definitions = {
|
||||
],
|
||||
title: "PortProtocol"
|
||||
},
|
||||
RunCommandRequest: {
|
||||
properties: {
|
||||
command: {
|
||||
type: "string",
|
||||
title: "Command"
|
||||
}
|
||||
},
|
||||
type: "object",
|
||||
required: [
|
||||
"command"
|
||||
],
|
||||
title: "RunCommandRequest"
|
||||
},
|
||||
ServerInfo: {
|
||||
properties: {
|
||||
id_: {
|
||||
@ -503,7 +474,7 @@ const definitions = {
|
||||
],
|
||||
title: "ValidationError"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -550,11 +521,21 @@ export const SERVER_ACTIONS: ActionInfo[] = [
|
||||
{
|
||||
name: "Run Command",
|
||||
args: {
|
||||
"$ref": "#/definitions/RunCommandRequest",
|
||||
properties: {
|
||||
command: {
|
||||
type: "string",
|
||||
title: "Command"
|
||||
}
|
||||
},
|
||||
type: "object",
|
||||
required: [
|
||||
"command"
|
||||
],
|
||||
title: "Run Command",
|
||||
definitions: definitions,
|
||||
},
|
||||
requestType: "post",
|
||||
endpoint: "/servers/{server_id}/command",
|
||||
endpoint: "/servers/{server_id}/run_command",
|
||||
permissions: Permission.RunCommand,
|
||||
response_action: "Ignore"
|
||||
},
|
||||
@ -595,12 +576,41 @@ export const SERVER_ACTIONS: ActionInfo[] = [
|
||||
permissions: Permission.Admin,
|
||||
response_action: "Ignore"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
export const CREATE_SERVER_ACTION: ActionInfo = {
|
||||
name: "Create Server",
|
||||
args: {
|
||||
"$ref": "#/definitions/CreateServer",
|
||||
properties: {
|
||||
ImageId: {
|
||||
type: "string",
|
||||
title: "Image Id",
|
||||
fetch_display_path: "DisplayName",
|
||||
fetch_key_path: "Id",
|
||||
fetch_url: "/images"
|
||||
},
|
||||
Nickname: {
|
||||
type: "string",
|
||||
title: "Server Nickname"
|
||||
},
|
||||
DefaultCommand: {
|
||||
type: "string",
|
||||
title: "Default Command"
|
||||
},
|
||||
DefaultPorts: {
|
||||
items: {
|
||||
"$ref": "#/definitions/Port-Input"
|
||||
},
|
||||
type: "array",
|
||||
title: "Default Ports",
|
||||
}
|
||||
},
|
||||
type: "object",
|
||||
required: [
|
||||
"ImageId"
|
||||
],
|
||||
title: "Create Server",
|
||||
|
||||
definitions: definitions,
|
||||
},
|
||||
requestType: "post",
|
||||
@ -610,7 +620,7 @@ export const CREATE_SERVER_ACTION: ActionInfo = {
|
||||
}
|
||||
|
||||
export const INVITE_USER_ACTION: ActionInfo = {
|
||||
name: "Create Server",
|
||||
name: "Invite User",
|
||||
args: {
|
||||
"$ref": "#/definitions/InviteUserRequests",
|
||||
definitions: definitions,
|
||||
@ -620,3 +630,13 @@ export const INVITE_USER_ACTION: ActionInfo = {
|
||||
permissions: Permission.Admin,
|
||||
response_action: "Ignore"
|
||||
}
|
||||
export const USERS_ACTIONS: ActionInfo[] = [
|
||||
{
|
||||
name: "Delete User",
|
||||
args: {},
|
||||
requestType: "get",
|
||||
endpoint: "/users/{user_id}",
|
||||
permissions: Permission.Admin,
|
||||
response_action: "Ignore"
|
||||
}
|
||||
]
|
@ -81,14 +81,14 @@ export const api: AxiosInstance = axios.create({
|
||||
|
||||
export function ApiWrapper(p: { children: ReactNode}) {
|
||||
const {children} = p
|
||||
const token = localStorage.getItem('token')
|
||||
const token = Cookies.get('auth')
|
||||
if (token) {
|
||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||
|
||||
}
|
||||
|
||||
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
||||
if (!apiAuthenticated) {
|
||||
localStorage.removeItem('token')
|
||||
Cookies.remove('auth')
|
||||
}
|
||||
const path = useLocation()
|
||||
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>
|
||||
|
@ -2,7 +2,7 @@ import { TableRow, TableCell, Chip } from "@mui/material"
|
||||
import { useContext, Dispatch, useState, useEffect, Context, createContext } from "react"
|
||||
import { apiAuthenticatedContext, api, ActionInfo, ActionGroup, actionIdentifierContext, DataTable } from "./common"
|
||||
import { User } from './interfaces'
|
||||
import { INVITE_USER_ACTION, Permission } from "./actions";
|
||||
import { INVITE_USER_ACTION, Permission, USERS_ACTIONS } from "./actions";
|
||||
|
||||
const UserActionsContext: Context<ActionInfo[]> = createContext([] as ActionInfo[])
|
||||
function getPermissionStrings(permissions: number){
|
||||
@ -26,7 +26,7 @@ function getPermissionStrings(permissions: number){
|
||||
strings.push("Delete")
|
||||
}
|
||||
if (permissions & Permission.RunCommand){
|
||||
strings.push("RunCommand")
|
||||
strings.push("Run Command")
|
||||
}
|
||||
return strings
|
||||
}
|
||||
@ -48,6 +48,7 @@ function UserItem(p: { user: User }) {
|
||||
export function UsersPage({ }) {
|
||||
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
||||
const [users, setUsers]: [User[], Dispatch<User[]>] = useState([] as User[])
|
||||
console.log({apiAuthenticated: apiAuthenticated, users: users})
|
||||
|
||||
const action: ActionInfo|undefined = INVITE_USER_ACTION
|
||||
|
||||
@ -55,7 +56,9 @@ export function UsersPage({ }) {
|
||||
if (!apiAuthenticated) {
|
||||
return
|
||||
}
|
||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
||||
api.get('/users').then((response) => {
|
||||
setUsers(response.data)
|
||||
}).catch(
|
||||
(error) => {
|
||||
console.log('Failed to get servers: ' + error);
|
||||
if (error.response) {
|
||||
@ -70,7 +73,10 @@ export function UsersPage({ }) {
|
||||
)
|
||||
|
||||
const interval = setInterval(() => {
|
||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
||||
api.get('/users').then((response) => {
|
||||
setUsers(response.data)
|
||||
|
||||
}).catch(
|
||||
(error) => {
|
||||
console.log('Failed to get users: ' + error);
|
||||
if (error.response) {
|
||||
@ -96,7 +102,7 @@ export function UsersPage({ }) {
|
||||
}
|
||||
|
||||
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>
|
||||
<UserActionsContext.Provider value={[]}>
|
||||
<UserActionsContext.Provider value={USERS_ACTIONS}>
|
||||
{userComponents}
|
||||
</UserActionsContext.Provider>
|
||||
</DataTable>
|
||||
|
Loading…
x
Reference in New Issue
Block a user