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 = {
|
export const Permission = {
|
||||||
Start: 1,
|
Start: 1,
|
||||||
Stop: 1 << 2,
|
Stop: 1 << 1,
|
||||||
Browse: 1 << 3,
|
Browse: 1 << 2,
|
||||||
Create: 1 << 4,
|
Create: 1 << 3,
|
||||||
Delete: 1 << 5,
|
Delete: 1 << 4,
|
||||||
RunCommand: 1 << 6,
|
RunCommand: 1 << 5,
|
||||||
Admin: 1 << 7,
|
Admin: 1 << 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
const definitions = {
|
const definitions = {
|
||||||
@ -27,22 +27,6 @@ const definitions = {
|
|||||||
],
|
],
|
||||||
title: "ChangeUserRequest"
|
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: {
|
CreateUserRequest: {
|
||||||
properties: {
|
properties: {
|
||||||
username: {
|
username: {
|
||||||
@ -284,19 +268,6 @@ const definitions = {
|
|||||||
],
|
],
|
||||||
title: "PortProtocol"
|
title: "PortProtocol"
|
||||||
},
|
},
|
||||||
RunCommandRequest: {
|
|
||||||
properties: {
|
|
||||||
command: {
|
|
||||||
type: "string",
|
|
||||||
title: "Command"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
type: "object",
|
|
||||||
required: [
|
|
||||||
"command"
|
|
||||||
],
|
|
||||||
title: "RunCommandRequest"
|
|
||||||
},
|
|
||||||
ServerInfo: {
|
ServerInfo: {
|
||||||
properties: {
|
properties: {
|
||||||
id_: {
|
id_: {
|
||||||
@ -503,7 +474,7 @@ const definitions = {
|
|||||||
],
|
],
|
||||||
title: "ValidationError"
|
title: "ValidationError"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -550,11 +521,21 @@ export const SERVER_ACTIONS: ActionInfo[] = [
|
|||||||
{
|
{
|
||||||
name: "Run Command",
|
name: "Run Command",
|
||||||
args: {
|
args: {
|
||||||
"$ref": "#/definitions/RunCommandRequest",
|
properties: {
|
||||||
|
command: {
|
||||||
|
type: "string",
|
||||||
|
title: "Command"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type: "object",
|
||||||
|
required: [
|
||||||
|
"command"
|
||||||
|
],
|
||||||
|
title: "Run Command",
|
||||||
definitions: definitions,
|
definitions: definitions,
|
||||||
},
|
},
|
||||||
requestType: "post",
|
requestType: "post",
|
||||||
endpoint: "/servers/{server_id}/command",
|
endpoint: "/servers/{server_id}/run_command",
|
||||||
permissions: Permission.RunCommand,
|
permissions: Permission.RunCommand,
|
||||||
response_action: "Ignore"
|
response_action: "Ignore"
|
||||||
},
|
},
|
||||||
@ -595,12 +576,41 @@ export const SERVER_ACTIONS: ActionInfo[] = [
|
|||||||
permissions: Permission.Admin,
|
permissions: Permission.Admin,
|
||||||
response_action: "Ignore"
|
response_action: "Ignore"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const CREATE_SERVER_ACTION: ActionInfo = {
|
export const CREATE_SERVER_ACTION: ActionInfo = {
|
||||||
name: "Create Server",
|
name: "Create Server",
|
||||||
args: {
|
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,
|
definitions: definitions,
|
||||||
},
|
},
|
||||||
requestType: "post",
|
requestType: "post",
|
||||||
@ -610,7 +620,7 @@ export const CREATE_SERVER_ACTION: ActionInfo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const INVITE_USER_ACTION: ActionInfo = {
|
export const INVITE_USER_ACTION: ActionInfo = {
|
||||||
name: "Create Server",
|
name: "Invite User",
|
||||||
args: {
|
args: {
|
||||||
"$ref": "#/definitions/InviteUserRequests",
|
"$ref": "#/definitions/InviteUserRequests",
|
||||||
definitions: definitions,
|
definitions: definitions,
|
||||||
@ -620,3 +630,13 @@ export const INVITE_USER_ACTION: ActionInfo = {
|
|||||||
permissions: Permission.Admin,
|
permissions: Permission.Admin,
|
||||||
response_action: "Ignore"
|
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}) {
|
export function ApiWrapper(p: { children: ReactNode}) {
|
||||||
const {children} = p
|
const {children} = p
|
||||||
const token = localStorage.getItem('token')
|
const token = Cookies.get('auth')
|
||||||
if (token) {
|
if (token) {
|
||||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
||||||
if (!apiAuthenticated) {
|
if (!apiAuthenticated) {
|
||||||
localStorage.removeItem('token')
|
Cookies.remove('auth')
|
||||||
}
|
}
|
||||||
const path = useLocation()
|
const path = useLocation()
|
||||||
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>
|
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 { useContext, Dispatch, useState, useEffect, Context, createContext } from "react"
|
||||||
import { apiAuthenticatedContext, api, ActionInfo, ActionGroup, actionIdentifierContext, DataTable } from "./common"
|
import { apiAuthenticatedContext, api, ActionInfo, ActionGroup, actionIdentifierContext, DataTable } from "./common"
|
||||||
import { User } from './interfaces'
|
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[])
|
const UserActionsContext: Context<ActionInfo[]> = createContext([] as ActionInfo[])
|
||||||
function getPermissionStrings(permissions: number){
|
function getPermissionStrings(permissions: number){
|
||||||
@ -26,7 +26,7 @@ function getPermissionStrings(permissions: number){
|
|||||||
strings.push("Delete")
|
strings.push("Delete")
|
||||||
}
|
}
|
||||||
if (permissions & Permission.RunCommand){
|
if (permissions & Permission.RunCommand){
|
||||||
strings.push("RunCommand")
|
strings.push("Run Command")
|
||||||
}
|
}
|
||||||
return strings
|
return strings
|
||||||
}
|
}
|
||||||
@ -48,6 +48,7 @@ function UserItem(p: { user: User }) {
|
|||||||
export function UsersPage({ }) {
|
export function UsersPage({ }) {
|
||||||
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
||||||
const [users, setUsers]: [User[], Dispatch<User[]>] = useState([] as User[])
|
const [users, setUsers]: [User[], Dispatch<User[]>] = useState([] as User[])
|
||||||
|
console.log({apiAuthenticated: apiAuthenticated, users: users})
|
||||||
|
|
||||||
const action: ActionInfo|undefined = INVITE_USER_ACTION
|
const action: ActionInfo|undefined = INVITE_USER_ACTION
|
||||||
|
|
||||||
@ -55,7 +56,9 @@ export function UsersPage({ }) {
|
|||||||
if (!apiAuthenticated) {
|
if (!apiAuthenticated) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
api.get('/users').then((response) => {
|
||||||
|
setUsers(response.data)
|
||||||
|
}).catch(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log('Failed to get servers: ' + error);
|
console.log('Failed to get servers: ' + error);
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
@ -70,7 +73,10 @@ export function UsersPage({ }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
api.get('/users').then((response) => {
|
||||||
|
setUsers(response.data)
|
||||||
|
|
||||||
|
}).catch(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log('Failed to get users: ' + error);
|
console.log('Failed to get users: ' + error);
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
@ -96,7 +102,7 @@ export function UsersPage({ }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>
|
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>
|
||||||
<UserActionsContext.Provider value={[]}>
|
<UserActionsContext.Provider value={USERS_ACTIONS}>
|
||||||
{userComponents}
|
{userComponents}
|
||||||
</UserActionsContext.Provider>
|
</UserActionsContext.Provider>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user