From a4af8ec977293f2bb0eb62cc18553c246d955694 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 20 May 2020 18:55:59 -0600 Subject: [PATCH] Add the ability to create mounts --- .../Controllers/Admin/MountController.php | 40 +++++++++++++- app/Http/Requests/Admin/MountFormRequest.php | 29 +++++++++++ app/Models/Mount.php | 9 +++- app/Services/Mounts/MountCreationService.php | 40 ++++++++++++++ resources/views/admin/mounts/index.blade.php | 52 ++++++++++++++++++- routes/admin.php | 2 + 6 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 app/Http/Requests/Admin/MountFormRequest.php create mode 100644 app/Services/Mounts/MountCreationService.php diff --git a/app/Http/Controllers/Admin/MountController.php b/app/Http/Controllers/Admin/MountController.php index 977dd558c..c8dc3e647 100644 --- a/app/Http/Controllers/Admin/MountController.php +++ b/app/Http/Controllers/Admin/MountController.php @@ -1,26 +1,45 @@ alert = $alert; $this->repository = $repository; + $this->creationService = $creationService; } /** @@ -34,4 +53,21 @@ class MountController extends Controller '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'); + } } diff --git a/app/Http/Requests/Admin/MountFormRequest.php b/app/Http/Requests/Admin/MountFormRequest.php new file mode 100644 index 000000000..b6647b16b --- /dev/null +++ b/app/Http/Requests/Admin/MountFormRequest.php @@ -0,0 +1,29 @@ +. + * + * 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(); + } +} diff --git a/app/Models/Mount.php b/app/Models/Mount.php index 6c3e699fe..c2eb1f1ce 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -52,7 +52,7 @@ class Mount extends Model * @var string */ 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', 'description' => 'nullable|string|max:255', 'source' => 'required|string', @@ -61,6 +61,13 @@ class Mount extends Model 'user_mountable' => 'sometimes|boolean', ]; + /** + * Disable timestamps on this model. + * + * @var bool + */ + public $timestamps = false; + /** * Returns all eggs that have this mount assigned. * diff --git a/app/Services/Mounts/MountCreationService.php b/app/Services/Mounts/MountCreationService.php new file mode 100644 index 000000000..ac6a8e00f --- /dev/null +++ b/app/Services/Mounts/MountCreationService.php @@ -0,0 +1,40 @@ +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); + } +} diff --git a/resources/views/admin/mounts/index.blade.php b/resources/views/admin/mounts/index.blade.php index 6b9364b91..765c62fbe 100644 --- a/resources/views/admin/mounts/index.blade.php +++ b/resources/views/admin/mounts/index.blade.php @@ -78,13 +78,61 @@
-

Thiccc boi name used to separate this mount from another!

+

Unique name used to separate this mount from another.

-

A longer description of this mount. Must be less than 255 characters.

+

A longer description for this mount, must be less than 255 characters.

+
+ +
+ + +

File path on the host system to mount to a container.

+
+ +
+ + +

Where the mount will be accessible inside a container.

+
+ +
+ + +
+
+ + +
+ +
+ + +
+
+ +

Is the mount read only inside the container?

+
+ +
+ + +
+
+ + +
+ +
+ + +
+
+ +

Should users be able to mount this themselves?

diff --git a/routes/admin.php b/routes/admin.php index 7419ef574..f1d95cc10 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -175,6 +175,8 @@ Route::group(['prefix' => 'nodes'], function () { */ Route::group(['prefix' => 'mounts'], function () { Route::get('/', 'MountController@index')->name('admin.mounts'); + + Route::post('/', 'MountController@create'); }); /*