Skip to content

Commit 7618f30

Browse files
committed
Support functionality for per-egg features
1 parent 7ec614e commit 7618f30

File tree

7 files changed

+70
-20
lines changed

7 files changed

+70
-20
lines changed

app/Models/Egg.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @property string $author
1010
* @property string $name
1111
* @property string|null $description
12+
* @property array|null $features
1213
* @property string $docker_image
1314
* @property string|null $config_files
1415
* @property string|null $config_startup
@@ -31,6 +32,7 @@
3132
* @property string|null $inherit_config_startup
3233
* @property string|null $inherit_config_logs
3334
* @property string|null $inherit_config_stop
35+
* @property array|null $inherit_features
3436
*
3537
* @property \Pterodactyl\Models\Nest $nest
3638
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Server[] $servers
@@ -46,6 +48,18 @@ class Egg extends Model
4648
*/
4749
const RESOURCE_NAME = 'egg';
4850

51+
/**
52+
* Different features that can be enabled on any given egg. These are used internally
53+
* to determine which types of frontend functionality should be shown to the user. Eggs
54+
* will automatically inherit features from a parent egg if they are already configured
55+
* to copy configuration values from said egg.
56+
*
57+
* To skip copying the features, an empty array value should be passed in ("[]") rather
58+
* than leaving it null.
59+
*/
60+
const FEATURE_EULA_POPUP = 'eula';
61+
const FEATURE_FASTDL = 'fastdl';
62+
4963
/**
5064
* The table associated with the model.
5165
*
@@ -61,6 +75,7 @@ class Egg extends Model
6175
protected $fillable = [
6276
'name',
6377
'description',
78+
'features',
6479
'docker_image',
6580
'config_files',
6681
'config_startup',
@@ -85,6 +100,7 @@ class Egg extends Model
85100
'config_from' => 'integer',
86101
'script_is_privileged' => 'boolean',
87102
'copy_script_from' => 'integer',
103+
'features' => 'array',
88104
];
89105

90106
/**
@@ -95,6 +111,7 @@ class Egg extends Model
95111
'uuid' => 'required|string|size:36',
96112
'name' => 'required|string|max:191',
97113
'description' => 'string|nullable',
114+
'features' => 'json|nullable',
98115
'author' => 'required|string|email',
99116
'docker_image' => 'required|string|max:191',
100117
'startup' => 'required|nullable|string',
@@ -109,6 +126,7 @@ class Egg extends Model
109126
* @var array
110127
*/
111128
protected $attributes = [
129+
'features' => null,
112130
'config_stop' => null,
113131
'config_startup' => null,
114132
'config_logs' => null,
@@ -216,6 +234,21 @@ public function getInheritConfigStopAttribute()
216234
return $this->configFrom->config_stop;
217235
}
218236

237+
/**
238+
* Returns the features available to this egg from the parent configuration if there are
239+
* no features defined for this egg specifically and there is a parent egg configured.
240+
*
241+
* @return array|null
242+
*/
243+
public function getInheritFeaturesAttribute()
244+
{
245+
if (! is_null($this->features) || is_null($this->config_from)) {
246+
return $this->features;
247+
}
248+
249+
return $this->configFrom->features;
250+
}
251+
219252
/**
220253
* Gets nest associated with an egg.
221254
*

app/Services/Eggs/EggUpdateService.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ public function __construct(EggRepositoryInterface $repository)
3333
/**
3434
* Update a service option.
3535
*
36-
* @param int|\Pterodactyl\Models\Egg $egg
36+
* @param \Pterodactyl\Models\Egg $egg
3737
* @param array $data
3838
*
3939
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
4040
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
4141
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
4242
*/
43-
public function handle($egg, array $data)
43+
public function handle(Egg $egg, array $data)
4444
{
45-
if (! $egg instanceof Egg) {
46-
$egg = $this->repository->find($egg);
47-
}
48-
4945
if (! is_null(array_get($data, 'config_from'))) {
5046
$results = $this->repository->findCountWhere([
5147
['nest_id', '=', $egg->nest_id],

app/Services/Eggs/Sharing/EggExporterService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function handle(int $egg): string
4343
'name' => $egg->name,
4444
'author' => $egg->author,
4545
'description' => $egg->description,
46+
'features' => $egg->features,
4647
'image' => $egg->docker_image,
4748
'startup' => $egg->startup,
4849
'config' => [

app/Services/Eggs/Sharing/EggImporterService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function handle(UploadedFile $file, int $nest): Egg
101101
'author' => object_get($parsed, 'author'),
102102
'name' => object_get($parsed, 'name'),
103103
'description' => object_get($parsed, 'description'),
104+
'features' => object_get($parsed, 'features'),
104105
'docker_image' => object_get($parsed, 'image'),
105106
'config_files' => object_get($parsed, 'config.files'),
106107
'config_startup' => object_get($parsed, 'config.startup'),

app/Services/Eggs/Sharing/EggUpdateImporterService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function handle(Egg $egg, UploadedFile $file)
8686
'author' => object_get($parsed, 'author'),
8787
'name' => object_get($parsed, 'name'),
8888
'description' => object_get($parsed, 'description'),
89+
'features' => object_get($parsed, 'features'),
8990
'docker_image' => object_get($parsed, 'image'),
9091
'config_files' => object_get($parsed, 'config.files'),
9192
'config_startup' => object_get($parsed, 'config.startup'),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddFeaturesColumnToEggs extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('eggs', function (Blueprint $table) {
17+
$table->json('features')->after('description')->nullable();
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('eggs', function (Blueprint $table) {
29+
$table->dropColumn('features');
30+
});
31+
}
32+
}

tests/Unit/Services/Eggs/EggUpdateServiceTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,4 @@ public function testExceptionIsThrownIfInvalidParentConfigIsPassed()
8888
$this->assertEquals(trans('exceptions.nest.egg.must_be_child'), $exception->getMessage());
8989
}
9090
}
91-
92-
/**
93-
* Test that an integer linking to a model can be passed in place of the Egg model.
94-
*/
95-
public function testIntegerCanBePassedInPlaceOfModel()
96-
{
97-
$this->repository->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
98-
$this->repository->shouldReceive('withoutFreshModel->update')
99-
->with($this->model->id, ['test_field' => 'field_value'])->once()->andReturnNull();
100-
101-
$this->service->handle($this->model->id, ['test_field' => 'field_value']);
102-
103-
$this->assertTrue(true);
104-
}
10591
}

0 commit comments

Comments
 (0)