From 180ddaf3ee5fe2547385091ee1c0afdc58fe966a Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 22 Nov 2024 07:25:50 +0200 Subject: [PATCH] Removed the admin tasks from routes and added them as a Command --- app/Console/Commands/TestAdminTasks.php | 52 +++++++++++++++++++++++++ routes/web.php | 11 +++--- 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 app/Console/Commands/TestAdminTasks.php diff --git a/app/Console/Commands/TestAdminTasks.php b/app/Console/Commands/TestAdminTasks.php new file mode 100644 index 000000000..2b77e3cb3 --- /dev/null +++ b/app/Console/Commands/TestAdminTasks.php @@ -0,0 +1,52 @@ +choice('Which task would you like to test?', ['Translate service', 'Test email', 'Test Sentry error']); + + if ($task === 'Translate service') { + $this->info('Testing the translation service...'); + $texts = ['Hello', 'How are you?', 'Good morning']; + $lang_code = 'fr'; + $translations = Translator::translateTexts($texts, $lang_code); + $this->info('Translations:'); + foreach ($translations as $translation) { + $this->info($translation); + } + $this->info('API Key: ' . config('app.google_translate_key')); + } elseif ($task === 'Test email') { + $this->info('Testing the email service...'); + $email = $this->ask('Enter the email address to send the test email to:'); + User::where(['email' => $email])->first()->notify(new UserRegistered); + $this->info('The test email has been sent to ' . $email); + } elseif ($task === 'Test Sentry error') { + $this->info('Testing the Sentry error reporting service...'); + $message = $this->ask('Enter the message for the Sentry error:'); + throw new \Exception('Test Sentry error: ' . $message); + } + } +} diff --git a/routes/web.php b/routes/web.php index 0dad0bc80..c74e1f71c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,9 +13,6 @@ use App\Http\Controllers\Solution\SolutionController; use App\Http\Controllers\User\AdminController; use App\Http\Controllers\User\UserController; -use App\Models\User\User; -use App\Notifications\UserRegistered; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; @@ -68,9 +65,11 @@ Route::get('/communication/mailchimp', [CommunicationController::class, 'getMailChimpIntegration'])->name('mailchimp-integration.get'); Route::post('/communication/mailchimp', [CommunicationController::class, 'storeMailChimpListsIds'])->name('mailchimp-integration'); }); - Route::get('/test-sentry/{message}', fn (Request $request) => throw new Exception('Test Sentry error: ' . $request->message)); - Route::get('/phpinfo', fn () => phpinfo()); - Route::get('/test-email/{email}', fn (Request $request) => User::where(['email' => $request->email])->first()->notify(new UserRegistered) && 'Success! Email sent to: ' . $request->email); + Route::middleware(['throttle:api-public'])->group(function () { + Route::group(['prefix' => 'admin'], function () { + Route::get('/phpinfo', fn () => phpinfo()); + }); + }); }); Route::group(['middleware' => ['auth', 'can:manage-platform-content']], function () use ($localeInfo, $backOfficePrefix) {