forked from Alex/Pterodactyl-Panel
Push beginning of DB deletion stuff
This commit is contained in:
parent
c28e9c1ab7
commit
9be2aa4ca9
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Response;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Transformers\Api\Client\DatabaseTransformer;
|
use Pterodactyl\Transformers\Api\Client\DatabaseTransformer;
|
||||||
|
use Pterodactyl\Services\Databases\DatabaseManagementService;
|
||||||
use Pterodactyl\Services\Databases\DeployServerDatabaseService;
|
use Pterodactyl\Services\Databases\DeployServerDatabaseService;
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Databases\GetDatabasesRequest;
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Databases\GetDatabasesRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Databases\StoreDatabaseRequest;
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Databases\StoreDatabaseRequest;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Databases\DeleteDatabaseRequest;
|
||||||
|
|
||||||
class DatabaseController extends ClientApiController
|
class DatabaseController extends ClientApiController
|
||||||
{
|
{
|
||||||
@ -22,18 +25,28 @@ class DatabaseController extends ClientApiController
|
|||||||
*/
|
*/
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
|
||||||
|
*/
|
||||||
|
private $managementService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DatabaseController constructor.
|
* DatabaseController constructor.
|
||||||
*
|
*
|
||||||
|
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $managementService
|
||||||
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $repository
|
||||||
* @param \Pterodactyl\Services\Databases\DeployServerDatabaseService $deployDatabaseService
|
* @param \Pterodactyl\Services\Databases\DeployServerDatabaseService $deployDatabaseService
|
||||||
*/
|
*/
|
||||||
public function __construct(DatabaseRepositoryInterface $repository, DeployServerDatabaseService $deployDatabaseService)
|
public function __construct(
|
||||||
{
|
DatabaseManagementService $managementService,
|
||||||
|
DatabaseRepositoryInterface $repository,
|
||||||
|
DeployServerDatabaseService $deployDatabaseService
|
||||||
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->deployDatabaseService = $deployDatabaseService;
|
$this->deployDatabaseService = $deployDatabaseService;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
$this->managementService = $managementService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,4 +79,16 @@ class DatabaseController extends ClientApiController
|
|||||||
->transformWith($this->getTransformer(DatabaseTransformer::class))
|
->transformWith($this->getTransformer(DatabaseTransformer::class))
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Databases\DeleteDatabaseRequest $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*
|
||||||
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function delete(DeleteDatabaseRequest $request): Response
|
||||||
|
{
|
||||||
|
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||||
|
// $this->managementService->delete($request->input('database'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ namespace Pterodactyl\Http\Middleware\Api\Client;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
|
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||||
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
|
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
|
||||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||||
|
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||||
|
|
||||||
class SubstituteClientApiBindings extends ApiSubstituteBindings
|
class SubstituteClientApiBindings extends ApiSubstituteBindings
|
||||||
{
|
{
|
||||||
@ -34,6 +36,20 @@ class SubstituteClientApiBindings extends ApiSubstituteBindings
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->router->bind('database', function ($value) use ($request) {
|
||||||
|
try {
|
||||||
|
$id = Container::getInstance()->make(HashidsInterface::class)->decodeFirst($value);
|
||||||
|
|
||||||
|
return Container::getInstance()->make(DatabaseRepositoryInterface::class)->findFirstWhere([
|
||||||
|
['id', '=', $id],
|
||||||
|
]);
|
||||||
|
} catch (RecordNotFoundException $exception) {
|
||||||
|
$request->attributes->set('is_missing_model', true);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return parent::handle($request, $next);
|
return parent::handle($request, $next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,10 +126,6 @@ abstract class ApplicationApiRequest extends FormRequest
|
|||||||
*
|
*
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function passesAuthorization()
|
protected function passesAuthorization()
|
||||||
{
|
{
|
||||||
// If we have already validated we do not need to call this function
|
// If we have already validated we do not need to call this function
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Databases;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Server;
|
||||||
|
use Pterodactyl\Models\Database;
|
||||||
|
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||||
|
|
||||||
|
class DeleteDatabaseRequest extends ClientApiRequest implements ClientPermissionsRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function permission(): string
|
||||||
|
{
|
||||||
|
return 'delete-database';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the provided database even belongs to this server instance.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function resourceExists(): bool
|
||||||
|
{
|
||||||
|
$server = $this->getModel(Server::class);
|
||||||
|
$database = $this->getModel(Database::class);
|
||||||
|
|
||||||
|
return $database->server_id === $server->id;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Transformers\Api\Client;
|
|||||||
use Pterodactyl\Models\Database;
|
use Pterodactyl\Models\Database;
|
||||||
use League\Fractal\Resource\Item;
|
use League\Fractal\Resource\Item;
|
||||||
use Illuminate\Contracts\Encryption\Encrypter;
|
use Illuminate\Contracts\Encryption\Encrypter;
|
||||||
|
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||||
|
|
||||||
class DatabaseTransformer extends BaseClientTransformer
|
class DatabaseTransformer extends BaseClientTransformer
|
||||||
{
|
{
|
||||||
@ -15,14 +16,21 @@ class DatabaseTransformer extends BaseClientTransformer
|
|||||||
*/
|
*/
|
||||||
private $encrypter;
|
private $encrypter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Contracts\Extensions\HashidsInterface
|
||||||
|
*/
|
||||||
|
private $hashids;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dependency injection.
|
* Handle dependency injection.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
||||||
|
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
|
||||||
*/
|
*/
|
||||||
public function handle(Encrypter $encrypter)
|
public function handle(Encrypter $encrypter, HashidsInterface $hashids)
|
||||||
{
|
{
|
||||||
$this->encrypter = $encrypter;
|
$this->encrypter = $encrypter;
|
||||||
|
$this->hashids = $hashids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +50,7 @@ class DatabaseTransformer extends BaseClientTransformer
|
|||||||
$model->loadMissing('host');
|
$model->loadMissing('host');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'id' => $this->hashids->encode($model->id),
|
||||||
'host' => [
|
'host' => [
|
||||||
'address' => $model->getRelation('host')->host,
|
'address' => $model->getRelation('host')->host,
|
||||||
'port' => $model->getRelation('host')->port,
|
'port' => $model->getRelation('host')->port,
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div class="content-box mb-6" v-for="database in databases" :key="database.name">
|
<div class="content-box mb-6 hover:border-grey" v-for="database in databases" :key="database.name">
|
||||||
<div class="flex items-center text-grey-darker">
|
<div class="flex items-center text-grey-darker">
|
||||||
<database-icon class="flex-none text-green"></database-icon>
|
<database-icon class="flex-none text-green"></database-icon>
|
||||||
<div class="flex-1 px-4">
|
<div class="flex-1 px-4">
|
||||||
@ -38,11 +38,16 @@
|
|||||||
<p class="uppercase text-xs text-grey pb-1 select-none">Server</p>
|
<p class="uppercase text-xs text-grey pb-1 select-none">Server</p>
|
||||||
<p><code class="text-sm">{{database.host.address}}:{{database.host.port}}</code></p>
|
<p><code class="text-sm">{{database.host.address}}:{{database.host.port}}</code></p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex-none px-4">
|
||||||
|
<button class="btn btn-xs btn-secondary btn-red" v-on:click="deleteDatabase(database)">
|
||||||
|
<trash2-icon class="w-3 h-3 mx-1"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<button class="btn btn-blue btn-lg" v-on:click="showCreateModal = true">Create new database</button>
|
<div>
|
||||||
</div>
|
<button class="btn btn-blue btn-lg" v-on:click="showCreateModal = true">Create new database</button>
|
||||||
</div>
|
</div>
|
||||||
<modal :show="showCreateModal" v-on:close="showCreateModal = false">
|
<modal :show="showCreateModal" v-on:close="showCreateModal = false">
|
||||||
<create-database-modal
|
<create-database-modal
|
||||||
@ -55,14 +60,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { DatabaseIcon, LockIcon } from 'vue-feather-icons';
|
import { DatabaseIcon, LockIcon, Trash2Icon } from 'vue-feather-icons';
|
||||||
import map from 'lodash/map';
|
import map from 'lodash/map';
|
||||||
import Modal from '../../core/Modal';
|
import Modal from '../../core/Modal';
|
||||||
import CreateDatabaseModal from '../components/CreateDatabaseModal';
|
import CreateDatabaseModal from '../components/CreateDatabaseModal';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'databases-page',
|
name: 'databases-page',
|
||||||
components: {CreateDatabaseModal, Modal, DatabaseIcon, LockIcon },
|
components: {CreateDatabaseModal, Modal, DatabaseIcon, LockIcon, Trash2Icon },
|
||||||
|
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
@ -136,6 +141,15 @@
|
|||||||
|
|
||||||
database.showPassword = !database.showPassword;
|
database.showPassword = !database.showPassword;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
deleteDatabase: function (database) {
|
||||||
|
window.axios.delete(this.route('api.client.servers.databases.delete', {
|
||||||
|
server: this.$route.params.id,
|
||||||
|
database: database.id,
|
||||||
|
}))
|
||||||
|
.then(response => console.log(response))
|
||||||
|
.catch(err => console.error(err.response));
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,6 @@
|
|||||||
.btn {
|
.btn {
|
||||||
@apply .rounded .p-2;
|
@apply .rounded .p-2;
|
||||||
|
transition: all 100ms ease-in-out;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button Colors
|
* Button Colors
|
||||||
@ -21,7 +22,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.btn-red {
|
&.btn-red {
|
||||||
@apply .bg-red .border-red-dark .border .text-white;
|
&:not(.btn-secondary) {
|
||||||
|
@apply .bg-red .border-red-dark .border .text-white;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover:enabled {
|
&:hover:enabled {
|
||||||
@apply .bg-red-dark .border-red-darker;
|
@apply .bg-red-dark .border-red-darker;
|
||||||
@ -34,6 +37,10 @@
|
|||||||
&:hover:enabled {
|
&:hover:enabled {
|
||||||
@apply .border-grey .text-grey-darker;
|
@apply .border-grey .text-grey-darker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.btn-red:hover:enabled {
|
||||||
|
@apply .bg-red-dark .border-red-darker .text-white;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,6 +58,10 @@
|
|||||||
@apply .px-6 .py-3 .uppercase .tracking-wide .text-sm;
|
@apply .px-6 .py-3 .uppercase .tracking-wide .text-sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.btn-xs {
|
||||||
|
@apply .py-2 .px-2 .uppercase .text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
&:disabled, &.disabled {
|
&:disabled, &.disabled {
|
||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
@ -38,5 +38,6 @@ Route::group(['prefix' => '/servers/{server}', 'middleware' => [AuthenticateClie
|
|||||||
Route::group(['prefix' => '/databases'], function () {
|
Route::group(['prefix' => '/databases'], function () {
|
||||||
Route::get('/', 'Servers\DatabaseController@index')->name('api.client.servers.databases');
|
Route::get('/', 'Servers\DatabaseController@index')->name('api.client.servers.databases');
|
||||||
Route::post('/', 'Servers\DatabaseController@store');
|
Route::post('/', 'Servers\DatabaseController@store');
|
||||||
|
Route::delete('/{database}', 'Servers\DatabaseController@delete')->name('api.client.servers.databases.delete');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user