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); } 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 24ec9f4ec..3d71b0f8e 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/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} /> 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/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 }) => {
: 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[]; 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');