slack and google calendar feature flags

This commit is contained in:
Adrian Hopek 2022-06-13 13:36:11 +02:00
parent 31a6d287c8
commit 2c35653f8a
4 changed files with 18 additions and 4 deletions

View File

@ -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);

View File

@ -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")

View File

@ -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,
]));

View File

@ -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"),