From 3158bdfef8261e491f775c712ca2e30570efb253 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sat, 10 Aug 2024 18:20:21 -0400 Subject: [PATCH 01/11] Fix Single Egg Import --- app/Filament/Resources/EggResource/Pages/EditEgg.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Filament/Resources/EggResource/Pages/EditEgg.php b/app/Filament/Resources/EggResource/Pages/EditEgg.php index b4af8bc0ae..acd76e4794 100644 --- a/app/Filament/Resources/EggResource/Pages/EditEgg.php +++ b/app/Filament/Resources/EggResource/Pages/EditEgg.php @@ -270,16 +270,14 @@ protected function getHeaderActions(): array Notification::make() ->title('Import Failed') ->body($exception->getMessage()) - ->danger() + ->danger() // Will Robinson ->send(); report($exception); return; } - } - - if (!empty($data['url'])) { + } elseif (!empty($data['url'])) { try { $eggImportService->fromUrl($data['url'], $egg); } catch (Exception $exception) { From bad5409d9c5354c42c5eaec4378f5a6d0f779635 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sat, 10 Aug 2024 19:39:41 -0400 Subject: [PATCH 02/11] Fix saving SMTP without encryption --- app/Filament/Pages/Settings.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 4cfe7ce100..aec3819c47 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -262,28 +262,27 @@ private function mailSettings(): array ->visible(fn (Get $get) => $get('MAIL_MAILER') === 'smtp') ->schema([ TextInput::make('MAIL_HOST') - ->label('SMTP Host') + ->label('Host') ->required() ->default(env('MAIL_HOST', config('mail.mailers.smtp.host'))), TextInput::make('MAIL_PORT') - ->label('SMTP Port') + ->label('Port') ->required() ->numeric() ->minValue(1) ->maxValue(65535) ->default(env('MAIL_PORT', config('mail.mailers.smtp.port'))), TextInput::make('MAIL_USERNAME') - ->label('SMTP Username') + ->label('Username') ->required() ->default(env('MAIL_USERNAME', config('mail.mailers.smtp.username'))), TextInput::make('MAIL_PASSWORD') - ->label('SMTP Password') + ->label('Password') ->password() ->revealable() ->default(env('MAIL_PASSWORD')), ToggleButtons::make('MAIL_ENCRYPTION') - ->label('SMTP encryption') - ->required() + ->label('Encryption') ->inline() ->options(['tls' => 'TLS', 'ssl' => 'SSL', '' => 'None']) ->default(env('MAIL_ENCRYPTION', config('mail.mailers.smtp.encryption', 'tls'))), @@ -293,15 +292,15 @@ private function mailSettings(): array ->visible(fn (Get $get) => $get('MAIL_MAILER') === 'mailgun') ->schema([ TextInput::make('MAILGUN_DOMAIN') - ->label('Mailgun Domain') + ->label('Domain') ->required() ->default(env('MAILGUN_DOMAIN', config('services.mailgun.domain'))), TextInput::make('MAILGUN_SECRET') - ->label('Mailgun Secret') + ->label('Secret') ->required() ->default(env('MAIL_USERNAME', config('services.mailgun.secret'))), TextInput::make('MAILGUN_ENDPOINT') - ->label('Mailgun Endpoint') + ->label('Endpoint') ->required() ->default(env('MAILGUN_ENDPOINT', config('services.mailgun.endpoint'))), ]), From 155f2d6476984185852fb69ed73958c6475437e9 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Tue, 13 Aug 2024 19:43:16 +0200 Subject: [PATCH 03/11] Add migration to fix allocations server_id foreign key (#542) * add migration to fix allocations server_id foreign key * fix the fix... --- ...1337_fix_allocation_server_foreign_key.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 database/migrations/2024_08_13_171337_fix_allocation_server_foreign_key.php diff --git a/database/migrations/2024_08_13_171337_fix_allocation_server_foreign_key.php b/database/migrations/2024_08_13_171337_fix_allocation_server_foreign_key.php new file mode 100644 index 0000000000..9abb9317e7 --- /dev/null +++ b/database/migrations/2024_08_13_171337_fix_allocation_server_foreign_key.php @@ -0,0 +1,54 @@ +getDriverName() !== 'sqlite') { + return; + } + + // Disable foreign checks + // legacy_alter_table needs to be 'ON' so existing foreign key table references aren't renamed when renaming the table, see https://www.sqlite.org/lang_altertable.html + DB::statement('PRAGMA foreign_keys = OFF'); + DB::statement('PRAGMA legacy_alter_table = ON'); + + DB::transaction(function () { + DB::statement('ALTER TABLE allocations RENAME TO _allocations_old'); + DB::statement('CREATE TABLE allocations + ("id" integer primary key autoincrement not null, + "node_id" integer not null, + "ip" varchar not null, + "port" integer not null, + "server_id" integer, + "created_at" datetime, + "updated_at" datetime, + "ip_alias" text, + "notes" varchar, + foreign key("node_id") references "nodes"("id") on delete cascade, + foreign key("server_id") references "servers"("id") on delete set null)'); + DB::statement('INSERT INTO allocations SELECT * FROM _allocations_old'); + DB::statement('DROP TABLE _allocations_old'); + DB::statement('CREATE UNIQUE INDEX "allocations_node_id_ip_port_unique" on "allocations" ("node_id", "ip", "port")'); + }); + + DB::statement('PRAGMA foreign_keys = ON'); + DB::statement('PRAGMA legacy_alter_table = OFF'); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // Reverse not needed + } +}; From 1864fff04f8b2847f8ff043bb38819f481b55028 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 16 Aug 2024 22:44:12 +0200 Subject: [PATCH 04/11] Update default image for new eggs (#540) --- app/Filament/Resources/EggResource/Pages/CreateEgg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/EggResource/Pages/CreateEgg.php b/app/Filament/Resources/EggResource/Pages/CreateEgg.php index d73863f570..856963fab6 100644 --- a/app/Filament/Resources/EggResource/Pages/CreateEgg.php +++ b/app/Filament/Resources/EggResource/Pages/CreateEgg.php @@ -187,7 +187,7 @@ public function form(Form $form): Form TextInput::make('script_container') ->required() ->maxLength(255) - ->default('alpine:3.4'), + ->default('ghcr.io/pelican-eggs/installers:debian'), Select::make('script_entry') ->selectablePlaceholder(false) From 68e24896ae0a4380342bcf148bc6fced53b1983a Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Fri, 16 Aug 2024 22:50:09 +0200 Subject: [PATCH 05/11] Patch for node 18 (#539) --- package.json | 3 ++- yarn.lock | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ebb3266be3..713b5cbafb 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-router-dom": "^5.1.2", "react-transition-group": "^4.4.1", "reaptcha": "^1.7.2", + "rimraf": "^4", "sockette": "^2.0.6", "styled-components": "^5.2.1", "styled-components-breakpoint": "^3.0.0-preview.20", @@ -130,7 +131,7 @@ "yarn-deduplicate": "^1.1.1" }, "scripts": { - "clean": "cd public/assets && find . \\( -name \"*.js\" -o -name \"*.map\" \\) -type f -delete", + "clean": "cd public/assets && rimraf -g *.js *.map", "test": "jest", "lint": "eslint ./resources/scripts/**/*.{ts,tsx} --ext .ts,.tsx", "watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress", diff --git a/yarn.lock b/yarn.lock index ff431b75ed..fca7a74157 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2736,6 +2736,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^2.3.1, braces@^2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" @@ -4758,6 +4765,16 @@ glob@^7.0.3, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.1.7: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^9.2.0: + version "9.3.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21" + integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q== + dependencies: + fs.realpath "^1.0.0" + minimatch "^8.0.2" + minipass "^4.2.4" + path-scurry "^1.6.1" + global-modules@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea" @@ -6164,6 +6181,11 @@ loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4 dependencies: js-tokens "^3.0.0 || ^4.0.0" +lru-cache@^10.2.0: + version "10.4.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" + integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -6376,6 +6398,13 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" +minimatch@^8.0.2: + version "8.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229" + integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA== + dependencies: + brace-expansion "^2.0.1" + minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5: version "1.2.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" @@ -6409,11 +6438,21 @@ minipass@^3.0.0, minipass@^3.1.1: dependencies: yallist "^4.0.0" +minipass@^4.2.4: + version "4.2.8" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a" + integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ== + minipass@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/minipass/-/minipass-5.0.0.tgz#3e9788ffb90b694a5d0ec94479a45b5d8738133d" integrity sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ== +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0": + version "7.1.2" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" + integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== + minizlib@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.2.tgz#e90d3466ba209b932451508a11ce3d3632145931" @@ -6923,6 +6962,14 @@ path-parse@^1.0.6, path-parse@^1.0.7: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== +path-scurry@^1.6.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" + integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== + dependencies: + lru-cache "^10.2.0" + minipass "^5.0.0 || ^6.0.2 || ^7.0.0" + path-to-regexp@0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" @@ -7991,6 +8038,13 @@ rimraf@^3.0.0, rimraf@^3.0.2: dependencies: glob "^7.1.3" +rimraf@^4: + version "4.4.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.4.1.tgz#bd33364f67021c5b79e93d7f4fa0568c7c21b755" + integrity sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og== + dependencies: + glob "^9.2.0" + ripemd160@^2.0.0, ripemd160@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" From bf23389dba1cd5fcfc561025e5523dc194b31987 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Sun, 18 Aug 2024 16:11:40 +0200 Subject: [PATCH 06/11] Fix default value for mailgun secret (#552) --- app/Filament/Pages/Settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index aec3819c47..ad9ea96bae 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -298,7 +298,7 @@ private function mailSettings(): array TextInput::make('MAILGUN_SECRET') ->label('Secret') ->required() - ->default(env('MAIL_USERNAME', config('services.mailgun.secret'))), + ->default(env('MAILGUN_SECRET', config('services.mailgun.secret'))), TextInput::make('MAILGUN_ENDPOINT') ->label('Endpoint') ->required() From ffadf9ac163c57ef5b0bca72016a109015398381 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Sun, 18 Aug 2024 16:43:40 +0200 Subject: [PATCH 07/11] Clear cache before running migrations (#553) --- app/Filament/Pages/Installer/PanelInstaller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Filament/Pages/Installer/PanelInstaller.php b/app/Filament/Pages/Installer/PanelInstaller.php index 2e0dcaf578..11cbd98c87 100644 --- a/app/Filament/Pages/Installer/PanelInstaller.php +++ b/app/Filament/Pages/Installer/PanelInstaller.php @@ -103,6 +103,10 @@ public function submit() $variables = array_get($inputs, 'env'); $this->writeToEnvironment($variables); + // Clear cache + Artisan::call('config:clear'); + Artisan::call('cache:clear'); + // Run migrations Artisan::call('migrate', [ '--force' => true, From d0c89b0729e8b52a6135b2076b291f74d9c3c54d Mon Sep 17 00:00:00 2001 From: Boy132 Date: Sun, 18 Aug 2024 17:23:02 +0200 Subject: [PATCH 08/11] ix installer cache (#554) --- app/Filament/Pages/Installer/PanelInstaller.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Filament/Pages/Installer/PanelInstaller.php b/app/Filament/Pages/Installer/PanelInstaller.php index 11cbd98c87..b6aea2b098 100644 --- a/app/Filament/Pages/Installer/PanelInstaller.php +++ b/app/Filament/Pages/Installer/PanelInstaller.php @@ -103,14 +103,11 @@ public function submit() $variables = array_get($inputs, 'env'); $this->writeToEnvironment($variables); - // Clear cache - Artisan::call('config:clear'); - Artisan::call('cache:clear'); - // Run migrations Artisan::call('migrate', [ '--force' => true, '--seed' => true, + '--database' => $variables['DB_CONNECTION'], ]); if (!$this->hasCompletedMigrations()) { From d1ca21de9f16008594d0b122187d6b8b6cb58426 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sun, 18 Aug 2024 11:41:36 -0400 Subject: [PATCH 09/11] Test Runners --- .github/workflows/ci.yaml | 6 +++--- .github/workflows/cla.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e2ee88471..14591007a2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ on: jobs: mysql: name: MySQL - runs-on: ubuntu-latest + runs-on: self-hosted strategy: fail-fast: false matrix: @@ -84,7 +84,7 @@ jobs: mariadb: name: MariaDB - runs-on: ubuntu-latest + runs-on: self-hosted strategy: fail-fast: false matrix: @@ -157,7 +157,7 @@ jobs: sqlite: name: SQLite - runs-on: ubuntu-latest + runs-on: self-hosted strategy: fail-fast: false matrix: diff --git a/.github/workflows/cla.yaml b/.github/workflows/cla.yaml index 90621b05c9..28d96a698c 100644 --- a/.github/workflows/cla.yaml +++ b/.github/workflows/cla.yaml @@ -13,7 +13,7 @@ permissions: jobs: CLAAssistant: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: "CLA Assistant" if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' From 0ff429215dad385e1373dfe3afc26d79dbf697d5 Mon Sep 17 00:00:00 2001 From: notCharles Date: Sun, 18 Aug 2024 11:54:12 -0400 Subject: [PATCH 10/11] Revert "Test Runners" This reverts commit d1ca21de9f16008594d0b122187d6b8b6cb58426. --- .github/workflows/ci.yaml | 6 +++--- .github/workflows/cla.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 14591007a2..5e2ee88471 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ on: jobs: mysql: name: MySQL - runs-on: self-hosted + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -84,7 +84,7 @@ jobs: mariadb: name: MariaDB - runs-on: self-hosted + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -157,7 +157,7 @@ jobs: sqlite: name: SQLite - runs-on: self-hosted + runs-on: ubuntu-latest strategy: fail-fast: false matrix: diff --git a/.github/workflows/cla.yaml b/.github/workflows/cla.yaml index 28d96a698c..90621b05c9 100644 --- a/.github/workflows/cla.yaml +++ b/.github/workflows/cla.yaml @@ -13,7 +13,7 @@ permissions: jobs: CLAAssistant: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - name: "CLA Assistant" if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' From c2b1a98d292753153de3c07fb65e4973a67e5ab4 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Mon, 19 Aug 2024 08:33:53 +0200 Subject: [PATCH 11/11] Convert variable "rules" to array (#507) * convert variable "rules" to array * allow importing eggs with string rules * fix tests * update stock eggs to rules array --- .../Resources/EggResource/Pages/CreateEgg.php | 29 +++++- .../Resources/EggResource/Pages/EditEgg.php | 29 +++++- .../ServerResource/Pages/CreateServer.php | 16 ++-- .../ServerResource/Pages/EditServer.php | 20 ++-- app/Models/EggVariable.php | 9 +- .../Eggs/Sharing/EggImporterService.php | 2 + .../Variables/VariableCreationService.php | 4 +- .../Eggs/Variables/VariableUpdateService.php | 11 +-- .../Api/Client/EggVariableTransformer.php | 2 +- .../eggs/minecraft/egg-bungeecord.json | 13 ++- .../eggs/minecraft/egg-forge-minecraft.json | 24 ++++- .../Seeders/eggs/minecraft/egg-paper.json | 24 ++++- .../minecraft/egg-sponge--sponge-vanilla.json | 12 ++- .../eggs/minecraft/egg-vanilla-minecraft.json | 13 ++- database/Seeders/eggs/rust/egg-rust.json | 96 +++++++++++++++---- ...egg-counter--strike--global-offensive.json | 21 +++- .../egg-custom-source-engine-game.json | 35 +++++-- .../eggs/source-engine/egg-garrys-mod.json | 48 ++++++++-- .../eggs/source-engine/egg-insurgency.json | 12 ++- .../source-engine/egg-team-fortress2.json | 19 +++- .../eggs/voice-servers/egg-mumble-server.json | 8 +- .../voice-servers/egg-teamspeak3-server.json | 38 ++++++-- ...24_07_25_072050_convert_rules_to_array.php | 37 +++++++ .../Startup/UpdateStartupVariableTest.php | 2 +- .../Servers/VariableValidatorServiceTest.php | 2 +- 25 files changed, 408 insertions(+), 118 deletions(-) create mode 100644 database/migrations/2024_07_25_072050_convert_rules_to_array.php diff --git a/app/Filament/Resources/EggResource/Pages/CreateEgg.php b/app/Filament/Resources/EggResource/Pages/CreateEgg.php index 856963fab6..5dfa3b05f8 100644 --- a/app/Filament/Resources/EggResource/Pages/CreateEgg.php +++ b/app/Filament/Resources/EggResource/Pages/CreateEgg.php @@ -134,7 +134,7 @@ public function form(Form $form): Form ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $data['default_value'] ??= ''; $data['description'] ??= ''; - $data['rules'] ??= ''; + $data['rules'] ??= []; $data['user_viewable'] ??= ''; $data['user_editable'] ??= ''; @@ -143,7 +143,7 @@ public function form(Form $form): Form ->mutateRelationshipDataBeforeSaveUsing(function (array $data): array { $data['default_value'] ??= ''; $data['description'] ??= ''; - $data['rules'] ??= ''; + $data['rules'] ??= []; $data['user_viewable'] ??= ''; $data['user_editable'] ??= ''; @@ -173,7 +173,30 @@ public function form(Form $form): Form Checkbox::make('user_viewable')->label('Viewable'), Checkbox::make('user_editable')->label('Editable'), ]), - Textarea::make('rules')->columnSpanFull(), + TagsInput::make('rules') + ->columnSpanFull() + ->placeholder('Add Rule') + ->reorderable() + ->suggestions([ + 'required', + 'nullable', + 'string', + 'integer', + 'numeric', + 'boolean', + 'alpha', + 'alpha_dash', + 'alpha_num', + 'url', + 'email', + 'regex:', + 'min:', + 'max:', + 'between:', + 'between:1024,65535', + 'in:', + 'in:true,false', + ]), ]), ]), Tab::make('Install Script') diff --git a/app/Filament/Resources/EggResource/Pages/EditEgg.php b/app/Filament/Resources/EggResource/Pages/EditEgg.php index acd76e4794..ee7bf5bd62 100644 --- a/app/Filament/Resources/EggResource/Pages/EditEgg.php +++ b/app/Filament/Resources/EggResource/Pages/EditEgg.php @@ -144,7 +144,7 @@ public function form(Form $form): Form ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $data['default_value'] ??= ''; $data['description'] ??= ''; - $data['rules'] ??= ''; + $data['rules'] ??= []; $data['user_viewable'] ??= ''; $data['user_editable'] ??= ''; @@ -153,7 +153,7 @@ public function form(Form $form): Form ->mutateRelationshipDataBeforeSaveUsing(function (array $data): array { $data['default_value'] ??= ''; $data['description'] ??= ''; - $data['rules'] ??= ''; + $data['rules'] ??= []; $data['user_viewable'] ??= ''; $data['user_editable'] ??= ''; @@ -183,7 +183,30 @@ public function form(Form $form): Form Checkbox::make('user_viewable')->label('Viewable'), Checkbox::make('user_editable')->label('Editable'), ]), - TextInput::make('rules')->columnSpanFull(), + TagsInput::make('rules') + ->columnSpanFull() + ->placeholder('Add Rule') + ->reorderable() + ->suggestions([ + 'required', + 'nullable', + 'string', + 'integer', + 'numeric', + 'boolean', + 'alpha', + 'alpha_dash', + 'alpha_num', + 'url', + 'email', + 'regex:', + 'min:', + 'max:', + 'between:', + 'between:1024,65535', + 'in:', + 'in:true,false', + ]), ]), ]), Tab::make('Install Script') diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index 343c8fa0c0..9f2de64b92 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -6,6 +6,7 @@ use App\Models\Allocation; use App\Models\Egg; use App\Models\Node; +use App\Models\ServerVariable; use App\Models\User; use App\Services\Allocations\AssignmentService; use App\Services\Servers\RandomWordService; @@ -443,8 +444,7 @@ public function form(Form $form): Form $text = Forms\Components\TextInput::make('variable_value') ->hidden($this->shouldHideComponent(...)) - ->maxLength(255) - ->required(fn (Forms\Get $get) => in_array('required', explode('|', $get('rules')))) + ->required(fn (ServerVariable $serverVariable) => $serverVariable->variable->getRequiredAttribute()) ->rules( fn (Forms\Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) { $validator = Validator::make(['validatorkey' => $value], [ @@ -806,11 +806,9 @@ protected function handleRecordCreation(array $data): Model return $service->handle($data); } - private function shouldHideComponent(Forms\Get $get, Forms\Components\Component $component): bool + private function shouldHideComponent(ServerVariable $serverVariable, Forms\Components\Component $component): bool { - $containsRuleIn = str($get('rules'))->explode('|')->reduce( - fn ($result, $value) => $result === true && !str($value)->startsWith('in:'), true - ); + $containsRuleIn = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:'), false); if ($component instanceof Forms\Components\Select) { return $containsRuleIn; @@ -823,11 +821,9 @@ private function shouldHideComponent(Forms\Get $get, Forms\Components\Component throw new \Exception('Component type not supported: ' . $component::class); } - private function getSelectOptionsFromRules(Forms\Get $get): array + private function getSelectOptionsFromRules(ServerVariable $serverVariable): array { - $inRule = str($get('rules'))->explode('|')->reduce( - fn ($result, $value) => str($value)->startsWith('in:') ? $value : $result, '' - ); + $inRule = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:')); return str($inRule) ->after('in:') diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index c8726fde54..74cfe70180 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -489,7 +489,7 @@ public function form(Form $form): Form $text = Forms\Components\TextInput::make('variable_value') ->hidden($this->shouldHideComponent(...)) - ->required(fn (ServerVariable $serverVariable) => in_array('required', explode('|', $serverVariable->variable->rules))) + ->required(fn (ServerVariable $serverVariable) => $serverVariable->variable->getRequiredAttribute()) ->rules([ fn (ServerVariable $serverVariable): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) { $validator = Validator::make(['validatorkey' => $value], [ @@ -516,7 +516,7 @@ public function form(Form $form): Form ->live(onBlur: true) ->hintIcon('tabler-code') ->label(fn (ServerVariable $serverVariable) => $serverVariable->variable->name) - ->hintIconTooltip(fn (ServerVariable $serverVariable) => $serverVariable->variable->rules) + ->hintIconTooltip(fn (ServerVariable $serverVariable) => implode('|', $serverVariable->variable->rules)) ->prefix(fn (ServerVariable $serverVariable) => '{{' . $serverVariable->variable->env_variable . '}}') ->helperText(fn (ServerVariable $serverVariable) => empty($serverVariable->variable->description) ? '—' : $serverVariable->variable->description); } @@ -757,28 +757,24 @@ public function getRelationManagers(): array ]; } - private function shouldHideComponent(Forms\Get $get, Forms\Components\Component $component): bool + private function shouldHideComponent(ServerVariable $serverVariable, Forms\Components\Component $component): bool { - $containsRuleIn = str($get('rules'))->explode('|')->reduce( - fn ($result, $value) => $result === true && !str($value)->startsWith('in:'), true - ); + $containsRuleIn = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:'), false); if ($component instanceof Forms\Components\Select) { - return $containsRuleIn; + return !$containsRuleIn; } if ($component instanceof Forms\Components\TextInput) { - return !$containsRuleIn; + return $containsRuleIn; } throw new \Exception('Component type not supported: ' . $component::class); } - private function getSelectOptionsFromRules(Forms\Get $get): array + private function getSelectOptionsFromRules(ServerVariable $serverVariable): array { - $inRule = str($get('rules'))->explode('|')->reduce( - fn ($result, $value) => str($value)->startsWith('in:') ? $value : $result, '' - ); + $inRule = array_first($serverVariable->variable->rules, fn ($value) => str($value)->startsWith('in:')); return str($inRule) ->after('in:') diff --git a/app/Models/EggVariable.php b/app/Models/EggVariable.php index c589d95341..2d3a4fb2c5 100644 --- a/app/Models/EggVariable.php +++ b/app/Models/EggVariable.php @@ -15,7 +15,7 @@ * @property string $default_value * @property bool $user_viewable * @property bool $user_editable - * @property string $rules + * @property array $rules * @property \Carbon\CarbonImmutable $created_at * @property \Carbon\CarbonImmutable $updated_at * @property bool $required @@ -58,12 +58,14 @@ class EggVariable extends Model 'default_value' => 'string', 'user_viewable' => 'boolean', 'user_editable' => 'boolean', - 'rules' => 'string', + 'rules' => 'array', + 'rules.*' => 'string', ]; protected $attributes = [ 'user_editable' => 0, 'user_viewable' => 0, + 'rules' => '[]', ]; protected function casts(): array @@ -72,6 +74,7 @@ protected function casts(): array 'egg_id' => 'integer', 'user_viewable' => 'bool', 'user_editable' => 'bool', + 'rules' => 'array', 'created_at' => 'immutable_datetime', 'updated_at' => 'immutable_datetime', ]; @@ -79,7 +82,7 @@ protected function casts(): array public function getRequiredAttribute(): bool { - return in_array('required', explode('|', $this->rules)); + return in_array('required', $this->rules); } public function egg(): HasOne diff --git a/app/Services/Eggs/Sharing/EggImporterService.php b/app/Services/Eggs/Sharing/EggImporterService.php index 1e85923d7d..dc54525a6e 100644 --- a/app/Services/Eggs/Sharing/EggImporterService.php +++ b/app/Services/Eggs/Sharing/EggImporterService.php @@ -54,6 +54,8 @@ public function fromFile(UploadedFile $file, Egg $egg = null): Egg // Update existing variables or create new ones. foreach ($parsed['variables'] ?? [] as $variable) { EggVariable::unguarded(function () use ($egg, $variable) { + $variable['rules'] = is_array($variable['rules']) ? $variable['rules'] : explode('|', $variable['rules']); + $egg->variables()->updateOrCreate([ 'env_variable' => $variable['env_variable'], ], Collection::make($variable)->except(['egg_id', 'env_variable'])->toArray()); diff --git a/app/Services/Eggs/Variables/VariableCreationService.php b/app/Services/Eggs/Variables/VariableCreationService.php index d2213f5be1..c6c7269862 100644 --- a/app/Services/Eggs/Variables/VariableCreationService.php +++ b/app/Services/Eggs/Variables/VariableCreationService.php @@ -40,7 +40,7 @@ public function handle(int $egg, array $data): EggVariable throw new ReservedVariableNameException(sprintf('Cannot use the protected name %s for this environment variable.', array_get($data, 'env_variable'))); } - if (!empty($data['rules'] ?? '')) { + if (!empty($data['rules'] ?? [])) { $this->validateRules($data['rules']); } @@ -55,7 +55,7 @@ public function handle(int $egg, array $data): EggVariable 'default_value' => $data['default_value'] ?? '', 'user_viewable' => in_array('user_viewable', $options), 'user_editable' => in_array('user_editable', $options), - 'rules' => $data['rules'] ?? '', + 'rules' => $data['rules'] ?? [], ]); return $eggVariable; diff --git a/app/Services/Eggs/Variables/VariableUpdateService.php b/app/Services/Eggs/Variables/VariableUpdateService.php index 515cbc2714..e56ae8ea74 100644 --- a/app/Services/Eggs/Variables/VariableUpdateService.php +++ b/app/Services/Eggs/Variables/VariableUpdateService.php @@ -2,7 +2,6 @@ namespace App\Services\Eggs\Variables; -use Illuminate\Support\Str; use App\Models\EggVariable; use App\Exceptions\DisplayException; use App\Traits\Services\ValidatesValidationRules; @@ -54,12 +53,8 @@ public function handle(EggVariable $variable, array $data): mixed } } - if (!empty($data['rules'] ?? '')) { - $this->validateRules( - (is_string($data['rules']) && Str::contains($data['rules'], ';;')) - ? explode(';;', $data['rules']) - : $data['rules'] - ); + if (!empty($data['rules'] ?? [])) { + $this->validateRules($data['rules']); } $options = array_get($data, 'options') ?? []; @@ -71,7 +66,7 @@ public function handle(EggVariable $variable, array $data): mixed 'default_value' => $data['default_value'] ?? '', 'user_viewable' => in_array('user_viewable', $options), 'user_editable' => in_array('user_editable', $options), - 'rules' => $data['rules'] ?? '', + 'rules' => $data['rules'] ?? [], ]); } } diff --git a/app/Transformers/Api/Client/EggVariableTransformer.php b/app/Transformers/Api/Client/EggVariableTransformer.php index bdc2fad152..141f43b618 100644 --- a/app/Transformers/Api/Client/EggVariableTransformer.php +++ b/app/Transformers/Api/Client/EggVariableTransformer.php @@ -27,7 +27,7 @@ public function transform(EggVariable $variable): array 'default_value' => $variable->default_value, 'server_value' => $variable->server_value, 'is_editable' => $variable->user_editable, - 'rules' => $variable->rules, + 'rules' => implode('|', $variable->rules), ]; } } diff --git a/database/Seeders/eggs/minecraft/egg-bungeecord.json b/database/Seeders/eggs/minecraft/egg-bungeecord.json index f9b3895601..49bc8be50b 100644 --- a/database/Seeders/eggs/minecraft/egg-bungeecord.json +++ b/database/Seeders/eggs/minecraft/egg-bungeecord.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/minecraft\/egg-bungeecord.json" }, - "exported_at": "2024-07-03T14:33:51+00:00", + "exported_at": "2024-07-25T12:03:12+00:00", "name": "Bungeecord", "author": "panel@example.com", "uuid": "9e6b409e-4028-4947-aea8-50a2c404c271", @@ -44,7 +44,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "required|alpha_num|between:1,6", + "rules": [ + "required", + "alpha_num", + "between:1,6" + ], "sort": null, "field_type": "text" }, @@ -55,7 +59,10 @@ "default_value": "bungeecord.jar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([\\w\\d._-]+)(\\.jar)$\/", + "rules": [ + "required", + "regex:\/^([\\w\\d._-]+)(\\.jar)$\/" + ], "sort": null, "field_type": "text" } diff --git a/database/Seeders/eggs/minecraft/egg-forge-minecraft.json b/database/Seeders/eggs/minecraft/egg-forge-minecraft.json index 693e299db2..13afe9748a 100644 --- a/database/Seeders/eggs/minecraft/egg-forge-minecraft.json +++ b/database/Seeders/eggs/minecraft/egg-forge-minecraft.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/minecraft\/egg-forge-minecraft.json" }, - "exported_at": "2024-07-03T14:33:51+00:00", + "exported_at": "2024-07-25T12:03:19+00:00", "name": "Forge Minecraft", "author": "panel@example.com", "uuid": "ed072427-f209-4603-875c-f540c6dd5a65", @@ -44,7 +44,10 @@ "default_value": "server.jar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([\\w\\d._-]+)(\\.jar)$\/", + "rules": [ + "required", + "regex:\/^([\\w\\d._-]+)(\\.jar)$\/" + ], "sort": 1, "field_type": "text" }, @@ -55,7 +58,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:9", + "rules": [ + "required", + "string", + "max:9" + ], "sort": 2, "field_type": "text" }, @@ -66,7 +73,11 @@ "default_value": "recommended", "user_viewable": true, "user_editable": true, - "rules": "required|string|in:recommended,latest", + "rules": [ + "required", + "string", + "in:recommended,latest" + ], "sort": 3, "field_type": "text" }, @@ -77,7 +88,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|regex:\/^[0-9\\.\\-]+$\/", + "rules": [ + "nullable", + "regex:\/^[0-9\\.\\-]+$\/" + ], "sort": 4, "field_type": "text" } diff --git a/database/Seeders/eggs/minecraft/egg-paper.json b/database/Seeders/eggs/minecraft/egg-paper.json index 39463b0e98..d8a73b9f40 100644 --- a/database/Seeders/eggs/minecraft/egg-paper.json +++ b/database/Seeders/eggs/minecraft/egg-paper.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/minecraft\/egg-paper.json" }, - "exported_at": "2024-07-03T14:33:52+00:00", + "exported_at": "2024-07-25T12:03:43+00:00", "name": "Paper", "author": "parker@example.com", "uuid": "5da37ef6-58da-4169-90a6-e683e1721247", @@ -44,7 +44,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "nullable|string|max:20", + "rules": [ + "nullable", + "string", + "max:20" + ], "sort": 1, "field_type": "text" }, @@ -55,7 +59,10 @@ "default_value": "server.jar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([\\w\\d._-]+)(\\.jar)$\/", + "rules": [ + "required", + "regex:\/^([\\w\\d._-]+)(\\.jar)$\/" + ], "sort": 2, "field_type": "text" }, @@ -66,7 +73,10 @@ "default_value": "", "user_viewable": false, "user_editable": false, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 3, "field_type": "text" }, @@ -77,7 +87,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:20", + "rules": [ + "required", + "string", + "max:20" + ], "sort": 4, "field_type": "text" } diff --git a/database/Seeders/eggs/minecraft/egg-sponge--sponge-vanilla.json b/database/Seeders/eggs/minecraft/egg-sponge--sponge-vanilla.json index 278f58a6cc..1a72aefe77 100644 --- a/database/Seeders/eggs/minecraft/egg-sponge--sponge-vanilla.json +++ b/database/Seeders/eggs/minecraft/egg-sponge--sponge-vanilla.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/minecraft\/egg-sponge--sponge-vanilla.json" }, - "exported_at": "2024-07-03T14:34:02+00:00", + "exported_at": "2024-07-25T12:03:55+00:00", "name": "Sponge (SpongeVanilla)", "author": "panel@example.com", "uuid": "f0d2f88f-1ff3-42a0-b03f-ac44c5571e6d", @@ -44,7 +44,10 @@ "default_value": "1.12.2-7.3.0", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([a-zA-Z0-9.\\-_]+)$\/", + "rules": [ + "required", + "regex:\/^([a-zA-Z0-9.\\-_]+)$\/" + ], "sort": 1, "field_type": "text" }, @@ -55,7 +58,10 @@ "default_value": "server.jar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([\\w\\d._-]+)(\\.jar)$\/", + "rules": [ + "required", + "regex:\/^([\\w\\d._-]+)(\\.jar)$\/" + ], "sort": 2, "field_type": "text" } diff --git a/database/Seeders/eggs/minecraft/egg-vanilla-minecraft.json b/database/Seeders/eggs/minecraft/egg-vanilla-minecraft.json index 94f2578633..71d71938e1 100644 --- a/database/Seeders/eggs/minecraft/egg-vanilla-minecraft.json +++ b/database/Seeders/eggs/minecraft/egg-vanilla-minecraft.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/minecraft\/egg-vanilla-minecraft.json" }, - "exported_at": "2024-07-03T14:34:02+00:00", + "exported_at": "2024-07-25T12:04:05+00:00", "name": "Vanilla Minecraft", "author": "panel@example.com", "uuid": "9ac39f3d-0c34-4d93-8174-c52ab9e6c57b", @@ -44,7 +44,10 @@ "default_value": "server.jar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^([\\w\\d._-]+)(\\.jar)$\/", + "rules": [ + "required", + "regex:\/^([\\w\\d._-]+)(\\.jar)$\/" + ], "sort": 1, "field_type": "text" }, @@ -55,7 +58,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "required|string|between:3,15", + "rules": [ + "required", + "string", + "between:3,15" + ], "sort": 2, "field_type": "text" } diff --git a/database/Seeders/eggs/rust/egg-rust.json b/database/Seeders/eggs/rust/egg-rust.json index 5b763bd7c1..e74368604a 100644 --- a/database/Seeders/eggs/rust/egg-rust.json +++ b/database/Seeders/eggs/rust/egg-rust.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/rust\/egg-rust.json" }, - "exported_at": "2024-07-03T14:34:09+00:00", + "exported_at": "2024-07-25T12:06:17+00:00", "name": "Rust", "author": "panel@example.com", "uuid": "bace2dfb-209c-452a-9459-7d6f340b07ae", @@ -38,7 +38,11 @@ "default_value": "A Rust Server", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:60", + "rules": [ + "required", + "string", + "max:60" + ], "sort": 1, "field_type": "text" }, @@ -49,7 +53,10 @@ "default_value": "vanilla", "user_viewable": true, "user_editable": true, - "rules": "required|in:vanilla,oxide,carbon", + "rules": [ + "required", + "in:vanilla,oxide,carbon" + ], "sort": 2, "field_type": "text" }, @@ -60,7 +67,11 @@ "default_value": "Procedural Map", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:20", + "rules": [ + "required", + "string", + "max:20" + ], "sort": 3, "field_type": "text" }, @@ -71,7 +82,10 @@ "default_value": "Powered by Panel", "user_viewable": true, "user_editable": true, - "rules": "required|string", + "rules": [ + "required", + "string" + ], "sort": 4, "field_type": "text" }, @@ -82,7 +96,10 @@ "default_value": "http:\/\/example.com", "user_viewable": true, "user_editable": true, - "rules": "nullable|url", + "rules": [ + "nullable", + "url" + ], "sort": 5, "field_type": "text" }, @@ -93,7 +110,10 @@ "default_value": "3000", "user_viewable": true, "user_editable": true, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 6, "field_type": "text" }, @@ -104,7 +124,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 7, "field_type": "text" }, @@ -115,7 +138,10 @@ "default_value": "40", "user_viewable": true, "user_editable": true, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 8, "field_type": "text" }, @@ -126,7 +152,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|url", + "rules": [ + "nullable", + "url" + ], "sort": 9, "field_type": "text" }, @@ -137,7 +166,10 @@ "default_value": "27017", "user_viewable": true, "user_editable": false, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 10, "field_type": "text" }, @@ -148,7 +180,10 @@ "default_value": "28016", "user_viewable": true, "user_editable": false, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 11, "field_type": "text" }, @@ -159,7 +194,11 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^[\\w.-]*$\/|max:64", + "rules": [ + "required", + "regex:\/^[\\w.-]*$\/", + "max:64" + ], "sort": 12, "field_type": "text" }, @@ -170,7 +209,10 @@ "default_value": "60", "user_viewable": true, "user_editable": true, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 13, "field_type": "text" }, @@ -181,7 +223,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 14, "field_type": "text" }, @@ -192,7 +237,10 @@ "default_value": "28082", "user_viewable": true, "user_editable": false, - "rules": "required|integer", + "rules": [ + "required", + "integer" + ], "sort": 15, "field_type": "text" }, @@ -203,7 +251,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|url", + "rules": [ + "nullable", + "url" + ], "sort": 16, "field_type": "text" }, @@ -214,7 +265,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|url", + "rules": [ + "nullable", + "url" + ], "sort": 17, "field_type": "text" }, @@ -225,7 +279,11 @@ "default_value": "258550", "user_viewable": false, "user_editable": false, - "rules": "required|string|in:258550", + "rules": [ + "required", + "string", + "in:258550" + ], "sort": 18, "field_type": "text" } diff --git a/database/Seeders/eggs/source-engine/egg-counter--strike--global-offensive.json b/database/Seeders/eggs/source-engine/egg-counter--strike--global-offensive.json index 6f450834c5..1c092bd213 100644 --- a/database/Seeders/eggs/source-engine/egg-counter--strike--global-offensive.json +++ b/database/Seeders/eggs/source-engine/egg-counter--strike--global-offensive.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/source-engine\/egg-counter--strike--global-offensive.json" }, - "exported_at": "2024-07-03T14:34:03+00:00", + "exported_at": "2024-07-25T12:04:25+00:00", "name": "Counter-Strike: Global Offensive", "author": "panel@example.com", "uuid": "437c367d-06be-498f-a604-fdad135504d7", @@ -39,7 +39,11 @@ "default_value": "de_dust2", "user_viewable": true, "user_editable": true, - "rules": "required|string|alpha_dash", + "rules": [ + "required", + "string", + "alpha_dash" + ], "sort": 1, "field_type": "text" }, @@ -50,7 +54,12 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "required|string|alpha_num|size:32", + "rules": [ + "required", + "string", + "alpha_num", + "size:32" + ], "sort": 2, "field_type": "text" }, @@ -61,7 +70,11 @@ "default_value": "740", "user_viewable": false, "user_editable": false, - "rules": "required|string|max:20", + "rules": [ + "required", + "string", + "max:20" + ], "sort": 3, "field_type": "text" } diff --git a/database/Seeders/eggs/source-engine/egg-custom-source-engine-game.json b/database/Seeders/eggs/source-engine/egg-custom-source-engine-game.json index f2e8bc0884..1126e629f1 100644 --- a/database/Seeders/eggs/source-engine/egg-custom-source-engine-game.json +++ b/database/Seeders/eggs/source-engine/egg-custom-source-engine-game.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/source-engine\/egg-custom-source-engine-game.json" }, - "exported_at": "2024-07-03T14:34:04+00:00", + "exported_at": "2024-07-25T12:03:27+00:00", "name": "Custom Source Engine Game", "author": "panel@example.com", "uuid": "2a42d0c2-c0ba-4067-9a0a-9b95d77a3490", @@ -38,7 +38,11 @@ "default_value": "", "user_viewable": true, "user_editable": false, - "rules": "required|numeric|digits_between:1,6", + "rules": [ + "required", + "numeric", + "digits_between:1,6" + ], "sort": 1, "field_type": "text" }, @@ -49,7 +53,11 @@ "default_value": "", "user_viewable": true, "user_editable": false, - "rules": "required|alpha_dash|between:1,100", + "rules": [ + "required", + "alpha_dash", + "between:1,100" + ], "sort": 2, "field_type": "text" }, @@ -60,7 +68,11 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "required|string|alpha_dash", + "rules": [ + "required", + "string", + "alpha_dash" + ], "sort": 3, "field_type": "text" }, @@ -71,7 +83,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 4, "field_type": "text" }, @@ -82,7 +97,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 5, "field_type": "text" }, @@ -93,7 +111,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string", + "rules": [ + "nullable", + "string" + ], "sort": 6, "field_type": "text" } diff --git a/database/Seeders/eggs/source-engine/egg-garrys-mod.json b/database/Seeders/eggs/source-engine/egg-garrys-mod.json index 60a6c4298c..21a289cd5e 100644 --- a/database/Seeders/eggs/source-engine/egg-garrys-mod.json +++ b/database/Seeders/eggs/source-engine/egg-garrys-mod.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/source-engine\/egg-garrys-mod.json" }, - "exported_at": "2024-07-03T14:34:04+00:00", + "exported_at": "2024-07-25T12:05:02+00:00", "name": "Garrys Mod", "author": "panel@example.com", "uuid": "60ef81d4-30a2-4d98-ab64-f59c69e2f915", @@ -39,7 +39,11 @@ "default_value": "gm_flatgrass", "user_viewable": true, "user_editable": true, - "rules": "required|string|alpha_dash", + "rules": [ + "required", + "string", + "alpha_dash" + ], "sort": 1, "field_type": "text" }, @@ -50,7 +54,12 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|string|alpha_num|size:32", + "rules": [ + "nullable", + "string", + "alpha_num", + "size:32" + ], "sort": 2, "field_type": "text" }, @@ -61,7 +70,11 @@ "default_value": "4020", "user_viewable": false, "user_editable": false, - "rules": "required|string|max:20", + "rules": [ + "required", + "string", + "max:20" + ], "sort": 3, "field_type": "text" }, @@ -72,7 +85,10 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "nullable|integer", + "rules": [ + "nullable", + "integer" + ], "sort": 4, "field_type": "text" }, @@ -83,7 +99,10 @@ "default_value": "sandbox", "user_viewable": true, "user_editable": true, - "rules": "required|string", + "rules": [ + "required", + "string" + ], "sort": 5, "field_type": "text" }, @@ -94,7 +113,11 @@ "default_value": "32", "user_viewable": true, "user_editable": true, - "rules": "required|integer|max:128", + "rules": [ + "required", + "integer", + "max:128" + ], "sort": 6, "field_type": "text" }, @@ -105,7 +128,11 @@ "default_value": "22", "user_viewable": true, "user_editable": true, - "rules": "required|integer|max:100", + "rules": [ + "required", + "integer", + "max:100" + ], "sort": 7, "field_type": "text" }, @@ -116,7 +143,10 @@ "default_value": "0", "user_viewable": true, "user_editable": true, - "rules": "required|boolean", + "rules": [ + "required", + "boolean" + ], "sort": 8, "field_type": "text" } diff --git a/database/Seeders/eggs/source-engine/egg-insurgency.json b/database/Seeders/eggs/source-engine/egg-insurgency.json index b246dabbe3..1c7e1525f4 100644 --- a/database/Seeders/eggs/source-engine/egg-insurgency.json +++ b/database/Seeders/eggs/source-engine/egg-insurgency.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/source-engine\/egg-insurgency.json" }, - "exported_at": "2024-07-03T14:34:05+00:00", + "exported_at": "2024-07-25T12:05:30+00:00", "name": "Insurgency", "author": "panel@example.com", "uuid": "a5702286-655b-4069-bf1e-925c7300b61a", @@ -38,7 +38,10 @@ "default_value": "237410", "user_viewable": true, "user_editable": false, - "rules": "required|regex:\/^(237410)$\/", + "rules": [ + "required", + "regex:\/^(237410)$\/" + ], "sort": 1, "field_type": "text" }, @@ -49,7 +52,10 @@ "default_value": "sinjar", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^(\\w{1,20})$\/", + "rules": [ + "required", + "regex:\/^(\\w{1,20})$\/" + ], "sort": 2, "field_type": "text" } diff --git a/database/Seeders/eggs/source-engine/egg-team-fortress2.json b/database/Seeders/eggs/source-engine/egg-team-fortress2.json index 24795824c9..667d045559 100644 --- a/database/Seeders/eggs/source-engine/egg-team-fortress2.json +++ b/database/Seeders/eggs/source-engine/egg-team-fortress2.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/source-engine\/egg-team-fortress2.json" }, - "exported_at": "2024-07-03T14:34:06+00:00", + "exported_at": "2024-07-25T12:05:42+00:00", "name": "Team Fortress 2", "author": "panel@example.com", "uuid": "7f8eb681-b2c8-4bf8-b9f4-d79ff70b6e5d", @@ -39,7 +39,10 @@ "default_value": "232250", "user_viewable": true, "user_editable": false, - "rules": "required|in:232250", + "rules": [ + "required", + "in:232250" + ], "sort": 1, "field_type": "text" }, @@ -50,7 +53,10 @@ "default_value": "cp_dustbowl", "user_viewable": true, "user_editable": true, - "rules": "required|regex:\/^(\\w{1,20})$\/", + "rules": [ + "required", + "regex:\/^(\\w{1,20})$\/" + ], "sort": 2, "field_type": "text" }, @@ -61,7 +67,12 @@ "default_value": "", "user_viewable": true, "user_editable": true, - "rules": "required|string|alpha_num|size:32", + "rules": [ + "required", + "string", + "alpha_num", + "size:32" + ], "sort": 3, "field_type": "text" } diff --git a/database/Seeders/eggs/voice-servers/egg-mumble-server.json b/database/Seeders/eggs/voice-servers/egg-mumble-server.json index 6254b856a6..a4c02919f9 100644 --- a/database/Seeders/eggs/voice-servers/egg-mumble-server.json +++ b/database/Seeders/eggs/voice-servers/egg-mumble-server.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/voice-servers\/egg-mumble-server.json" }, - "exported_at": "2024-07-03T14:34:07+00:00", + "exported_at": "2024-07-25T12:05:52+00:00", "name": "Mumble Server", "author": "panel@example.com", "uuid": "727ee758-7fb2-4979-972b-d3eba4e1e9f0", @@ -36,7 +36,11 @@ "default_value": "100", "user_viewable": true, "user_editable": false, - "rules": "required|numeric|digits_between:1,5", + "rules": [ + "required", + "numeric", + "digits_between:1,5" + ], "sort": 1, "field_type": "text" } diff --git a/database/Seeders/eggs/voice-servers/egg-teamspeak3-server.json b/database/Seeders/eggs/voice-servers/egg-teamspeak3-server.json index 949d6a03dc..0543a16c04 100644 --- a/database/Seeders/eggs/voice-servers/egg-teamspeak3-server.json +++ b/database/Seeders/eggs/voice-servers/egg-teamspeak3-server.json @@ -4,7 +4,7 @@ "version": "PTDL_v2", "update_url": "https:\/\/github.com\/pelican-dev\/panel\/raw\/main\/database\/Seeders\/eggs\/voice-servers\/egg-teamspeak3-server.json" }, - "exported_at": "2024-07-03T14:34:08+00:00", + "exported_at": "2024-07-25T12:06:05+00:00", "name": "Teamspeak3 Server", "author": "panel@example.com", "uuid": "983b1fac-d322-4d5f-a636-436127326b37", @@ -36,7 +36,11 @@ "default_value": "latest", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:6", + "rules": [ + "required", + "string", + "max:6" + ], "sort": 1, "field_type": "text" }, @@ -47,7 +51,11 @@ "default_value": "30033", "user_viewable": true, "user_editable": false, - "rules": "required|integer|between:1025,65535", + "rules": [ + "required", + "integer", + "between:1025,65535" + ], "sort": 2, "field_type": "text" }, @@ -58,7 +66,11 @@ "default_value": "10011", "user_viewable": true, "user_editable": false, - "rules": "required|integer|between:1025,65535", + "rules": [ + "required", + "integer", + "between:1025,65535" + ], "sort": 3, "field_type": "text" }, @@ -69,7 +81,11 @@ "default_value": "raw,http,ssh", "user_viewable": true, "user_editable": true, - "rules": "required|string|max:12", + "rules": [ + "required", + "string", + "max:12" + ], "sort": 4, "field_type": "text" }, @@ -80,7 +96,11 @@ "default_value": "10022", "user_viewable": true, "user_editable": false, - "rules": "required|integer|between:1025,65535", + "rules": [ + "required", + "integer", + "between:1025,65535" + ], "sort": 5, "field_type": "text" }, @@ -91,7 +111,11 @@ "default_value": "10080", "user_viewable": true, "user_editable": false, - "rules": "required|integer|between:1025,65535", + "rules": [ + "required", + "integer", + "between:1025,65535" + ], "sort": 6, "field_type": "text" } diff --git a/database/migrations/2024_07_25_072050_convert_rules_to_array.php b/database/migrations/2024_07_25_072050_convert_rules_to_array.php new file mode 100644 index 0000000000..8e6473a950 --- /dev/null +++ b/database/migrations/2024_07_25_072050_convert_rules_to_array.php @@ -0,0 +1,37 @@ +json('rules')->change(); + }); + + DB::table('egg_variables')->select(['id', 'rules'])->cursor()->each(function ($eggVariable) { + DB::table('egg_variables')->where('id', $eggVariable->id)->update(['rules' => explode('|', $eggVariable->rules)]); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('api_keys', function (Blueprint $table) { + $table->text('rules')->change(); + }); + + DB::table('egg_variables')->select(['id', 'rules'])->cursor()->each(function ($eggVariable) { + DB::table('egg_variables')->where('id', $eggVariable->id)->update(['rules' => implode('|', json_decode($eggVariable->rules))]); + }); + } +}; diff --git a/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php b/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php index 02d972fe43..e9c8af97ce 100644 --- a/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php +++ b/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php @@ -120,7 +120,7 @@ public function testEggVariableWithNullableStringIsNotRequired(): void [$user, $server] = $this->generateTestAccount(); $egg = $this->cloneEggAndVariables($server->egg); - $egg->variables()->first()->update(['rules' => 'nullable|string']); + $egg->variables()->first()->update(['rules' => ['nullable', 'string']]); $server->fill(['egg_id' => $egg->id])->save(); $server->refresh(); diff --git a/tests/Integration/Services/Servers/VariableValidatorServiceTest.php b/tests/Integration/Services/Servers/VariableValidatorServiceTest.php index 113e297624..6f49b97fb2 100644 --- a/tests/Integration/Services/Servers/VariableValidatorServiceTest.php +++ b/tests/Integration/Services/Servers/VariableValidatorServiceTest.php @@ -120,7 +120,7 @@ public function testNullableEnvironmentVariablesCanBeUsedCorrectly(): void $egg = $this->cloneEggAndVariables($this->egg); $egg->variables()->where('env_variable', '!=', 'BUNGEE_VERSION')->delete(); - $egg->variables()->update(['rules' => 'nullable|string']); + $egg->variables()->update(['rules' => ['nullable', 'string']]); $response = $this->getService()->handle($egg->id, []); $this->assertCount(1, $response);