Merge branch 'develop' into develop

This commit is contained in:
GravityCube 2020-11-13 01:11:18 -03:00 committed by GitHub
commit 5eebc7221d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 58 additions and 51 deletions

View file

@ -29,7 +29,7 @@ class AuthenticateIPAccess
} }
$find = new IP($request->ip()); $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)) { if (Range::parse($ip)->contains($find)) {
return $next($request); return $next($request);
} }

View file

@ -1,4 +1,4 @@
import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/getServerDatabases'; import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/databases/getServerDatabases';
import http from '@/api/http'; import http from '@/api/http';
export default (uuid: string, data: { connectionsFrom: string; databaseName: string }): Promise<ServerDatabase> => { export default (uuid: string, data: { connectionsFrom: string; databaseName: string }): Promise<ServerDatabase> => {

View file

@ -1,4 +1,4 @@
import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/getServerDatabases'; import { rawDataToServerDatabase, ServerDatabase } from '@/api/server/databases/getServerDatabases';
import http from '@/api/http'; import http from '@/api/http';
export default (uuid: string, database: string): Promise<ServerDatabase> => { export default (uuid: string, database: string): Promise<ServerDatabase> => {

View file

@ -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); const [ copied, setCopied ] = useState(false);
useEffect(() => { useEffect(() => {

View file

@ -80,12 +80,16 @@ export default () => {
TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m', TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m',
); );
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => { const handleCommandKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'ArrowUp') { if (e.key === 'ArrowUp') {
const newIndex = Math.min(historyIndex + 1, history!.length - 1); const newIndex = Math.min(historyIndex + 1, history!.length - 1);
setHistoryIndex(newIndex); setHistoryIndex(newIndex);
e.currentTarget.value = history![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') { if (e.key === 'ArrowDown') {
@ -185,7 +189,7 @@ export default () => {
type={'text'} type={'text'}
disabled={!instance || !connected} disabled={!instance || !connected}
css={tw`bg-transparent text-neutral-100 p-2 pl-0 w-full`} css={tw`bg-transparent text-neutral-100 p-2 pl-0 w-full`}
onKeyDown={e => handleCommandKeydown(e)} onKeyDown={handleCommandKeyDown}
/> />
</div> </div>
</div> </div>

View file

@ -34,7 +34,7 @@ export default () => {
<ServerContentBlock title={'Backups'}> <ServerContentBlock title={'Backups'}>
<FlashMessageRender byKey={'backups'} css={tw`mb-4`}/> <FlashMessageRender byKey={'backups'} css={tw`mb-4`}/>
{!backups.items.length ? {!backups.items.length ?
<p css={tw`text-center text-sm text-neutral-400`}> <p css={tw`text-center text-sm text-neutral-300`}>
There are no backups stored for this server. There are no backups stored for this server.
</p> </p>
: :
@ -47,21 +47,21 @@ export default () => {
</div> </div>
} }
{backupLimit === 0 && {backupLimit === 0 &&
<p css={tw`text-center text-sm text-neutral-400`}> <p css={tw`text-center text-sm text-neutral-300`}>
Backups cannot be created for this server. Backups cannot be created for this server.
</p> </p>
} }
<Can action={'backup.create'}> <Can action={'backup.create'}>
{(backupLimit > 0 && backups.items.length > 0) && <div css={tw`mt-6 sm:flex items-center justify-end`}>
<p css={tw`text-center text-xs text-neutral-400 mt-2`}> {(backupLimit > 0 && backups.items.length > 0) &&
{backups.items.length} of {backupLimit} backups have been created for this server. <p css={tw`text-sm text-neutral-300 mb-4 sm:mr-6 sm:mb-0`}>
</p> {backups.items.length} of {backupLimit} backups have been created for this server.
} </p>
{backupLimit > 0 && backupLimit !== backups.items.length && }
<div css={tw`mt-6 flex justify-end`}> {backupLimit > 0 && backupLimit !== backups.items.length &&
<CreateBackupButton/> <CreateBackupButton css={tw`w-full sm:w-auto`}/>
}
</div> </div>
}
</Can> </Can>
</ServerContentBlock> </ServerContentBlock>
); );

View file

@ -3,7 +3,7 @@ import Modal from '@/components/elements/Modal';
import { Form, Formik, FormikHelpers } from 'formik'; import { Form, Formik, FormikHelpers } from 'formik';
import Field from '@/components/elements/Field'; import Field from '@/components/elements/Field';
import { object, string } from 'yup'; import { object, string } from 'yup';
import createServerDatabase from '@/api/server/createServerDatabase'; import createServerDatabase from '@/api/server/databases/createServerDatabase';
import { ServerContext } from '@/state/server'; import { ServerContext } from '@/state/server';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';

View file

@ -7,17 +7,18 @@ import Field from '@/components/elements/Field';
import { object, string } from 'yup'; import { object, string } from 'yup';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
import { ServerContext } from '@/state/server'; import { ServerContext } from '@/state/server';
import deleteServerDatabase from '@/api/server/deleteServerDatabase'; import deleteServerDatabase from '@/api/server/databases/deleteServerDatabase';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import RotatePasswordButton from '@/components/server/databases/RotatePasswordButton'; import RotatePasswordButton from '@/components/server/databases/RotatePasswordButton';
import Can from '@/components/elements/Can'; 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 useFlash from '@/plugins/useFlash';
import tw from 'twin.macro'; import tw from 'twin.macro';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import Label from '@/components/elements/Label'; import Label from '@/components/elements/Label';
import Input from '@/components/elements/Input'; import Input from '@/components/elements/Input';
import GreyRowBox from '@/components/elements/GreyRowBox'; import GreyRowBox from '@/components/elements/GreyRowBox';
import CopyOnClick from '@/components/elements/CopyOnClick';
interface Props { interface Props {
database: ServerDatabase; database: ServerDatabase;
@ -113,7 +114,7 @@ export default ({ database, className }: Props) => {
<h3 css={tw`mb-6`}>Database connection details</h3> <h3 css={tw`mb-6`}>Database connection details</h3>
<div> <div>
<Label>Endpoint</Label> <Label>Endpoint</Label>
<Input type={'text'} readOnly value={database.connectionString} /> <CopyOnClick text={database.connectionString}><Input type={'text'} readOnly value={database.connectionString} /></CopyOnClick>
</div> </div>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Label>Connections from</Label> <Label>Connections from</Label>
@ -121,21 +122,23 @@ export default ({ database, className }: Props) => {
</div> </div>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Label>Username</Label> <Label>Username</Label>
<Input type={'text'} readOnly value={database.username} /> <CopyOnClick text={database.username}><Input type={'text'} readOnly value={database.username} /></CopyOnClick>
</div> </div>
<Can action={'database.view_password'}> <Can action={'database.view_password'}>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Label>Password</Label> <Label>Password</Label>
<Input type={'text'} readOnly value={database.password}/> <CopyOnClick text={database.password?.valueOf}><Input type={'text'} readOnly value={database.password}/></CopyOnClick>
</div> </div>
</Can> </Can>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
<Label>JBDC Connection String</Label> <Label>JBDC Connection String</Label>
<Input <CopyOnClick text={`jdbc:mysql://${database.username}:${database.password}@${database.connectionString}/${database.name}`}>
type={'text'} <Input
readOnly type={'text'}
value={`jdbc:mysql://${database.username}:${database.password}@${database.connectionString}/${database.name}`} readOnly
/> value={`jdbc:mysql://${database.username}:${database.password}@${database.connectionString}/${database.name}`}
/>
</CopyOnClick>
</div> </div>
<div css={tw`mt-6 text-right`}> <div css={tw`mt-6 text-right`}>
<Can action={'database.update'}> <Can action={'database.update'}>
@ -151,10 +154,10 @@ export default ({ database, className }: Props) => {
<FontAwesomeIcon icon={faDatabase} fixedWidth/> <FontAwesomeIcon icon={faDatabase} fixedWidth/>
</div> </div>
<div css={tw`flex-1 ml-4`}> <div css={tw`flex-1 ml-4`}>
<p css={tw`text-lg`}>{database.name}</p> <CopyOnClick text={database.name}><p css={tw`text-lg`}>{database.name}</p></CopyOnClick>
</div> </div>
<div css={tw`ml-8 text-center hidden md:block`}> <div css={tw`ml-8 text-center hidden md:block`}>
<p css={tw`text-sm`}>{database.connectionString}</p> <CopyOnClick text={database.connectionString}><p css={tw`text-sm`}>{database.connectionString}</p></CopyOnClick>
<p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Endpoint</p> <p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Endpoint</p>
</div> </div>
<div css={tw`ml-8 text-center hidden md:block`}> <div css={tw`ml-8 text-center hidden md:block`}>
@ -162,7 +165,7 @@ export default ({ database, className }: Props) => {
<p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Connections from</p> <p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Connections from</p>
</div> </div>
<div css={tw`ml-8 text-center hidden md:block`}> <div css={tw`ml-8 text-center hidden md:block`}>
<p css={tw`text-sm`}>{database.username}</p> <CopyOnClick text={database.username}><p css={tw`text-sm`}>{database.username}</p></CopyOnClick>
<p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Username</p> <p css={tw`mt-1 text-2xs text-neutral-500 uppercase select-none`}>Username</p>
</div> </div>
<div css={tw`ml-8`}> <div css={tw`ml-8`}>

View file

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'; 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 { ServerContext } from '@/state/server';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
@ -62,17 +62,17 @@ export default () => {
</p> </p>
} }
<Can action={'database.create'}> <Can action={'database.create'}>
{(databaseLimit > 0 && databases.length > 0) && <div css={tw`mt-6 sm:flex items-center justify-end`}>
<p css={tw`text-center text-xs text-neutral-400 mt-2`}> {(databaseLimit > 0 && databases.length > 0) &&
{databases.length} of {databaseLimit} databases have been allocated to this <p css={tw`text-sm text-neutral-300 mb-4 sm:mr-6 sm:mb-0`}>
server. {databases.length} of {databaseLimit} databases have been allocated to this
</p> server.
} </p>
{databaseLimit > 0 && databaseLimit !== databases.length && }
<div css={tw`mt-6 flex justify-end`}> {databaseLimit > 0 && databaseLimit !== databases.length &&
<CreateDatabaseButton/> <CreateDatabaseButton css={tw`w-full sm:w-auto`}/>
}
</div> </div>
}
</Can> </Can>
</> </>
</Fade> </Fade>

View file

@ -1,9 +1,9 @@
import React, { useState } from 'react'; 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 { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationStore } from '@/state'; import { ApplicationStore } from '@/state';
import { ServerContext } from '@/state/server'; import { ServerContext } from '@/state/server';
import { ServerDatabase } from '@/api/server/getServerDatabases'; import { ServerDatabase } from '@/api/server/databases/getServerDatabases';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import tw from 'twin.macro'; import tw from 'twin.macro';

View file

@ -45,7 +45,7 @@ const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
</div> </div>
: :
<NavLink <NavLink
to={`${match.url}/${file.isFile ? 'edit/' : ''}#${destination}`} to={`${match.url}${file.isFile ? '/edit' : ''}#${destination}`}
css={tw`flex flex-1 text-neutral-300 no-underline p-3 overflow-hidden truncate`} css={tw`flex flex-1 text-neutral-300 no-underline p-3 overflow-hidden truncate`}
onClick={onRowClick} onClick={onRowClick}
> >

View file

@ -43,7 +43,7 @@ export default ({ match, history }: RouteComponentProps) => {
<> <>
{ {
schedules.length === 0 ? schedules.length === 0 ?
<p css={tw`text-sm text-center text-neutral-400`}> <p css={tw`text-sm text-center text-neutral-300`}>
There are no schedules configured for this server. There are no schedules configured for this server.
</p> </p>
: :

View file

@ -51,7 +51,7 @@ export default () => {
<ServerContentBlock title={'Subusers'}> <ServerContentBlock title={'Subusers'}>
<FlashMessageRender byKey={'users'} css={tw`mb-4`}/> <FlashMessageRender byKey={'users'} css={tw`mb-4`}/>
{!subusers.length ? {!subusers.length ?
<p css={tw`text-center text-sm text-neutral-400`}> <p css={tw`text-center text-sm text-neutral-300`}>
It looks like you don&apos;t have any subusers. It looks like you don&apos;t have any subusers.
</p> </p>
: :

View file

@ -1,5 +1,5 @@
import { action, Action } from 'easy-peasy'; import { action, Action } from 'easy-peasy';
import { ServerDatabase } from '@/api/server/getServerDatabases'; import { ServerDatabase } from '@/api/server/databases/getServerDatabases';
export interface ServerDatabaseStore { export interface ServerDatabaseStore {
data: ServerDatabase[]; data: ServerDatabase[];

View file

@ -26,7 +26,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
*/ */
public function testWithValidIP() 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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1'); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1');
@ -39,7 +39,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
*/ */
public function testValidIPAgainstCIDRRange() 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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15'); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15');
@ -55,7 +55,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
{ {
$this->expectException(AccessDeniedHttpException::class); $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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2'); $this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2');