Add the ability to create mounts
This commit is contained in:
parent
a750362e5a
commit
a4af8ec977
|
@ -1,26 +1,45 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Admin\Mounts;
|
namespace Pterodactyl\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
|
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
|
||||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
use Pterodactyl\Services\Mounts\MountCreationService;
|
||||||
|
|
||||||
class MountController extends Controller
|
class MountController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \Prologue\Alerts\AlertsMessageBag
|
||||||
|
*/
|
||||||
|
protected $alert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Locations\LocationCreationService
|
||||||
|
*/
|
||||||
|
protected $creationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MountController constructor.
|
* MountController constructor.
|
||||||
*
|
*
|
||||||
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
|
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
MountRepository $repository
|
AlertsMessageBag $alert,
|
||||||
|
MountRepository $repository,
|
||||||
|
MountCreationService $creationService
|
||||||
) {
|
) {
|
||||||
|
$this->alert = $alert;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
$this->creationService = $creationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,4 +53,21 @@ class MountController extends Controller
|
||||||
'mounts' => $this->repository->getAllWithDetails(),
|
'mounts' => $this->repository->getAllWithDetails(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle request to create new mount.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Admin\MountFormRequest $request
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function create(MountFormRequest $request)
|
||||||
|
{
|
||||||
|
$mount = $this->creationService->handle($request->normalize());
|
||||||
|
$this->alert->success('Mount was created successfully.')->flash();
|
||||||
|
|
||||||
|
//return redirect()->route('admin.mounts.view', $mount->id);
|
||||||
|
return redirect()->route('admin.mounts');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Pterodactyl - Panel
|
||||||
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||||
|
*
|
||||||
|
* This software is licensed under the terms of the MIT license.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Requests\Admin;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Mount;
|
||||||
|
|
||||||
|
class MountFormRequest extends AdminFormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Setup the validation rules to use for these requests.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
if ($this->method() === 'PATCH') {
|
||||||
|
return Mount::getRulesForUpdate($this->route()->parameter('mount')->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Mount::getRules();
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,7 +52,7 @@ class Mount extends Model
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static $validationRules = [
|
public static $validationRules = [
|
||||||
'id' => 'required|string|size:36|unique:mounts,id',
|
// 'id' => 'required|string|size:36|unique:mounts,id',
|
||||||
'name' => 'required|string|min:2|max:64|unique:mounts,name',
|
'name' => 'required|string|min:2|max:64|unique:mounts,name',
|
||||||
'description' => 'nullable|string|max:255',
|
'description' => 'nullable|string|max:255',
|
||||||
'source' => 'required|string',
|
'source' => 'required|string',
|
||||||
|
@ -61,6 +61,13 @@ class Mount extends Model
|
||||||
'user_mountable' => 'sometimes|boolean',
|
'user_mountable' => 'sometimes|boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable timestamps on this model.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all eggs that have this mount assigned.
|
* Returns all eggs that have this mount assigned.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Services\Mounts;
|
||||||
|
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
|
||||||
|
class MountCreationService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MountCreationService constructor.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(MountRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new mount.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return \Pterodactyl\Models\Mount
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
|
*/
|
||||||
|
public function handle(array $data)
|
||||||
|
{
|
||||||
|
return $this->repository->create(array_merge($data, [
|
||||||
|
'id' => Uuid::uuid4()->toString(),
|
||||||
|
]), true, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,13 +78,61 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label for="pName" class="form-label">Name</label>
|
<label for="pName" class="form-label">Name</label>
|
||||||
<input type="text" id="pName" name="name" class="form-control" />
|
<input type="text" id="pName" name="name" class="form-control" />
|
||||||
<p class="text-muted small">Thiccc boi name used to separate this mount from another!</p>
|
<p class="text-muted small">Unique name used to separate this mount from another.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label for="pDescription" class="form-label">Description</label>
|
<label for="pDescription" class="form-label">Description</label>
|
||||||
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
|
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
|
||||||
<p class="text-muted small">A longer description of this mount. Must be less than 255 characters.</p>
|
<p class="text-muted small">A longer description for this mount, must be less than 255 characters.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="pSource" class="form-label">Source</label>
|
||||||
|
<input type="text" id="pSource" name="source" class="form-control" />
|
||||||
|
<p class="text-muted small">File path on the host system to mount to a container.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="pTarget" class="form-label">Target</label>
|
||||||
|
<input type="text" id="pTarget" name="target" class="form-control" />
|
||||||
|
<p class="text-muted small">Where the mount will be accessible inside a container.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="form-label">Read Only</label>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="radio radio-success radio-inline">
|
||||||
|
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" checked>
|
||||||
|
<label for="pReadOnlyFalse">False</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="radio radio-warning radio-inline">
|
||||||
|
<input type="radio" id="pReadOnly" name="read_only" value="1">
|
||||||
|
<label for="pReadOnly">True</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-muted small">Is the mount read only inside the container?</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="form-label">User Mountable</label>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="radio radio-success radio-inline">
|
||||||
|
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" checked>
|
||||||
|
<label for="pUserMountableFalse">False</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="radio radio-warning radio-inline">
|
||||||
|
<input type="radio" id="pUserMountable" name="user_mountable" value="1">
|
||||||
|
<label for="pUserMountable">True</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-muted small">Should users be able to mount this themselves?</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -175,6 +175,8 @@ Route::group(['prefix' => 'nodes'], function () {
|
||||||
*/
|
*/
|
||||||
Route::group(['prefix' => 'mounts'], function () {
|
Route::group(['prefix' => 'mounts'], function () {
|
||||||
Route::get('/', 'MountController@index')->name('admin.mounts');
|
Route::get('/', 'MountController@index')->name('admin.mounts');
|
||||||
|
|
||||||
|
Route::post('/', 'MountController@create');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue