This commit is contained in:
Andras Bacsai
2023-06-20 19:08:43 +02:00
parent f648ab49f7
commit 9f0ca1cc2e
19 changed files with 226 additions and 197 deletions

View File

@@ -12,7 +12,7 @@ class EmailChannel
{
$this->bootConfigs($notifiable);
$bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients');
$bcc = $notifiable->routeNotificationForEmail('test_recipients');
if (count($bcc) === 0) {
if ($notifiable instanceof \App\Models\Team) {
$bcc = $notifiable->members()->pluck('email')->toArray();
@@ -24,8 +24,8 @@ class EmailChannel
[],
fn (Message $message) => $message
->from(
$notifiable->extra_attributes?->get('smtp_from_address'),
$notifiable->extra_attributes?->get('smtp_from_name')
data_get($notifiable, 'smtp.from_address'),
data_get($notifiable, 'smtp.from_name'),
)
->bcc($bcc)
->subject($mailMessage->subject)
@@ -38,12 +38,12 @@ class EmailChannel
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
"host" => $notifiable->extra_attributes?->get('smtp_host'),
"port" => $notifiable->extra_attributes?->get('smtp_port'),
"encryption" => $notifiable->extra_attributes?->get('smtp_encryption'),
"username" => $notifiable->extra_attributes?->get('smtp_username'),
"password" => $notifiable->extra_attributes?->get('smtp_password'),
"timeout" => $notifiable->extra_attributes?->get('smtp_timeout'),
"host" => data_get($notifiable, 'smtp.host'),
"port" => data_get($notifiable, 'smtp.port'),
"encryption" => data_get($notifiable, 'smtp.encryption'),
"username" => data_get($notifiable, 'smtp.username'),
"password" => data_get($notifiable, 'smtp.password'),
"timeout" => data_get($notifiable, 'smtp.timeout'),
"local_domain" => null,
]);
}

View File

@@ -13,23 +13,22 @@ class TransactionalEmailChannel
public function send(User $notifiable, Notification $notification): void
{
$settings = InstanceSettings::get();
if ($settings->extra_attributes?->get('smtp_enabled') !== true) {
if (data_get($settings, 'smtp.enabled') !== true) {
return;
}
$email = $notifiable->email;
if (!$email) {
return;
}
$this->bootConfigs($settings);
$this->bootConfigs();
$mailMessage = $notification->toMail($notifiable);
Mail::send(
[],
[],
fn (Message $message) => $message
->from(
$settings->extra_attributes?->get('smtp_from_address'),
$settings->extra_attributes?->get('smtp_from_name')
data_get($settings, 'smtp.from_address'),
data_get($settings, 'smtp.from_name')
)
->to($email)
->subject($mailMessage->subject)
@@ -37,7 +36,7 @@ class TransactionalEmailChannel
);
}
private function bootConfigs(InstanceSettings $settings): void
private function bootConfigs(): void
{
set_transanctional_email_settings();
}

View File

@@ -43,10 +43,15 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
public function via(object $notifiable): array
{
$channels = [];
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
$isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailDeployments = data_get($notifiable, 'smtp_notifications.deployments');
$isSubscribedToDiscordDeployments = data_get($notifiable, 'discord_notifications.deployments');
if ($isEmailEnabled && $isSubscribedToEmailDeployments) {
$channels[] = EmailChannel::class;
}
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
if ($isDiscordEnabled && $isSubscribedToDiscordDeployments) {
$channels[] = DiscordChannel::class;
}
return $channels;

View File

@@ -44,10 +44,15 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
public function via(object $notifiable): array
{
$channels = [];
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
$isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailDeployments = data_get($notifiable, 'smtp_notifications.deployments');
$isSubscribedToDiscordDeployments = data_get($notifiable, 'discord_notifications.deployments');
if ($isEmailEnabled && $isSubscribedToEmailDeployments) {
$channels[] = EmailChannel::class;
}
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
if ($isDiscordEnabled && $isSubscribedToDiscordDeployments) {
$channels[] = DiscordChannel::class;
}
return $channels;

View File

@@ -20,12 +20,21 @@ class TestNotification extends Notification implements ShouldQueue
public function via(object $notifiable): array
{
$channels = [];
if (($this->type === 'smtp' || is_null($this->type)) && $notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_smtp_test')) {
$isSmtp = $this->type === 'smtp' || is_null($this->type);
$isDiscord = $this->type === 'discord' || is_null($this->type);
$isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailTests = data_get($notifiable, 'smtp_notifications.test');
$isSubscribedToDiscordTests = data_get($notifiable, 'discord_notifications.test');
if ($isEmailEnabled && $isSubscribedToEmailTests && $isSmtp) {
$channels[] = EmailChannel::class;
}
if (($this->type === 'discord' || is_null($this->type)) && $notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_test')) {
if ($isDiscordEnabled && $isSubscribedToDiscordTests && $isDiscord) {
$channels[] = DiscordChannel::class;
}
return $channels;
}
public function toMail(): MailMessage
@@ -39,7 +48,7 @@ class TestNotification extends Notification implements ShouldQueue
public function toDiscord(): string
{
return 'This is a test Discord notification from Coolify.
[Go to your dashboard](' . base_url() . ')';
}
}