Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: test notifications to only send it to the right channel

Andras Bacsaib44296597697
diff --git a/app/Livewire/Notifications/Discord.php b/app/Livewire/Notifications/Discord.php
index c09966e53b..57007813ee 100644
--- a/app/Livewire/Notifications/Discord.php
+++ b/app/Livewire/Notifications/Discord.php
@@ -154,7 +154,7 @@ class Discord extends Component
public function sendTestNotification()
{
try {
- $this->team->notify(new Test);
+ $this->team->notify(new Test(channel: 'discord'));
$this->dispatch('success', 'Test notification sent.');
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.php
index dc5a35d669..dc2a95e845 100644
--- a/app/Livewire/Notifications/Email.php
+++ b/app/Livewire/Notifications/Email.php
@@ -106,6 +106,7 @@ class Email extends Component
$this->emails = auth()->user()->email;
$this->settings = $this->team->emailNotificationSettings;
$this->syncData();
+ $this->testEmailAddress = auth()->user()->email;
} catch (\Throwable $e) {
return handleError($e, $this);
}
@@ -317,7 +318,7 @@ class Email extends Component
'test-email:'.$this->team->id,
$perMinute = 0,
function () {
- $this->team?->notify(new Test($this->testEmailAddress));
+ $this->team?->notify(new Test($this->testEmailAddress, 'email'));
$this->dispatch('success', 'Test Email sent.');
},
$decaySeconds = 10,
diff --git a/app/Livewire/Notifications/Slack.php b/app/Livewire/Notifications/Slack.php
index 91f05f42fe..97464fa1c9 100644
--- a/app/Livewire/Notifications/Slack.php
+++ b/app/Livewire/Notifications/Slack.php
@@ -154,7 +154,7 @@ class Slack extends Component
public function sendTestNotification()
{
try {
- $this->team->notify(new Test);
+ $this->team->notify(new Test(channel: 'slack'));
$this->dispatch('success', 'Test notification sent.');
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/app/Livewire/Notifications/Telegram.php b/app/Livewire/Notifications/Telegram.php
index d425fd2625..de2fa9cdc4 100644
--- a/app/Livewire/Notifications/Telegram.php
+++ b/app/Livewire/Notifications/Telegram.php
@@ -223,7 +223,7 @@ class Telegram extends Component
public function sendTestNotification()
{
try {
- $this->team->notify(new Test);
+ $this->team->notify(new Test(channel: 'telegram'));
$this->dispatch('success', 'Test notification sent.');
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/app/Livewire/SettingsEmail.php b/app/Livewire/SettingsEmail.php
index 4636a3b25d..1c5edb108a 100644
--- a/app/Livewire/SettingsEmail.php
+++ b/app/Livewire/SettingsEmail.php
@@ -3,8 +3,10 @@
namespace App\Livewire;
use App\Models\InstanceSettings;
+use App\Models\Team;
use App\Notifications\Test;
use Illuminate\Support\Facades\RateLimiter;
+use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
@@ -12,6 +14,9 @@ class SettingsEmail extends Component
{
public InstanceSettings $settings;
+ #[Locked]
+ public Team $team;
+
#[Validate(['boolean'])]
public bool $smtpEnabled = false;
@@ -58,6 +63,8 @@ class SettingsEmail extends Component
}
$this->settings = instanceSettings();
$this->syncData();
+ $this->team = auth()->user()->currentTeam();
+ $this->testEmailAddress = auth()->user()->email;
}
public function syncData(bool $toModel = false)
@@ -219,7 +226,7 @@ class SettingsEmail extends Component
'test-email:'.$this->team->id,
$perMinute = 0,
function () {
- $this->team?->notify(new Test($this->testEmailAddress));
+ $this->team?->notify(new Test($this->testEmailAddress, 'email'));
$this->dispatch('success', 'Test Email sent.');
},
$decaySeconds = 10,
diff --git a/app/Notifications/Test.php b/app/Notifications/Test.php
index 7ae1c52860..da90985008 100644
--- a/app/Notifications/Test.php
+++ b/app/Notifications/Test.php
@@ -2,7 +2,10 @@
namespace App\Notifications;
+use App\Notifications\Channels\DiscordChannel;
use App\Notifications\Channels\EmailChannel;
+use App\Notifications\Channels\SlackChannel;
+use App\Notifications\Channels\TelegramChannel;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Bus\Queueable;
@@ -17,14 +20,26 @@ class Test extends Notification implements ShouldQueue
public $tries = 5;
- public function __construct(public ?string $emails = null)
+ public function __construct(public ?string $emails = null, public ?string $channel = null)
{
$this->onQueue('high');
}
public function via(object $notifiable): array
{
- return $notifiable->getEnabledChannels('test');
+ if ($this->channel) {
+ $channels = match ($this->channel) {
+ 'email' => [EmailChannel::class],
+ 'discord' => [DiscordChannel::class],
+ 'telegram' => [TelegramChannel::class],
+ 'slack' => [SlackChannel::class],
+ default => [],
+ };
+ } else {
+ $channels = $notifiable->getEnabledChannels('test');
+ }
+
+ return $channels;
}
public function middleware(object $notifiable, string $channel)
diff --git a/resources/views/livewire/settings-email.blade.php b/resources/views/livewire/settings-email.blade.php
index 81ee4878e6..19c77971cd 100644
--- a/resources/views/livewire/settings-email.blade.php
+++ b/resources/views/livewire/settings-email.blade.php
@@ -1,78 +1,81 @@
<div>
<x-slot:title>
Transactional Email | Coolify
- </x-slot>
- <x-settings.navbar />
- <form wire:submit='submit' class="flex flex-col gap-2 pb-4">
- <div class="flex items-center gap-2">
- <h2>Transactional Email</h2>
- <x-forms.button type="submit">
- Save
- </x-forms.button>
- @if (is_transactional_emails_enabled() && auth()->user()->isAdminFromSession())
+ </x-slot>
+ <x-settings.navbar />
+ <form wire:submit='submit' class="flex flex-col gap-2 pb-4">
+ <div class="flex items-center gap-2">
+ <h2>Transactional Email</h2>
+ <x-forms.button type="submit">
+ Save
+ </x-forms.button>
+ @if (is_transactional_emails_enabled() && auth()->user()->isAdminFromSession())
<x-modal-input buttonTitle="Send Test Email" title="Send Test Email">
<form wire:submit.prevent="sendTestEmail" class="flex flex-col w-full gap-2">
- <x-forms.input wire:model="testEmailAddress" placeholder="[email protected]" id="testEmailAddress" label="Recipients" required />
+ <x-forms.input wire:model="testEmailAddress" placeholder="[email protected]" id="testEmailAddress"
+ label="Recipients" required />
<x-forms.button type="submit" @click="modalOpen=false">
Send Email
</x-forms.button>
</form>
</x-modal-input>
- @endif
- </div>
- <div class="pb-4">Instance wide email settings for password resets, invitations, etc.</div>
- <div class="flex gap-4">
- <x-forms.input required id="smtpFromName" helper="Name used in emails." label="From Name" />
- <x-forms.input required id="smtpFromAddress" helper="Email address used in emails." label="From Address" />
- </div>
- </form>
- <div class="flex flex-col gap-4">
- <div class="p-4 border dark:border-coolgray-300">
- <form wire:submit.prevent="submitSmtp" class="flex flex-col">
- <div class="flex gap-2">
- <h3>SMTP Server</h3>
- <x-forms.button type="submit">
- Save
- </x-forms.button>
- </div>
- <div class="w-32">
- <x-forms.checkbox instantSave='instantSave("SMTP")' id="smtpEnabled" label="Enabled" />
- </div>
- <div class="flex flex-col gap-4">
- <div class="flex flex-col w-full gap-2 xl:flex-row">
- <x-forms.input required id="smtpHost" placeholder="smtp.mailgun.org" label="Host" />
- <x-forms.input required id="smtpPort" placeholder="587" label="Port" />
- <x-forms.select id="smtpEncryption" label="Encryption">
- <option value="tls">TLS</option>
- <option value="ssl">SSL</option>
- <option value="none">None</option>
- </x-forms.select>
- </div>
- <div class="flex flex-col w-full gap-2 xl:flex-row">
- <x-forms.input id="smtpUsername" label="SMTP Username" />
- <x-forms.input id="smtpPassword" type="password" label="SMTP Password" autocomplete="new-password" />
- <x-forms.input id="smtpTimeout" helper="Timeout value for sending emails." label="Timeout" />
- </div>
- </div>
- </form>
- </div>
- <div class="p-4 border dark:border-coolgray-300">
- <form wire:submit.prevent="submitResend" class="flex flex-col">
- <div class="flex gap-2">
- <h3>Resend</h3>
- <x-forms.button type="submit">
- Save
- </x-forms.button>
+ @endif
+ </div>
+ <div class="pb-4">Instance wide email settings for password resets, invitations, etc.</div>
+ <div class="flex gap-4">
+ <x-forms.input required id="smtpFromName" helper="Name used in emails." label="From Name" />
+ <x-forms.input required id="smtpFromAddress" helper="Email address used in emails." label="From Address" />
+ </div>
+ </form>
+ <div class="flex flex-col gap-4">
+ <div class="p-4 border dark:border-coolgray-300">
+ <form wire:submit.prevent="submitSmtp" class="flex flex-col">
+ <div class="flex gap-2">
+ <h3>SMTP Server</h3>
+ <x-forms.button type="submit">
+ Save
+ </x-forms.button>
+ </div>
+ <div class="w-32">
+ <x-forms.checkbox instantSave='instantSave("SMTP")' id="smtpEnabled" label="Enabled" />
+ </div>
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col w-full gap-2 xl:flex-row">
+ <x-forms.input required id="smtpHost" placeholder="smtp.mailgun.org" label="Host" />
+ <x-forms.input required id="smtpPort" placeholder="587" label="Port" />
+ <x-forms.select id="smtpEncryption" label="Encryption">
+ <option value="tls">TLS</option>
+ <option value="ssl">SSL</option>
+ <option value="none">None</option>
+ </x-forms.select>
</div>
- <div class="w-32">
- <x-forms.checkbox instantSave='instantSave("Resend")' id="resendEnabled" label="Enabled" />
+ <div class="flex flex-col w-full gap-2 xl:flex-row">
+ <x-forms.input id="smtpUsername" label="SMTP Username" />
+ <x-forms.input id="smtpPassword" type="password" label="SMTP Password"
+ autocomplete="new-password" />
+ <x-forms.input id="smtpTimeout" helper="Timeout value for sending emails." label="Timeout" />
</div>
- <div class="flex flex-col gap-4">
- <div class="flex flex-col w-full gap-2 xl:flex-row">
- <x-forms.input type="password" id="resendApiKey" placeholder="API key" required label="API Key" autocomplete="new-password" />
- </div>
+ </div>
+ </form>
+ </div>
+ <div class="p-4 border dark:border-coolgray-300">
+ <form wire:submit.prevent="submitResend" class="flex flex-col">
+ <div class="flex gap-2">
+ <h3>Resend</h3>
+ <x-forms.button type="submit">
+ Save
+ </x-forms.button>
+ </div>
+ <div class="w-32">
+ <x-forms.checkbox instantSave='instantSave("Resend")' id="resendEnabled" label="Enabled" />
+ </div>
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col w-full gap-2 xl:flex-row">
+ <x-forms.input type="password" id="resendApiKey" placeholder="API key" required label="API Key"
+ autocomplete="new-password" />
</div>
- </form>
- </div>
+ </div>
+ </form>
</div>
+ </div>
</div>