From d9355b93b41e70c24010099bccfa86e117d8a27b Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 3 Feb 2018 12:28:39 -0600 Subject: [PATCH] Fix exception when adjusting mail settings, closes #907 --- CHANGELOG.md | 1 + .../Repository/SettingsRepositoryInterface.php | 6 +++--- .../Admin/Settings/MailSettingsFormRequest.php | 11 ++++++----- app/Repositories/Eloquent/SettingsRepository.php | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b415433d4..a5d23238b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * `[rc.1]` — Fixes exception thrown when revoking user sessions. * `[rc.1]` — Fixes exception that would occur when trying to delete allocations from a node. +* `[rc.1]` — Fixes exception thown when attempting to adjust mail settings as well as a validation error thrown afterwards. ## v0.7.0-rc.1 (Derelict Dermodactylus) ### Fixed diff --git a/app/Contracts/Repository/SettingsRepositoryInterface.php b/app/Contracts/Repository/SettingsRepositoryInterface.php index 9128e7f78..7d192c80a 100644 --- a/app/Contracts/Repository/SettingsRepositoryInterface.php +++ b/app/Contracts/Repository/SettingsRepositoryInterface.php @@ -7,13 +7,13 @@ interface SettingsRepositoryInterface extends RepositoryInterface /** * Store a new persistent setting in the database. * - * @param string $key - * @param string $value + * @param string $key + * @param string|null $value * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function set(string $key, string $value); + public function set(string $key, string $value = null); /** * Retrieve a persistent setting from the database. diff --git a/app/Http/Requests/Admin/Settings/MailSettingsFormRequest.php b/app/Http/Requests/Admin/Settings/MailSettingsFormRequest.php index 269c2f6c7..5a2e2ee8e 100644 --- a/app/Http/Requests/Admin/Settings/MailSettingsFormRequest.php +++ b/app/Http/Requests/Admin/Settings/MailSettingsFormRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Admin\Settings; +use Illuminate\Validation\Rule; use Pterodactyl\Http\Requests\Admin\AdminFormRequest; class MailSettingsFormRequest extends AdminFormRequest @@ -16,11 +17,11 @@ class MailSettingsFormRequest extends AdminFormRequest return [ 'mail:host' => 'required|string', 'mail:port' => 'required|integer|between:1,65535', - 'mail:encryption' => 'present|string|in:"",tls,ssl', - 'mail:username' => 'string|max:255', - 'mail:password' => 'string|max:255', + 'mail:encryption' => ['present', Rule::in([null, 'tls', 'ssl'])], + 'mail:username' => 'nullable|string|max:255', + 'mail:password' => 'nullable|string|max:255', 'mail:from:address' => 'required|string|email', - 'mail:from:name' => 'string|max:255', + 'mail:from:name' => 'nullable|string|max:255', ]; } @@ -31,7 +32,7 @@ class MailSettingsFormRequest extends AdminFormRequest * @param array $only * @return array */ - public function normalize($only = []) + public function normalize(array $only = null) { $keys = array_flip(array_keys($this->rules())); diff --git a/app/Repositories/Eloquent/SettingsRepository.php b/app/Repositories/Eloquent/SettingsRepository.php index dd516d68e..0d25a1b80 100644 --- a/app/Repositories/Eloquent/SettingsRepository.php +++ b/app/Repositories/Eloquent/SettingsRepository.php @@ -30,17 +30,17 @@ class SettingsRepository extends EloquentRepository implements SettingsRepositor /** * Store a new persistent setting in the database. * - * @param string $key - * @param string $value + * @param string $key + * @param string|null $value * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function set(string $key, string $value) + public function set(string $key, string $value = null) { // Clear item from the cache. $this->clearCache($key); - $this->withoutFreshModel()->updateOrCreate(['key' => $key], ['value' => $value]); + $this->withoutFreshModel()->updateOrCreate(['key' => $key], ['value' => $value ?? '']); self::$cache[$key] = $value; }