Skip to content

Commit ae671e6

Browse files
committed
Begin updating UI
1 parent 493c588 commit ae671e6

File tree

22 files changed

+179
-99
lines changed

22 files changed

+179
-99
lines changed

.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ QUEUE_HIGH=high
3232
QUEUE_STANDARD=standard
3333
QUEUE_LOW=low
3434

35-
SQS_KEY=aws-public
36-
SQS_SECRET=aws-secret
37-
SQS_QUEUE_PREFIX=aws-queue-prefix
35+
SERVICE_AUTHOR=undefined@unknown-author.com

app/Console/Commands/Environment/AppSettingsCommand.php

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

1010
namespace Pterodactyl\Console\Commands\Environment;
1111

12-
use Ramsey\Uuid\Uuid;
1312
use Illuminate\Console\Command;
1413
use Illuminate\Contracts\Console\Kernel;
1514
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
@@ -38,6 +37,7 @@ class AppSettingsCommand extends Command
3837
* @var string
3938
*/
4039
protected $signature = 'p:environment:setup
40+
{--author= : The email that services created on this instance should be linked to.}
4141
{--url= : The URL that this Panel is running on.}
4242
{--timezone= : The timezone to use for Panel times.}
4343
{--cache= : The cache driver backend to use.}
@@ -72,9 +72,10 @@ public function __construct(ConfigRepository $config, Kernel $command)
7272
*/
7373
public function handle()
7474
{
75-
if (is_null($this->config->get('pterodactyl.service.author'))) {
76-
$this->variables['SERVICE_AUTHOR'] = Uuid::uuid4()->toString();
77-
}
75+
$this->output->comment(trans('command/messages.environment.app.author_help'));
76+
$this->variables['SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(
77+
trans('command/messages.environment.app.author'), $this->config->get('pterodactyl.service.author', 'undefined@unknown-author.com')
78+
);
7879

7980
$this->output->comment(trans('command/messages.environment.app.app_url_help'));
8081
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(

app/Contracts/Repository/ServiceRepositoryInterface.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12+
use Pterodactyl\Models\Service;
13+
use Illuminate\Support\Collection;
14+
1215
interface ServiceRepositoryInterface extends RepositoryInterface
1316
{
1417
/**
@@ -17,13 +20,21 @@ interface ServiceRepositoryInterface extends RepositoryInterface
1720
* @param int $id
1821
* @return \Illuminate\Support\Collection
1922
*/
20-
public function getWithOptions($id = null);
23+
public function getWithOptions(int $id = null): Collection;
24+
25+
/**
26+
* Return a service or all services and the count of options, packs, and servers for that service.
27+
*
28+
* @param int|null $id
29+
* @return \Illuminate\Support\Collection
30+
*/
31+
public function getWithCounts(int $id = null): Collection;
2132

2233
/**
2334
* Return a service along with its associated options and the servers relation on those options.
2435
*
2536
* @param int $id
2637
* @return mixed
2738
*/
28-
public function getWithOptionServers($id);
39+
public function getWithOptionServers(int $id): Service;
2940
}

app/Http/Controllers/Admin/ServiceController.php

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

1010
namespace Pterodactyl\Http\Controllers\Admin;
1111

12+
use Illuminate\View\View;
1213
use Pterodactyl\Models\Service;
14+
use Illuminate\Http\RedirectResponse;
1315
use Prologue\Alerts\AlertsMessageBag;
1416
use Pterodactyl\Http\Controllers\Controller;
1517
use Pterodactyl\Services\Services\ServiceUpdateService;
@@ -46,6 +48,15 @@ class ServiceController extends Controller
4648
*/
4749
protected $updateService;
4850

51+
/**
52+
* ServiceController constructor.
53+
*
54+
* @param \Prologue\Alerts\AlertsMessageBag $alert
55+
* @param \Pterodactyl\Services\Services\ServiceCreationService $creationService
56+
* @param \Pterodactyl\Services\Services\ServiceDeletionService $deletionService
57+
* @param \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface $repository
58+
* @param \Pterodactyl\Services\Services\ServiceUpdateService $updateService
59+
*/
4960
public function __construct(
5061
AlertsMessageBag $alert,
5162
ServiceCreationService $creationService,
@@ -65,10 +76,10 @@ public function __construct(
6576
*
6677
* @return \Illuminate\View\View
6778
*/
68-
public function index()
79+
public function index(): View
6980
{
7081
return view('admin.services.index', [
71-
'services' => $this->repository->getWithOptions(),
82+
'services' => $this->repository->getWithCounts(),
7283
]);
7384
}
7485

@@ -77,7 +88,7 @@ public function index()
7788
*
7889
* @return \Illuminate\View\View
7990
*/
80-
public function create()
91+
public function create(): View
8192
{
8293
return view('admin.services.new');
8394
}
@@ -88,7 +99,7 @@ public function create()
8899
* @param int $service
89100
* @return \Illuminate\View\View
90101
*/
91-
public function view($service)
102+
public function view(int $service): View
92103
{
93104
return view('admin.services.view', [
94105
'service' => $this->repository->getWithOptionServers($service),
@@ -101,7 +112,7 @@ public function view($service)
101112
* @param \Pterodactyl\Models\Service $service
102113
* @return \Illuminate\View\View
103114
*/
104-
public function viewFunctions(Service $service)
115+
public function viewFunctions(Service $service): View
105116
{
106117
return view('admin.services.functions', ['service' => $service]);
107118
}
@@ -114,7 +125,7 @@ public function viewFunctions(Service $service)
114125
*
115126
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
116127
*/
117-
public function store(ServiceFormRequest $request)
128+
public function store(ServiceFormRequest $request): RedirectResponse
118129
{
119130
$service = $this->creationService->handle($request->normalize());
120131
$this->alert->success(trans('admin/services.notices.service_created', ['name' => $service->name]))->flash();
@@ -132,7 +143,7 @@ public function store(ServiceFormRequest $request)
132143
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
133144
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
134145
*/
135-
public function update(ServiceFormRequest $request, Service $service)
146+
public function update(ServiceFormRequest $request, Service $service): RedirectResponse
136147
{
137148
$this->updateService->handle($service->id, $request->normalize());
138149
$this->alert->success(trans('admin/services.notices.service_updated'))->flash();
@@ -150,7 +161,7 @@ public function update(ServiceFormRequest $request, Service $service)
150161
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
151162
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
152163
*/
153-
public function updateFunctions(ServiceFunctionsFormRequest $request, Service $service)
164+
public function updateFunctions(ServiceFunctionsFormRequest $request, Service $service): RedirectResponse
154165
{
155166
$this->updateService->handle($service->id, $request->normalize());
156167
$this->alert->success(trans('admin/services.notices.functions_updated'))->flash();
@@ -166,7 +177,7 @@ public function updateFunctions(ServiceFunctionsFormRequest $request, Service $s
166177
*
167178
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
168179
*/
169-
public function destroy(Service $service)
180+
public function destroy(Service $service): RedirectResponse
170181
{
171182
$this->deletionService->handle($service->id);
172183
$this->alert->success(trans('admin/services.notices.service_deleted'))->flash();

app/Http/Requests/Admin/AdminFormRequest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313

1414
abstract class AdminFormRequest extends FormRequest
1515
{
16-
abstract public function rules();
16+
/**
17+
* The rules to apply to the incoming form request.
18+
*
19+
* @return array
20+
*/
21+
abstract public function rules(): array;
1722

1823
/**
1924
* Determine if the user is an admin and has permission to access this
2025
* form controller in the first place.
2126
*
2227
* @return bool
2328
*/
24-
public function authorize()
29+
public function authorize(): bool
2530
{
2631
if (is_null($this->user())) {
2732
return false;
@@ -37,7 +42,7 @@ public function authorize()
3742
* @param array $only
3843
* @return array
3944
*/
40-
public function normalize($only = [])
45+
public function normalize($only = []): array
4146
{
4247
return array_merge(
4348
$this->only($only),

app/Http/Requests/Admin/Service/ServiceFormRequest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@ class ServiceFormRequest extends AdminFormRequest
1616
/**
1717
* @return array
1818
*/
19-
public function rules()
19+
public function rules(): array
2020
{
21-
$rules = [
21+
return [
2222
'name' => 'required|string|min:1|max:255',
2323
'description' => 'required|nullable|string',
24-
'folder' => 'required|regex:/^[\w.-]{1,50}$/|unique:services,folder',
2524
'startup' => 'required|nullable|string',
2625
];
27-
28-
if ($this->method() === 'PATCH') {
29-
$service = $this->route()->parameter('service');
30-
$rules['folder'] = $rules['folder'] . ',' . $service->id;
31-
32-
return $rules;
33-
}
34-
35-
return $rules;
3626
}
3727
}

app/Models/Service.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ class Service extends Model implements CleansAttributes, ValidableContract
3131
*
3232
* @var array
3333
*/
34-
protected $fillable = ['name', 'author', 'description', 'folder', 'startup', 'index_file'];
34+
protected $fillable = [
35+
'name',
36+
'description',
37+
'startup',
38+
'index_file',
39+
];
3540

3641
/**
3742
* @var array
@@ -40,7 +45,6 @@ class Service extends Model implements CleansAttributes, ValidableContract
4045
'author' => 'required',
4146
'name' => 'required',
4247
'description' => 'sometimes',
43-
'folder' => 'required',
4448
'startup' => 'sometimes',
4549
'index_file' => 'required',
4650
];
@@ -49,10 +53,9 @@ class Service extends Model implements CleansAttributes, ValidableContract
4953
* @var array
5054
*/
5155
protected static $dataIntegrityRules = [
52-
'author' => 'string|size:36',
56+
'author' => 'email',
5357
'name' => 'string|max:255',
5458
'description' => 'nullable|string',
55-
'folder' => 'string|max:255|regex:/^[\w.-]{1,50}$/|unique:services,folder',
5659
'startup' => 'nullable|string',
5760
'index_file' => 'string',
5861
];
@@ -74,12 +77,7 @@ public function options()
7477
*/
7578
public function packs()
7679
{
77-
return $this->hasManyThrough(
78-
Pack::class,
79-
ServiceOption::class,
80-
'service_id',
81-
'option_id'
82-
);
80+
return $this->hasManyThrough(Pack::class, ServiceOption::class, 'service_id', 'option_id');
8381
}
8482

8583
/**

app/Models/ServiceOption.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ class ServiceOption extends Model implements CleansAttributes, ValidableContract
3131
*
3232
* @var array
3333
*/
34-
protected $guarded = ['id', 'created_at', 'updated_at'];
34+
protected $fillable = [
35+
'name',
36+
'description',
37+
'docker_image',
38+
'config_files',
39+
'config_startup',
40+
'config_logs',
41+
'config_stop',
42+
'config_from',
43+
'startup',
44+
'script_is_privileged',
45+
'script_install',
46+
'script_entry',
47+
'script_container',
48+
'copy_script_from',
49+
];
3550

3651
/**
3752
* Cast values to correct type.
@@ -40,14 +55,17 @@ class ServiceOption extends Model implements CleansAttributes, ValidableContract
4055
*/
4156
protected $casts = [
4257
'service_id' => 'integer',
58+
'config_from' => 'integer',
4359
'script_is_privileged' => 'boolean',
60+
'copy_script_from' => 'integer',
4461
];
4562

4663
/**
4764
* @var array
4865
*/
4966
protected static $applicationRules = [
5067
'service_id' => 'required',
68+
'author' => 'required',
5169
'name' => 'required',
5270
'description' => 'required',
5371
'tag' => 'required',
@@ -64,13 +82,14 @@ class ServiceOption extends Model implements CleansAttributes, ValidableContract
6482
* @var array
6583
*/
6684
protected static $dataIntegrityRules = [
67-
'service_id' => 'numeric|exists:services,id',
85+
'service_id' => 'bail|numeric|exists:services,id',
86+
'author' => 'email',
6887
'name' => 'string|max:255',
6988
'description' => 'string',
70-
'tag' => 'alpha_num|max:60|unique:service_options,tag',
89+
'tag' => 'bail|alpha_num|max:60|unique:service_options,tag',
7190
'docker_image' => 'string|max:255',
7291
'startup' => 'nullable|string',
73-
'config_from' => 'nullable|numeric|exists:service_options,id',
92+
'config_from' => 'bail|nullable|numeric|exists:service_options,id',
7493
'config_stop' => 'nullable|string|max:255',
7594
'config_startup' => 'nullable|json',
7695
'config_logs' => 'nullable|json',

0 commit comments

Comments
 (0)