From 8eede367a18d2b1b3658b5495759b721b0324777 Mon Sep 17 00:00:00 2001 From: "Anthony M. Powers" Date: Wed, 26 Jan 2022 07:24:36 -0800 Subject: [PATCH] feat: allow clearing Discord Connector oAuth Fields (#67) * If you clear all fields, reset the setting. * Invert logic (woops!) --- src/Http/Controllers/SettingsController.php | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Http/Controllers/SettingsController.php b/src/Http/Controllers/SettingsController.php index 555992d..0d56d6f 100644 --- a/src/Http/Controllers/SettingsController.php +++ b/src/Http/Controllers/SettingsController.php @@ -22,6 +22,7 @@ namespace Warlof\Seat\Connector\Drivers\Discord\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Validation\ValidationException; use Laravel\Socialite\Facades\Socialite; use Seat\Web\Http\Controllers\Controller; use SocialiteProviders\Manager\Config; @@ -51,15 +52,24 @@ class SettingsController extends Controller * @param \Illuminate\Http\Request $request * @return mixed * @throws \Seat\Services\Exceptions\SettingException + * @throws \Illuminate\Validation\ValidationException */ public function store(Request $request) { - $request->validate([ - 'client_id' => 'required|string', - 'client_secret' => 'required|string', - 'bot_token' => 'required|string', - 'use_email_scope' => 'boolean', - ]); + try { + $request->validate([ + 'client_id' => 'required|string', + 'client_secret' => 'required|string', + 'bot_token' => 'required|string', + 'use_email_scope' => 'boolean', + ]); + } catch(ValidationException $e) { + if ($request->anyFilled(['client_id', 'client_secret', 'bot_token'])) { + throw $e; + } else { + setting(['seat-connector.drivers.discord', null], true); + } + } $settings = (object) [ 'client_id' => $request->input('client_id'),