From 68e32ad9309f03152d688d91eff77475f931c380 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Mon, 13 Jun 2022 13:50:23 +0200 Subject: [PATCH] #166 - Slack and Google Calendar feature flags (#167) * slack and google calendar feature flags * cs fix * update .env.example --- .env.example | 2 ++ .../Jobs/ClearVacationRequestDaysInGoogleCalendar.php | 4 ++++ .../Jobs/SendVacationRequestDaysToGoogleCalendar.php | 4 ++++ app/Infrastructure/Slack/Channels/SlackApiChannel.php | 9 ++++++--- config/services.php | 2 ++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 0689964..4766ed1 100644 --- a/.env.example +++ b/.env.example @@ -57,11 +57,13 @@ DOCKER_INSTALL_XDEBUG=false GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +GOOGLE_CALENDAR_ENABLED=true GOOGLE_REDIRECT=http://localhost/login/google/end GOOGLE_CALENDAR_ID= LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE= SLACK_URL=https://slack.com/api +SLACK_ENABLED=true SLACK_CLIENT_TOKEN= SLACK_SIGNING_SECRET= SLACK_DEFAULT_CHANNEL="#general" diff --git a/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php b/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php index 56c042f..b03be3f 100644 --- a/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php +++ b/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php @@ -21,6 +21,10 @@ class ClearVacationRequestDaysInGoogleCalendar implements ShouldQueue 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"),