From 4a234af7a30c0d53ec78ee8c8bf15e2d5db43ecc Mon Sep 17 00:00:00 2001 From: Charles Morgan Date: Sun, 8 Nov 2020 21:09:22 -0500 Subject: [PATCH 1/5] Minor changes Changes CopyOnClick to allow any. Allows database information to be copied on click. Changes layouts on database/backups to match the network tab. Changes text to lighten it one level from 400 to 300 for easier visibility. Moves database api endpoints to their own folder for some organization. --- .../{ => databases}/createServerDatabase.ts | 2 +- .../{ => databases}/deleteServerDatabase.ts | 0 .../{ => databases}/getServerDatabases.ts | 0 .../{ => databases}/rotateDatabasePassword.ts | 2 +- .../components/elements/CopyOnClick.tsx | 2 +- .../server/backups/BackupContainer.tsx | 22 +++++++------- .../server/databases/CreateDatabaseButton.tsx | 2 +- .../server/databases/DatabaseRow.tsx | 29 ++++++++++--------- .../server/databases/DatabasesContainer.tsx | 22 +++++++------- .../server/databases/RotatePasswordButton.tsx | 4 +-- .../server/schedules/ScheduleContainer.tsx | 2 +- .../server/users/UsersContainer.tsx | 2 +- resources/scripts/state/server/databases.ts | 2 +- 13 files changed, 47 insertions(+), 44 deletions(-) rename resources/scripts/api/server/{ => databases}/createServerDatabase.ts (94%) rename resources/scripts/api/server/{ => databases}/deleteServerDatabase.ts (100%) rename resources/scripts/api/server/{ => databases}/getServerDatabases.ts (100%) rename resources/scripts/api/server/{ => databases}/rotateDatabasePassword.ts (92%) diff --git a/resources/scripts/api/server/createServerDatabase.ts b/resources/scripts/api/server/databases/createServerDatabase.ts similarity index 94% rename from resources/scripts/api/server/createServerDatabase.ts rename to resources/scripts/api/server/databases/createServerDatabase.ts index 90103337c..cf036f91f 100644 --- a/resources/scripts/api/server/createServerDatabase.ts +++ b/resources/scripts/api/server/databases/createServerDatabase.ts @@ -1,4 +1,4 @@ -import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/getServerDatabases'; +import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/databases/getServerDatabases'; import http from '@/api/http'; export default (uuid: string, data: { connectionsFrom: string; databaseName: string }): Promise => { diff --git a/resources/scripts/api/server/deleteServerDatabase.ts b/resources/scripts/api/server/databases/deleteServerDatabase.ts similarity index 100% rename from resources/scripts/api/server/deleteServerDatabase.ts rename to resources/scripts/api/server/databases/deleteServerDatabase.ts diff --git a/resources/scripts/api/server/getServerDatabases.ts b/resources/scripts/api/server/databases/getServerDatabases.ts similarity index 100% rename from resources/scripts/api/server/getServerDatabases.ts rename to resources/scripts/api/server/databases/getServerDatabases.ts diff --git a/resources/scripts/api/server/rotateDatabasePassword.ts b/resources/scripts/api/server/databases/rotateDatabasePassword.ts similarity index 92% rename from resources/scripts/api/server/rotateDatabasePassword.ts rename to resources/scripts/api/server/databases/rotateDatabasePassword.ts index c6c9e8aef..0e0619a84 100644 --- a/resources/scripts/api/server/rotateDatabasePassword.ts +++ b/resources/scripts/api/server/databases/rotateDatabasePassword.ts @@ -1,4 +1,4 @@ -import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/getServerDatabases'; +import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/databases/getServerDatabases'; import http from '@/api/http'; export default (uuid: string, database: string): Promise => { diff --git a/resources/scripts/components/elements/CopyOnClick.tsx b/resources/scripts/components/elements/CopyOnClick.tsx index f1914ed57..f7e2d4957 100644 --- a/resources/scripts/components/elements/CopyOnClick.tsx +++ b/resources/scripts/components/elements/CopyOnClick.tsx @@ -19,7 +19,7 @@ const Toast = styled.div` } `; -const CopyOnClick: React.FC<{ text: string }> = ({ text, children }) => { +const CopyOnClick: React.FC<{ text: any }> = ({ text, children }) => { const [ copied, setCopied ] = useState(false); useEffect(() => { diff --git a/resources/scripts/components/server/backups/BackupContainer.tsx b/resources/scripts/components/server/backups/BackupContainer.tsx index b3bfdc945..493c059a5 100644 --- a/resources/scripts/components/server/backups/BackupContainer.tsx +++ b/resources/scripts/components/server/backups/BackupContainer.tsx @@ -34,7 +34,7 @@ export default () => { {!backups.items.length ? -

+

There are no backups stored for this server.

: @@ -47,21 +47,21 @@ export default () => { } {backupLimit === 0 && -

+

Backups cannot be created for this server.

} - {(backupLimit > 0 && backups.items.length > 0) && -

- {backups.items.length} of {backupLimit} backups have been created for this server. -

- } - {backupLimit > 0 && backupLimit !== backups.items.length && -
- +
+ {(backupLimit > 0 && backups.items.length > 0) && +

+ {backups.items.length} of {backupLimit} backups have been created for this server. +

+ } + {backupLimit > 0 && backupLimit !== backups.items.length && + + }
- } ); diff --git a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx index 044587e6e..2ce843365 100644 --- a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx +++ b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx @@ -3,7 +3,7 @@ import Modal from '@/components/elements/Modal'; import { Form, Formik, FormikHelpers } from 'formik'; import Field from '@/components/elements/Field'; import { object, string } from 'yup'; -import createServerDatabase from '@/api/server/createServerDatabase'; +import createServerDatabase from '@/api/server/databases/createServerDatabase'; import { ServerContext } from '@/state/server'; import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; diff --git a/resources/scripts/components/server/databases/DatabaseRow.tsx b/resources/scripts/components/server/databases/DatabaseRow.tsx index 1175aef48..3eeaa981e 100644 --- a/resources/scripts/components/server/databases/DatabaseRow.tsx +++ b/resources/scripts/components/server/databases/DatabaseRow.tsx @@ -7,17 +7,18 @@ import Field from '@/components/elements/Field'; import { object, string } from 'yup'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ServerContext } from '@/state/server'; -import deleteServerDatabase from '@/api/server/deleteServerDatabase'; +import deleteServerDatabase from '@/api/server/databases/deleteServerDatabase'; import { httpErrorToHuman } from '@/api/http'; import RotatePasswordButton from '@/components/server/databases/RotatePasswordButton'; import Can from '@/components/elements/Can'; -import { ServerDatabase } from '@/api/server/getServerDatabases'; +import { ServerDatabase } from '@/api/server/databases/getServerDatabases'; import useFlash from '@/plugins/useFlash'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; import Label from '@/components/elements/Label'; import Input from '@/components/elements/Input'; import GreyRowBox from '@/components/elements/GreyRowBox'; +import CopyOnClick from '@/components/elements/CopyOnClick'; interface Props { database: ServerDatabase; @@ -113,7 +114,7 @@ export default ({ database, className }: Props) => {

Database connection details

- +
@@ -121,21 +122,23 @@ export default ({ database, className }: Props) => {
- +
- +
- + + +
@@ -151,10 +154,10 @@ export default ({ database, className }: Props) => {
-

{database.name}

+

{database.name}

diff --git a/resources/scripts/components/server/databases/DatabasesContainer.tsx b/resources/scripts/components/server/databases/DatabasesContainer.tsx index 8ee4b3129..b61d8ed09 100644 --- a/resources/scripts/components/server/databases/DatabasesContainer.tsx +++ b/resources/scripts/components/server/databases/DatabasesContainer.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import getServerDatabases from '@/api/server/getServerDatabases'; +import getServerDatabases from '@/api/server/databases/getServerDatabases'; import { ServerContext } from '@/state/server'; import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; @@ -62,17 +62,17 @@ export default () => {

} - {(databaseLimit > 0 && databases.length > 0) && -

- {databases.length} of {databaseLimit} databases have been allocated to this - server. -

- } - {databaseLimit > 0 && databaseLimit !== databases.length && -
- +
+ {(databaseLimit > 0 && databases.length > 0) && +

+ {databases.length} of {databaseLimit} databases have been allocated to this + server. +

+ } + {databaseLimit > 0 && databaseLimit !== databases.length && + + }
- } diff --git a/resources/scripts/components/server/databases/RotatePasswordButton.tsx b/resources/scripts/components/server/databases/RotatePasswordButton.tsx index 41c116006..68b1e532d 100644 --- a/resources/scripts/components/server/databases/RotatePasswordButton.tsx +++ b/resources/scripts/components/server/databases/RotatePasswordButton.tsx @@ -1,9 +1,9 @@ import React, { useState } from 'react'; -import rotateDatabasePassword from '@/api/server/rotateDatabasePassword'; +import rotateDatabasePassword from '@/api/server/databases/rotateDatabasePassword'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { ServerContext } from '@/state/server'; -import { ServerDatabase } from '@/api/server/getServerDatabases'; +import { ServerDatabase } from '@/api/server/databases/getServerDatabases'; import { httpErrorToHuman } from '@/api/http'; import Button from '@/components/elements/Button'; import tw from 'twin.macro'; diff --git a/resources/scripts/components/server/schedules/ScheduleContainer.tsx b/resources/scripts/components/server/schedules/ScheduleContainer.tsx index 54a63a328..04c302917 100644 --- a/resources/scripts/components/server/schedules/ScheduleContainer.tsx +++ b/resources/scripts/components/server/schedules/ScheduleContainer.tsx @@ -43,7 +43,7 @@ export default ({ match, history }: RouteComponentProps) => { <> { schedules.length === 0 ? -

+

There are no schedules configured for this server.

: diff --git a/resources/scripts/components/server/users/UsersContainer.tsx b/resources/scripts/components/server/users/UsersContainer.tsx index f29dc9202..f5589f4a5 100644 --- a/resources/scripts/components/server/users/UsersContainer.tsx +++ b/resources/scripts/components/server/users/UsersContainer.tsx @@ -51,7 +51,7 @@ export default () => { {!subusers.length ? -

+

It looks like you don't have any subusers.

: diff --git a/resources/scripts/state/server/databases.ts b/resources/scripts/state/server/databases.ts index 7fa697dbd..deee25ffb 100644 --- a/resources/scripts/state/server/databases.ts +++ b/resources/scripts/state/server/databases.ts @@ -1,5 +1,5 @@ import { action, Action } from 'easy-peasy'; -import { ServerDatabase } from '@/api/server/getServerDatabases'; +import { ServerDatabase } from '@/api/server/databases/getServerDatabases'; export interface ServerDatabaseStore { data: ServerDatabase[]; From df6402644999bc23a639e809d9095f92de8d071b Mon Sep 17 00:00:00 2001 From: Matt Malec Date: Sun, 8 Nov 2020 21:57:22 -0500 Subject: [PATCH 2/5] Update AuthenticateIPAccess.php Fix a 500 error when processing a request with an IP filter --- app/Http/Middleware/Api/AuthenticateIPAccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/Api/AuthenticateIPAccess.php b/app/Http/Middleware/Api/AuthenticateIPAccess.php index 30377794b..8f57b820d 100644 --- a/app/Http/Middleware/Api/AuthenticateIPAccess.php +++ b/app/Http/Middleware/Api/AuthenticateIPAccess.php @@ -29,7 +29,7 @@ class AuthenticateIPAccess } $find = new IP($request->ip()); - foreach (json_decode($model->allowed_ips) as $ip) { + foreach ($model->allowed_ips as $ip) { if (Range::parse($ip)->contains($find)) { return $next($request); } From 76e3bcaa4206423c4be4770736e6b8f84940b248 Mon Sep 17 00:00:00 2001 From: Griffin T Date: Mon, 9 Nov 2020 15:34:56 +0800 Subject: [PATCH 3/5] Keep cursor at the end of line when going through history --- resources/scripts/components/server/Console.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/scripts/components/server/Console.tsx b/resources/scripts/components/server/Console.tsx index abf423d34..c14354a75 100644 --- a/resources/scripts/components/server/Console.tsx +++ b/resources/scripts/components/server/Console.tsx @@ -80,12 +80,16 @@ export default () => { TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m', ); - const handleCommandKeydown = (e: React.KeyboardEvent) => { + const handleCommandKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'ArrowUp') { const newIndex = Math.min(historyIndex + 1, history!.length - 1); setHistoryIndex(newIndex); e.currentTarget.value = history![newIndex] || ''; + + // By default up arrow will also bring the cursor to the start of the line, + // so we'll preventDefault to keep it at the end. + e.preventDefault(); } if (e.key === 'ArrowDown') { @@ -185,7 +189,7 @@ export default () => { type={'text'} disabled={!instance || !connected} css={tw`bg-transparent text-neutral-100 p-2 pl-0 w-full`} - onKeyDown={e => handleCommandKeydown(e)} + onKeyDown={handleCommandKeyDown} />
From f65cdd2dfbc8fb753ee1dbb537c6457417f20781 Mon Sep 17 00:00:00 2001 From: Griffin T Date: Mon, 9 Nov 2020 16:14:09 +0800 Subject: [PATCH 4/5] Dont add trailing slash to file manager row NavLink --- resources/scripts/components/server/files/FileObjectRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/scripts/components/server/files/FileObjectRow.tsx b/resources/scripts/components/server/files/FileObjectRow.tsx index f4ac06219..fccef1ec6 100644 --- a/resources/scripts/components/server/files/FileObjectRow.tsx +++ b/resources/scripts/components/server/files/FileObjectRow.tsx @@ -45,7 +45,7 @@ const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
: From 2f2d105a4f1d5178b42f938c96bd31f364056f25 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 10 Nov 2020 20:13:55 -0800 Subject: [PATCH 5/5] Fix test cases --- tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php index 8d47fdd54..545626317 100644 --- a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php +++ b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php @@ -26,7 +26,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testWithValidIP() { - $model = factory(ApiKey::class)->make(['allowed_ips' => '["127.0.0.1"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1'); @@ -39,7 +39,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testValidIPAgainstCIDRRange() { - $model = factory(ApiKey::class)->make(['allowed_ips' => '["192.168.1.1/28"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['192.168.1.1/28']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15'); @@ -55,7 +55,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase { $this->expectException(AccessDeniedHttpException::class); - $model = factory(ApiKey::class)->make(['allowed_ips' => '["127.0.0.1"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2');