From 2c35653f8a5d86fec7663f076cd4b055c8b8d364 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Mon, 13 Jun 2022 13:36:11 +0200 Subject: [PATCH] slack and google calendar feature flags --- .../Jobs/ClearVacationRequestDaysInGoogleCalendar.php | 7 ++++++- .../Jobs/SendVacationRequestDaysToGoogleCalendar.php | 4 ++++ app/Infrastructure/Slack/Channels/SlackApiChannel.php | 9 ++++++--- config/services.php | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php b/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php index 56c042f..23d3e12 100644 --- a/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php +++ b/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php @@ -17,10 +17,15 @@ class ClearVacationRequestDaysInGoogleCalendar implements ShouldQueue public function __construct( protected VacationRequest $vacationRequest, - ) {} + ) { + } public function handle(): void { + if (!config("services.google.calendar_enabled")) { + return; + } + foreach ($this->vacationRequest->event_ids ?? [] as $eventId) { $calendarEvent = Event::find($eventId); diff --git a/app/Infrastructure/Jobs/SendVacationRequestDaysToGoogleCalendar.php b/app/Infrastructure/Jobs/SendVacationRequestDaysToGoogleCalendar.php index 9510f72..7d81886 100644 --- a/app/Infrastructure/Jobs/SendVacationRequestDaysToGoogleCalendar.php +++ b/app/Infrastructure/Jobs/SendVacationRequestDaysToGoogleCalendar.php @@ -23,6 +23,10 @@ class SendVacationRequestDaysToGoogleCalendar implements ShouldQueue public function handle(): void { + if (!config("services.google.calendar_enabled")) { + return; + } + $days = $this->vacationRequest ->vacations() ->orderBy("date") diff --git a/app/Infrastructure/Slack/Channels/SlackApiChannel.php b/app/Infrastructure/Slack/Channels/SlackApiChannel.php index b8a9e67..e67e03c 100644 --- a/app/Infrastructure/Slack/Channels/SlackApiChannel.php +++ b/app/Infrastructure/Slack/Channels/SlackApiChannel.php @@ -4,22 +4,25 @@ declare(strict_types=1); namespace Toby\Infrastructure\Slack\Channels; -use Illuminate\Http\Client\Response; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Http; use Toby\Domain\Notifications\Notifiable; class SlackApiChannel { - public function send(Notifiable $notifiable, Notification $notification): Response + public function send(Notifiable $notifiable, Notification $notification): void { + if (!config("services.slack.enabled")) { + return; + } + $baseUrl = $this->getBaseUrl(); $url = "{$baseUrl}/chat.postMessage"; $channel = $notifiable->routeNotificationFor("slack", $notification); $message = $notification->toSlack($notifiable); - return Http::withToken($this->getClientToken()) + Http::withToken($this->getClientToken()) ->post($url, array_merge($message->getPayload(), [ "channel" => $channel, ])); diff --git a/config/services.php b/config/services.php index 8940ddd..0390b8e 100644 --- a/config/services.php +++ b/config/services.php @@ -4,11 +4,13 @@ declare(strict_types=1); return [ "google" => [ + "calendar_enabled" => env("GOOGLE_CALENDAR_ENABLED", true), "client_id" => env("GOOGLE_CLIENT_ID"), "client_secret" => env("GOOGLE_CLIENT_SECRET"), "redirect" => env("GOOGLE_REDIRECT"), ], "slack" => [ + "enabled" => env("SLACK_ENABLED", true), "url" => "https://slack.com/api", "client_token" => env("SLACK_CLIENT_TOKEN"), "default_channel" => env("SLACK_DEFAULT_CHANNEL"),