Skip to content

Commit

Permalink
🐛 fix admin notification for denied events (#2840)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Aug 11, 2024
1 parent 76c4e33 commit 24e8cd9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions app/Http/Controllers/Frontend/Admin/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Validation\Rules\Enum;
use Illuminate\View\View;

Expand Down Expand Up @@ -109,20 +108,23 @@ public function denySuggestion(Request $request): RedirectResponse {
]);
$eventSuggestion = EventSuggestion::find($validated['id']);
$eventSuggestion->update(['processed' => true]);
if (!App::runningUnitTests() && config('services.telegram.admin.active')) {
Http::post(config('app.admin.notification.url'), [
'chat_id' => config('services.telegram.admin.chat_id'),
'text' => strtr("<b>Event suggestion denied</b>" . PHP_EOL .
"Title: :name" . PHP_EOL
. "Denial reason: :reason" . PHP_EOL
. "Denial user: :username" . PHP_EOL, [
':name' => $eventSuggestion->name,
':reason' => EventRejectionReason::from($validated['rejectionReason'])->getReason(),
':username' => auth()->user()->username,
]),
'parse_mode' => 'HTML',
]);
if (!App::runningUnitTests() && TelegramService::isAdminActive()) {
try {
TelegramService::admin()->sendMessage(
strtr("<b>Event suggestion denied</b>" . PHP_EOL .
"Title: :name" . PHP_EOL
. "Denial reason: :reason" . PHP_EOL
. "Denial user: :username" . PHP_EOL, [
':name' => $eventSuggestion->name,
':reason' => EventRejectionReason::from($validated['rejectionReason'])->getReason(),
':username' => auth()->user()->username,
])
);
} catch (TelegramException $exception) {
report($exception);
}
}

$eventSuggestion->user->notify(
new EventSuggestionProcessed(
$eventSuggestion,
Expand Down

0 comments on commit 24e8cd9

Please sign in to comment.