Skip to content

Commit a4af8ec

Browse files
committed
Add the ability to create mounts
1 parent a750362 commit a4af8ec

File tree

6 files changed

+167
-5
lines changed

6 files changed

+167
-5
lines changed

app/Http/Controllers/Admin/MountController.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
<?php
22

3-
namespace Pterodactyl\Http\Controllers\Admin\Mounts;
3+
namespace Pterodactyl\Http\Controllers\Admin;
44

5+
use Prologue\Alerts\AlertsMessageBag;
56
use Pterodactyl\Http\Controllers\Controller;
7+
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
68
use Pterodactyl\Repositories\Eloquent\MountRepository;
9+
use Pterodactyl\Services\Mounts\MountCreationService;
710

811
class MountController extends Controller
912
{
13+
/**
14+
* @var \Prologue\Alerts\AlertsMessageBag
15+
*/
16+
protected $alert;
17+
1018
/**
1119
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
1220
*/
1321
protected $repository;
1422

23+
/**
24+
* @var \Pterodactyl\Services\Locations\LocationCreationService
25+
*/
26+
protected $creationService;
27+
1528
/**
1629
* MountController constructor.
1730
*
31+
* @param \Prologue\Alerts\AlertsMessageBag $alert
1832
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
33+
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
1934
*/
2035
public function __construct(
21-
MountRepository $repository
36+
AlertsMessageBag $alert,
37+
MountRepository $repository,
38+
MountCreationService $creationService
2239
) {
40+
$this->alert = $alert;
2341
$this->repository = $repository;
42+
$this->creationService = $creationService;
2443
}
2544

2645
/**
@@ -34,4 +53,21 @@ public function index()
3453
'mounts' => $this->repository->getAllWithDetails(),
3554
]);
3655
}
56+
57+
/**
58+
* Handle request to create new mount.
59+
*
60+
* @param \Pterodactyl\Http\Requests\Admin\MountFormRequest $request
61+
* @return \Illuminate\Http\RedirectResponse
62+
*
63+
* @throws \Throwable
64+
*/
65+
public function create(MountFormRequest $request)
66+
{
67+
$mount = $this->creationService->handle($request->normalize());
68+
$this->alert->success('Mount was created successfully.')->flash();
69+
70+
//return redirect()->route('admin.mounts.view', $mount->id);
71+
return redirect()->route('admin.mounts');
72+
}
3773
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* This software is licensed under the terms of the MIT license.
7+
* https://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Pterodactyl\Http\Requests\Admin;
11+
12+
use Pterodactyl\Models\Mount;
13+
14+
class MountFormRequest extends AdminFormRequest
15+
{
16+
/**
17+
* Setup the validation rules to use for these requests.
18+
*
19+
* @return array
20+
*/
21+
public function rules()
22+
{
23+
if ($this->method() === 'PATCH') {
24+
return Mount::getRulesForUpdate($this->route()->parameter('mount')->id);
25+
}
26+
27+
return Mount::getRules();
28+
}
29+
}

app/Models/Mount.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Mount extends Model
5252
* @var string
5353
*/
5454
public static $validationRules = [
55-
'id' => 'required|string|size:36|unique:mounts,id',
55+
// 'id' => 'required|string|size:36|unique:mounts,id',
5656
'name' => 'required|string|min:2|max:64|unique:mounts,name',
5757
'description' => 'nullable|string|max:255',
5858
'source' => 'required|string',
@@ -61,6 +61,13 @@ class Mount extends Model
6161
'user_mountable' => 'sometimes|boolean',
6262
];
6363

64+
/**
65+
* Disable timestamps on this model.
66+
*
67+
* @var bool
68+
*/
69+
public $timestamps = false;
70+
6471
/**
6572
* Returns all eggs that have this mount assigned.
6673
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Pterodactyl\Services\Mounts;
4+
5+
use Ramsey\Uuid\Uuid;
6+
use Pterodactyl\Repositories\Eloquent\MountRepository;
7+
8+
class MountCreationService
9+
{
10+
/**
11+
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
12+
*/
13+
protected $repository;
14+
15+
/**
16+
* MountCreationService constructor.
17+
*
18+
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
19+
*/
20+
public function __construct(MountRepository $repository)
21+
{
22+
$this->repository = $repository;
23+
}
24+
25+
/**
26+
* Create a new mount.
27+
*
28+
* @param array $data
29+
* @return \Pterodactyl\Models\Mount
30+
*
31+
* @throws \Exception
32+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
33+
*/
34+
public function handle(array $data)
35+
{
36+
return $this->repository->create(array_merge($data, [
37+
'id' => Uuid::uuid4()->toString(),
38+
]), true, true);
39+
}
40+
}

resources/views/admin/mounts/index.blade.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,61 @@
7878
<div class="col-md-12">
7979
<label for="pName" class="form-label">Name</label>
8080
<input type="text" id="pName" name="name" class="form-control" />
81-
<p class="text-muted small">Thiccc boi name used to separate this mount from another!</p>
81+
<p class="text-muted small">Unique name used to separate this mount from another.</p>
8282
</div>
8383

8484
<div class="col-md-12">
8585
<label for="pDescription" class="form-label">Description</label>
8686
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
87-
<p class="text-muted small">A longer description of this mount. Must be less than 255 characters.</p>
87+
<p class="text-muted small">A longer description for this mount, must be less than 255 characters.</p>
88+
</div>
89+
90+
<div class="col-md-6">
91+
<label for="pSource" class="form-label">Source</label>
92+
<input type="text" id="pSource" name="source" class="form-control" />
93+
<p class="text-muted small">File path on the host system to mount to a container.</p>
94+
</div>
95+
96+
<div class="col-md-6">
97+
<label for="pTarget" class="form-label">Target</label>
98+
<input type="text" id="pTarget" name="target" class="form-control" />
99+
<p class="text-muted small">Where the mount will be accessible inside a container.</p>
100+
</div>
101+
102+
<div class="col-md-6">
103+
<label class="form-label">Read Only</label>
104+
105+
<div>
106+
<div class="radio radio-success radio-inline">
107+
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" checked>
108+
<label for="pReadOnlyFalse">False</label>
109+
</div>
110+
111+
<div class="radio radio-warning radio-inline">
112+
<input type="radio" id="pReadOnly" name="read_only" value="1">
113+
<label for="pReadOnly">True</label>
114+
</div>
115+
</div>
116+
117+
<p class="text-muted small">Is the mount read only inside the container?</p>
118+
</div>
119+
120+
<div class="col-md-6">
121+
<label class="form-label">User Mountable</label>
122+
123+
<div>
124+
<div class="radio radio-success radio-inline">
125+
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" checked>
126+
<label for="pUserMountableFalse">False</label>
127+
</div>
128+
129+
<div class="radio radio-warning radio-inline">
130+
<input type="radio" id="pUserMountable" name="user_mountable" value="1">
131+
<label for="pUserMountable">True</label>
132+
</div>
133+
</div>
134+
135+
<p class="text-muted small">Should users be able to mount this themselves?</p>
88136
</div>
89137
</div>
90138
</div>

routes/admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
*/
176176
Route::group(['prefix' => 'mounts'], function () {
177177
Route::get('/', 'MountController@index')->name('admin.mounts');
178+
179+
Route::post('/', 'MountController@create');
178180
});
179181

180182
/*

0 commit comments

Comments
 (0)