From 47c6d40358d99a92797a966b458e702899c78bbb Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 9 Nov 2023 21:04:27 -0500 Subject: [PATCH 1/5] fixed #349 --- core/src/handlers/users.rs | 2 +- dashboard/src/components/UserBox.tsx | 6 +----- dashboard/src/pages/settings/UserSettings.tsx | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/handlers/users.rs b/core/src/handlers/users.rs index f3a94f93..f6fe68c2 100644 --- a/core/src/handlers/users.rs +++ b/core/src/handlers/users.rs @@ -207,7 +207,7 @@ pub async fn change_password( let requester = users_manager.try_auth_or_err(&token)?; - if requester.uid != config.uid || !requester.can_perform_action(&UserAction::ManageUser) { + if requester.uid != config.uid && !requester.can_perform_action(&UserAction::ManageUser) { return Err(Error { kind: ErrorKind::PermissionDenied, source: eyre!("You are not authorized to change other users password"), diff --git a/dashboard/src/components/UserBox.tsx b/dashboard/src/components/UserBox.tsx index 7a42bcc9..31f09997 100644 --- a/dashboard/src/components/UserBox.tsx +++ b/dashboard/src/components/UserBox.tsx @@ -65,12 +65,8 @@ export default function UserBox({

- Create a new user account + Change password

-

- This user will start with no permissions. You can grant them - permissions later. -

