Skip to content

Commit 9a21584

Browse files
committed
Cleanup mount code; automatically include the mount in the configuration
1 parent 8c6c271 commit 9a21584

File tree

8 files changed

+69
-20
lines changed

8 files changed

+69
-20
lines changed

app/Contracts/Repository/PackRepositoryInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
use Pterodactyl\Models\Pack;
66
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
7-
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
87

9-
interface PackRepositoryInterface extends RepositoryInterface, SearchableInterface
8+
interface PackRepositoryInterface extends RepositoryInterface
109
{
1110
/**
1211
* Return a pack with the associated server models attached to it.

app/Http/Controllers/Admin/PackController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Http\Request;
1313
use Pterodactyl\Models\Pack;
1414
use Prologue\Alerts\AlertsMessageBag;
15+
use Spatie\QueryBuilder\QueryBuilder;
1516
use Pterodactyl\Http\Controllers\Controller;
1617
use Pterodactyl\Services\Packs\ExportPackService;
1718
use Pterodactyl\Services\Packs\PackUpdateService;
@@ -114,7 +115,7 @@ public function __construct(
114115
public function index(Request $request)
115116
{
116117
return view('admin.packs.index', [
117-
'packs' => $this->repository->setSearchTerm($request->input('query'))->paginateWithEggAndServerCount(),
118+
'packs' => $this->repository->paginateWithEggAndServerCount(),
118119
]);
119120
}
120121

app/Models/MountNode.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Pterodactyl\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class MountNode extends Model
8+
{
9+
/**
10+
* @var string
11+
*/
12+
protected $table = 'mount_node';
13+
14+
/**
15+
* @var null
16+
*/
17+
protected $primaryKey = null;
18+
19+
/**
20+
* @var bool
21+
*/
22+
public $incrementing = false;
23+
}

app/Models/MountServer.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Pterodactyl\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class MountServer extends Model
8+
{
9+
/**
10+
* @var string
11+
*/
12+
protected $table = 'mount_server';
13+
14+
/**
15+
* @var null
16+
*/
17+
protected $primaryKey = null;
18+
19+
/**
20+
* @var bool
21+
*/
22+
public $incrementing = false;
23+
}

app/Models/Node.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @property \Carbon\Carbon $updated_at
3434
*
3535
* @property \Pterodactyl\Models\Location $location
36+
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
3637
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
3738
* @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations
3839
*/
@@ -182,6 +183,7 @@ public function getConfiguration()
182183
'bind_port' => $this->daemonSFTP,
183184
],
184185
],
186+
'allowed_mounts' => $this->mounts->pluck('source')->toArray(),
185187
'remote' => route('index'),
186188
];
187189
}
@@ -219,6 +221,14 @@ public function getDecryptedKey(): string
219221
);
220222
}
221223

224+
/**
225+
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
226+
*/
227+
public function mounts()
228+
{
229+
return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id');
230+
}
231+
222232
/**
223233
* Gets the location associated with a node.
224234
*

app/Models/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ public function backups()
367367
/**
368368
* Returns all mounts that have this server has mounted.
369369
*
370-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
370+
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
371371
*/
372372
public function mounts()
373373
{
374-
return $this->belongsToMany(Mount::class);
374+
return $this->hasManyThrough(Mount::class, MountServer::class, 'server_id', 'id', 'id', 'mount_id');
375375
}
376376
}

app/Repositories/Eloquent/PackRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function loadServerData(Pack $pack, bool $refresh = false): Pack
4747
public function paginateWithEggAndServerCount(): LengthAwarePaginator
4848
{
4949
return $this->getBuilder()->with('egg')->withCount('servers')
50-
->search($this->getSearchTerm())
5150
->paginate(50, $this->getColumns());
5251
}
5352
}

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Pterodactyl\Services\Servers;
1111

12+
use Pterodactyl\Models\Mount;
1213
use Pterodactyl\Models\Server;
1314
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
1415

@@ -66,22 +67,9 @@ public function handle(Server $server, bool $legacy = false): array
6667
*
6768
* @param \Pterodactyl\Models\Server $server
6869
* @return array
69-
*
70-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
7170
*/
7271
protected function returnCurrentFormat(Server $server)
7372
{
74-
$mounts = $server->mounts;
75-
foreach ($mounts as $mount) {
76-
unset($mount->id);
77-
unset($mount->uuid);
78-
unset($mount->name);
79-
unset($mount->description);
80-
$mount->read_only = $mount->read_only == 1;
81-
unset($mount->user_mountable);
82-
unset($mount->pivot);
83-
}
84-
8573
return [
8674
'uuid' => $server->uuid,
8775
'suspended' => (bool) $server->suspended,
@@ -108,7 +96,13 @@ protected function returnCurrentFormat(Server $server)
10896
],
10997
'mappings' => $server->getAllocationMappings(),
11098
],
111-
'mounts' => $mounts,
99+
'mounts' => $server->mounts->map(function (Mount $mount) {
100+
return [
101+
'source' => $mount->source,
102+
'target' => $mount->target,
103+
'read_only' => $mount->read_only,
104+
];
105+
}),
112106
];
113107
}
114108

0 commit comments

Comments
 (0)