renamed vars
This commit is contained in:
parent
871f61e910
commit
c7667ec5b5
@ -11,13 +11,13 @@ const browserContext: Context<Browser> = createContext({} as Browser)
|
||||
const browserActionContext: Context<ActionInfo[]|null> = createContext(null as ActionInfo[]|null)
|
||||
|
||||
function FakeAction(props: {action: ActionInfo, browser: Browser}){
|
||||
return <Button rel="noopener noreferrer" target="_blank" href={`https://${props.browser.url}`}>{props.action.name}</Button>
|
||||
return <Button rel="noopener noreferrer" target="_blank" href={`https://${props.browser.Url}`}>{props.action.name}</Button>
|
||||
}
|
||||
|
||||
function BrowserActions() {
|
||||
const actions = useContext(browserActionContext)
|
||||
const browser = useContext(browserContext)
|
||||
return <actionIdentifierContext.Provider value={browser.id_}>
|
||||
return <actionIdentifierContext.Provider value={browser.Id}>
|
||||
<ActionGroup actions={actions? actions:[]} identifierSubstring="browser_id">
|
||||
<FakeAction action={{name: 'Browse', requestType: 'post', endpoint: '', args:{}}} browser={browser}/>
|
||||
</ActionGroup>
|
||||
@ -73,10 +73,10 @@ export function BrowsersPage({ }) {
|
||||
browserComponents.push(
|
||||
<browserContext.Provider value={browser}>
|
||||
<TableRow>
|
||||
<TableCell>{browser.owner_id}</TableCell>
|
||||
<TableCell>{browser.connected_to.user_id}</TableCell>
|
||||
<TableCell>{browser.connected_to.image.name}</TableCell>
|
||||
<TableCell>{browser.connected_to.image.version}</TableCell>
|
||||
<TableCell>{browser.OwnerId}</TableCell>
|
||||
<TableCell>{browser.ConnectedTo.OwnerId}</TableCell>
|
||||
<TableCell>{browser.ConnectedTo.Image.Name}</TableCell>
|
||||
<TableCell>{browser.ConnectedTo.Image.Version}</TableCell>
|
||||
<TableCell>
|
||||
<BrowserActions/>
|
||||
</TableCell>
|
||||
|
@ -257,7 +257,7 @@ function isUserAllowed(user: User|null, action: ActionInfo): boolean{
|
||||
return false
|
||||
}
|
||||
|
||||
const isAdmin = (user.permissions & Permission.Admin) === Permission.Admin
|
||||
const isAdmin = (user.Permissions & Permission.Admin) === Permission.Admin
|
||||
if (isAdmin){
|
||||
return true
|
||||
}
|
||||
@ -266,7 +266,7 @@ function isUserAllowed(user: User|null, action: ActionInfo): boolean{
|
||||
return true
|
||||
}
|
||||
|
||||
if ((action.permissions & user.permissions) == action.permissions){
|
||||
if ((action.permissions & user.Permissions) == action.permissions){
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1,51 +1,51 @@
|
||||
import { JSONSchema6, JSONSchema7 } from "json-schema"
|
||||
|
||||
export interface Port {
|
||||
number: number
|
||||
protocol: 'tcp' | 'udp'
|
||||
Number: number
|
||||
Protocol: 'tcp' | 'udp'
|
||||
}
|
||||
|
||||
|
||||
export interface ImageInfo {
|
||||
id_: string
|
||||
name: string
|
||||
version: string
|
||||
ports: Port[]
|
||||
Id: string
|
||||
Name: string
|
||||
Version: string
|
||||
Ports: Port[]
|
||||
}
|
||||
|
||||
|
||||
export interface ServerInfo {
|
||||
id_: string
|
||||
name: string
|
||||
on: boolean
|
||||
user_id: string
|
||||
image: ImageInfo
|
||||
ports: Port[] | null
|
||||
domain: string
|
||||
nickname?: string
|
||||
Id: string
|
||||
Name: string
|
||||
On: boolean
|
||||
OwnerId: string
|
||||
Image: ImageInfo
|
||||
Ports: Port[] | null
|
||||
Domain: string
|
||||
Nickname?: string
|
||||
}
|
||||
|
||||
|
||||
export interface User {
|
||||
username: string
|
||||
email: string
|
||||
permissions: number
|
||||
Username: string
|
||||
Email: string
|
||||
Permissions: number
|
||||
}
|
||||
|
||||
|
||||
export interface Browser {
|
||||
id_: string
|
||||
domain: string
|
||||
url: string
|
||||
owner_id: string
|
||||
connected_to: ServerInfo
|
||||
Id: string
|
||||
Domain: string
|
||||
Url: string
|
||||
OwnerId: string
|
||||
ConnectedTo: ServerInfo
|
||||
}
|
||||
|
||||
|
||||
export interface OpenApiMethodSchema {
|
||||
summary: string
|
||||
requestBody: {content: Record<string, {schema: JSONSchema7}>}
|
||||
api_response: 'Ignore' | 'Browse'
|
||||
api_response: 'Ignore' | 'Browse' | 'Terminal'
|
||||
permissions: number
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import React, { Context, Dispatch, createContext, useContext, useEffect, useStat
|
||||
import { TableRow, TableCell, Chip } from "@mui/material"
|
||||
import { ImageInfo, ServerInfo } from "./interfaces"
|
||||
import { JSONSchema7 } from "json-schema"
|
||||
import { Permission } from "./actions"
|
||||
import { Permission, SERVER_ACTIONS } from "./actions"
|
||||
|
||||
|
||||
|
||||
@ -25,36 +25,36 @@ function ServerItem(props: { server_info: ServerInfo }) {
|
||||
const user = useContext(UserInfoContext)
|
||||
let permissions = 0
|
||||
|
||||
if (props.server_info.user_id === user?.username){
|
||||
if (props.server_info.OwnerId === user?.Username){
|
||||
permissions |= Permission.Admin
|
||||
}else{
|
||||
if (serverPermissions === null){
|
||||
api.get(`/servers/${props.server_info.id_}/permissions`).then((event)=>{setServerPermissions(event.data)})
|
||||
api.get(`/servers/${props.server_info.Id}/permissions`).then((event)=>{setServerPermissions(event.data)})
|
||||
}else{
|
||||
permissions |= serverPermissions
|
||||
}
|
||||
if (user){
|
||||
permissions |= user.permissions
|
||||
permissions |= user.Permissions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const name = `${props.server_info.user_id}'s ${props.server_info.image.name} ${props.server_info.image.version} Server`
|
||||
const name = `${props.server_info.OwnerId}'s ${props.server_info.Image.Name} ${props.server_info.Image.Version} Server`
|
||||
|
||||
if (props.server_info.ports === null) {
|
||||
props.server_info.ports = []
|
||||
if (props.server_info.Ports === null) {
|
||||
props.server_info.Ports = []
|
||||
}
|
||||
|
||||
return (
|
||||
<UserInfoContext.Provider value={user? {username: user.username, email: user.email, permissions: permissions}: null}>
|
||||
<actionIdentifierContext.Provider value={props.server_info.id_}>
|
||||
<UserInfoContext.Provider value={user? {Username: user.Username, Email: user.Email, Permissions: permissions}: null}>
|
||||
<actionIdentifierContext.Provider value={props.server_info.Id}>
|
||||
<TableRow>
|
||||
<TableCell>{props.server_info.nickname}</TableCell>
|
||||
<TableCell>{props.server_info.user_id}</TableCell>
|
||||
<TableCell>{props.server_info.image.name}</TableCell>
|
||||
<TableCell>{props.server_info.image.version}</TableCell>
|
||||
<TableCell>{props.server_info.domain}</TableCell>
|
||||
<TableCell>{props.server_info.ports.map((port, index, array) => { return <Chip label={`${port.number}/${port.protocol}`} /> })}</TableCell>
|
||||
<TableCell>{props.server_info.Nickname}</TableCell>
|
||||
<TableCell>{props.server_info.OwnerId}</TableCell>
|
||||
<TableCell>{props.server_info.Image.Name}</TableCell>
|
||||
<TableCell>{props.server_info.Image.Version}</TableCell>
|
||||
<TableCell>{props.server_info.Domain}</TableCell>
|
||||
<TableCell>{props.server_info.Ports.map((port, index, array) => { return <Chip label={`${port.Number}/${port.Protocol}`} /> })}</TableCell>
|
||||
<TableCell>
|
||||
<ActionGroup actions={actions} identifierSubstring="server_id" />
|
||||
</TableCell>
|
||||
@ -74,7 +74,7 @@ export default function ServersBoard() {
|
||||
properties: {
|
||||
image_id: {
|
||||
type: "string",
|
||||
oneOf: images.map((value, index, array) => { return { const: value.id_, title: `${value.name} ${value.version}` } }),
|
||||
oneOf: images.map((value, index, array) => { return { const: value.Id, title: `${value.Name} ${value.Version}` } }),
|
||||
title: "Image Id"
|
||||
}
|
||||
},
|
||||
@ -140,9 +140,9 @@ export default function ServersBoard() {
|
||||
}
|
||||
)
|
||||
}}>
|
||||
<serverActionsContext.Provider value={useActions(api, '/servers/{server_id}')}>
|
||||
<serverActionsContext.Provider value={SERVER_ACTIONS}>
|
||||
{
|
||||
servers.sort((s1: ServerInfo, s2: ServerInfo) => { return s1.id_ < s2.id_ ? 0 : 1 }).map(
|
||||
servers.sort((s1: ServerInfo, s2: ServerInfo) => { return s1.Id < s2.Id ? 0 : 1 }).map(
|
||||
(value: ServerInfo, index: number, array) => {
|
||||
return <ServerItem server_info={value} />
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ function UserItem(p: { user: User }) {
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableCell>{user.username}</TableCell>
|
||||
<TableCell>{user.email}</TableCell>
|
||||
<TableCell>{user.permissions.map((value, index, array) => { return <Chip label={value} /> })}</TableCell>
|
||||
<TableCell>{user.Username}</TableCell>
|
||||
<TableCell>{user.Email}</TableCell>
|
||||
<TableCell>{user.Permissions.map((value, index, array) => { return <Chip label={value} /> })}</TableCell>
|
||||
<TableCell><ActionGroup actions={userActions} identifierSubstring="username" /></TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
@ -69,7 +69,7 @@ export function UsersPage({ }) {
|
||||
let userComponents = []
|
||||
|
||||
for (let user of users) {
|
||||
userComponents.push(<actionIdentifierContext.Provider value={user.username}><UserItem user={user} /></actionIdentifierContext.Provider>)
|
||||
userComponents.push(<actionIdentifierContext.Provider value={user.Username}><UserItem user={user} /></actionIdentifierContext.Provider>)
|
||||
}
|
||||
|
||||
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user