{isSelf ? ( setShowChangePassword(false)} diff --git a/dashboard/src/pages/settings/UserSettings.tsx b/dashboard/src/pages/settings/UserSettings.tsx index 7b372db1..0d1f134d 100644 --- a/dashboard/src/pages/settings/UserSettings.tsx +++ b/dashboard/src/pages/settings/UserSettings.tsx @@ -204,7 +204,7 @@ export const UserSettings = () => { disabled: boolean ) => selectedUser && ( -
+
{permissionList.map((permission) => { const currentSettings = selectedUser.permissions[permission.permission]; @@ -245,6 +245,7 @@ export const UserSettings = () => { optionKey={(uuid) => uuid} onChange={(newSettings) => { // I hate typescript + // |- me too const newPermissions = { ...selectedUser.permissions, [permission.permission]: newSettings, From bb9c3c3add27ade8003d8bde3cef4e9641662493 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 17 Nov 2023 07:43:48 -0500 Subject: [PATCH 2/5] added console filtering --- dashboard/src/components/GameConsole.tsx | 223 ++++++++++++------ dashboard/src/data/ConsoleStream.ts | 8 +- .../src/pages/InstanceTabs/InstanceTabs.tsx | 2 +- 3 files changed, 163 insertions(+), 70 deletions(-) diff --git a/dashboard/src/components/GameConsole.tsx b/dashboard/src/components/GameConsole.tsx index d33ae6d8..ca491b55 100644 --- a/dashboard/src/components/GameConsole.tsx +++ b/dashboard/src/components/GameConsole.tsx @@ -1,17 +1,19 @@ import { faCircle, faServer } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import axios from 'axios'; -import { useConsoleStream } from 'data/ConsoleStream'; +import { ConsoleEvent, useConsoleStream } from 'data/ConsoleStream'; import { InstanceContext } from 'data/InstanceContext'; import { CommandHistoryContext } from 'data/CommandHistoryContext'; import { useUserAuthorized } from 'data/UserInfo'; import Tooltip from 'rc-tooltip'; import { useContext, useEffect } from 'react'; import { useRef, useState } from 'react'; -import { usePrevious } from 'utils/hooks'; +import { useLocalStorageQueryParam, usePrevious } from 'utils/hooks'; import { DISABLE_AUTOFILL } from 'utils/util'; import ErrorGraphic from './ErrorGraphic'; import { useDocumentTitle } from 'usehooks-ts'; +import Checkbox from './Atoms/Checkbox'; +import Button from './Atoms/Button'; const autoScrollThreshold = 10; @@ -24,8 +26,14 @@ export default function GameConsole() { 'can_access_instance_console', uuid ); - const { consoleLog, consoleStatus } = useConsoleStream(uuid); + const defaultFilters = { + "PlayerMessage": true, + "SystemMessage": true, + "InstanceOutput": true + } + const { consoleLog, consoleStatus, clearConsoleLog } = useConsoleStream(uuid); const [command, setCommand] = useState(''); + const [filters, setFilters] = useLocalStorageQueryParam("filter", JSON.stringify(defaultFilters)) const { commandHistory, appendCommandHistory } = useContext( CommandHistoryContext ); @@ -128,75 +136,154 @@ export default function GameConsole() { } }; + const updatePlayerMFilter = (checked: boolean) => { + let filtersJSON: any = filters; + while (typeof filtersJSON == "string") { + console.log(filtersJSON) + filtersJSON = JSON.parse(filtersJSON) + } + filtersJSON["PlayerMessage"] = checked; + setFilters(JSON.stringify(filtersJSON)) + } + + const updateSystemMFilter = (checked: boolean) => { + let filtersJSON: any = filters; + while (typeof filtersJSON == "string") { + console.log(filtersJSON) + filtersJSON = JSON.parse(filtersJSON) + } + filtersJSON["SystemMessage"] = checked; + setFilters(JSON.stringify(filtersJSON)) + } + + const updateInstanceIOFilter = (checked: boolean) => { + console.log(filters, typeof filters) + let filtersJSON: any = filters; + while (typeof filtersJSON == "string") { + console.log(filtersJSON) + filtersJSON = JSON.parse(filtersJSON) + } + filtersJSON["InstanceOutput"] = checked; + setFilters(JSON.stringify(filtersJSON)) + } + + const filterMessage = (line: ConsoleEvent) => { + const playerm_ = new RegExp(/\[.+\]+: <(.+)> (.+)/); + const systemm_ = new RegExp(/\[.+\]+: (?!<)(.+)/); + + let filtersJSON: any = filters; + while (typeof filtersJSON == "string") { + filtersJSON = JSON.parse(filtersJSON) + } + + let found = false; + if (filtersJSON["PlayerMessage"]) { + if (line.message.match(playerm_)) found = true + } + if (filtersJSON["SystemMessage"]) { + console.log(line.message) + console.log(line.message.match(systemm_)) + if (line.message.match(systemm_)) found = true + } + if (filtersJSON["InstanceOutput"]) { + found = true + } + + return found + } + return ( -
- {consoleStatusMessage}} - placement="bottom" - showArrow={false} - trigger={['hover']} - mouseEnterDelay={0} - > - - - {!canAccessConsole || consoleStatus === 'no-permission' ? ( - - ) : consoleLog.length === 0 ? ( - +
+
+ + + +
+
); } diff --git a/dashboard/src/data/ConsoleStream.ts b/dashboard/src/data/ConsoleStream.ts index 36c123f1..469eff15 100644 --- a/dashboard/src/data/ConsoleStream.ts +++ b/dashboard/src/data/ConsoleStream.ts @@ -89,6 +89,11 @@ export const useConsoleStream = (uuid: string) => { uuid ); + const clearConsoleLog = () => { + const econsoleLog: ConsoleEvent[] = [] + setConsoleLog(econsoleLog) + } + const mergeConsoleLog = (newLog: ClientEvent[]) => { setConsoleLog((oldLog) => { const consoleEvents = newLog @@ -99,7 +104,6 @@ export const useConsoleStream = (uuid: string) => { ); }) .map(toConsoleEvent); - const mergedLog = [...oldLog, ...consoleEvents]; // this is slow ik return mergedLog.filter( @@ -135,6 +139,7 @@ export const useConsoleStream = (uuid: string) => { websocket.onclose = (event) => { setStatus(event.code === 1000 ? 'closed' : 'error'); + console.log("event: ", event) }; return () => { @@ -162,5 +167,6 @@ export const useConsoleStream = (uuid: string) => { return { consoleLog, consoleStatus: status, + clearConsoleLog }; }; diff --git a/dashboard/src/pages/InstanceTabs/InstanceTabs.tsx b/dashboard/src/pages/InstanceTabs/InstanceTabs.tsx index 43355700..2131ad9e 100644 --- a/dashboard/src/pages/InstanceTabs/InstanceTabs.tsx +++ b/dashboard/src/pages/InstanceTabs/InstanceTabs.tsx @@ -159,7 +159,7 @@ const InstanceTabs = () => { className="gutter-stable -mx-3 flex grow flex-row items-stretch overflow-y-auto pl-4 pr-2" key={`${instance.name}-${tab.title}`} > -
+
{tab.displayTitle && (
{tab.displayTitle} From 7b92e77573e09b75087c0d5c344fc45406003102 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 22 Nov 2023 19:09:39 -0500 Subject: [PATCH 3/5] added textwraps to notifications --- dashboard/src/components/Atoms/NotificationCard.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dashboard/src/components/Atoms/NotificationCard.tsx b/dashboard/src/components/Atoms/NotificationCard.tsx index a9482b1f..0396e0b9 100644 --- a/dashboard/src/components/Atoms/NotificationCard.tsx +++ b/dashboard/src/components/Atoms/NotificationCard.tsx @@ -51,14 +51,17 @@ export default function NotificationCard({ >
-

+

{title}

-

+

{message}

- {!message && ( - + {!message && ( + /** + * https://tailwindcss.com/docs/word-break + */ + {formatNotificationTime(timestamp)} )} From f3f2695db24d486b059b7fbfd7ab15468da47a2a Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 27 Nov 2023 19:53:20 -0500 Subject: [PATCH 4/5] added filter --- dashboard/src/components/GameConsole.tsx | 104 ++++++++--------------- 1 file changed, 34 insertions(+), 70 deletions(-) diff --git a/dashboard/src/components/GameConsole.tsx b/dashboard/src/components/GameConsole.tsx index ca491b55..67f2f405 100644 --- a/dashboard/src/components/GameConsole.tsx +++ b/dashboard/src/components/GameConsole.tsx @@ -12,8 +12,8 @@ import { useLocalStorageQueryParam, usePrevious } from 'utils/hooks'; import { DISABLE_AUTOFILL } from 'utils/util'; import ErrorGraphic from './ErrorGraphic'; import { useDocumentTitle } from 'usehooks-ts'; -import Checkbox from './Atoms/Checkbox'; import Button from './Atoms/Button'; +import Checkbox from './Atoms/Checkbox'; const autoScrollThreshold = 10; @@ -33,7 +33,8 @@ export default function GameConsole() { } const { consoleLog, consoleStatus, clearConsoleLog } = useConsoleStream(uuid); const [command, setCommand] = useState(''); - const [filters, setFilters] = useLocalStorageQueryParam("filter", JSON.stringify(defaultFilters)) + const [filter, setFilter] = useState(''); + const [regex, setRegex] = useState(true); const { commandHistory, appendCommandHistory } = useContext( CommandHistoryContext ); @@ -136,76 +137,28 @@ export default function GameConsole() { } }; - const updatePlayerMFilter = (checked: boolean) => { - let filtersJSON: any = filters; - while (typeof filtersJSON == "string") { - console.log(filtersJSON) - filtersJSON = JSON.parse(filtersJSON) - } - filtersJSON["PlayerMessage"] = checked; - setFilters(JSON.stringify(filtersJSON)) - } - - const updateSystemMFilter = (checked: boolean) => { - let filtersJSON: any = filters; - while (typeof filtersJSON == "string") { - console.log(filtersJSON) - filtersJSON = JSON.parse(filtersJSON) - } - filtersJSON["SystemMessage"] = checked; - setFilters(JSON.stringify(filtersJSON)) - } - - const updateInstanceIOFilter = (checked: boolean) => { - console.log(filters, typeof filters) - let filtersJSON: any = filters; - while (typeof filtersJSON == "string") { - console.log(filtersJSON) - filtersJSON = JSON.parse(filtersJSON) - } - filtersJSON["InstanceOutput"] = checked; - setFilters(JSON.stringify(filtersJSON)) - } - const filterMessage = (line: ConsoleEvent) => { - const playerm_ = new RegExp(/\[.+\]+: <(.+)> (.+)/); - const systemm_ = new RegExp(/\[.+\]+: (?!<)(.+)/); - - let filtersJSON: any = filters; - while (typeof filtersJSON == "string") { - filtersJSON = JSON.parse(filtersJSON) + if (filter == '') return true; + if (regex) { + try { + const filterRegex = new RegExp(filter, "i"); + if (line.message.match(filterRegex)) return true; + } catch (e) { + console.log("regex invalid!!!"); + } + } else { + if (line.message.toLowerCase().indexOf(filter.toLowerCase()) != -1) return true; } + return false; + } - let found = false; - if (filtersJSON["PlayerMessage"]) { - if (line.message.match(playerm_)) found = true - } - if (filtersJSON["SystemMessage"]) { - console.log(line.message) - console.log(line.message.match(systemm_)) - if (line.message.match(systemm_)) found = true - } - if (filtersJSON["InstanceOutput"]) { - found = true - } - - return found + const checkRegex = (checked: boolean) => { + setRegex(checked) } return (
-
-
- - - -
+ {/*
*/} +
+ setFilter(e.target.value)} + id="search" + type="text" + /> +
{!canAccessConsole || consoleStatus === 'no-permission' ? ( @@ -239,13 +203,13 @@ export default function GameConsole() { ) : (
    {consoleLog.map((line) => { @@ -272,7 +236,7 @@ export default function GameConsole() { }} > setCommand(e.target.value)} From 6d8adc1fa022ca6b690df72751b9923f23e52042 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 27 Nov 2023 19:59:22 -0500 Subject: [PATCH 5/5] text wrap --- dashboard/src/components/Atoms/NotificationCard.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/dashboard/src/components/Atoms/NotificationCard.tsx b/dashboard/src/components/Atoms/NotificationCard.tsx index 0396e0b9..c29422b3 100644 --- a/dashboard/src/components/Atoms/NotificationCard.tsx +++ b/dashboard/src/components/Atoms/NotificationCard.tsx @@ -58,9 +58,6 @@ export default function NotificationCard({ {message}

    {!message && ( - /** - * https://tailwindcss.com/docs/word-break - */ {formatNotificationTime(timestamp)}