refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Notifications\Application;
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeployedWithErrorNotification extends Notification implements ShouldQueue
|
||||
class DeploymentFailed extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
@@ -69,7 +69,7 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
|
||||
$mail->subject('❌ Pull request #' . $this->preview->pull_request_id . ' of ' . $this->application_name . ' deployment failed.');
|
||||
}
|
||||
|
||||
$mail->view('emails.application-deployed-with-error', [
|
||||
$mail->view('emails.application-deployment-failed', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'deployment_url' => $this->deployment_url,
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Notifications\Application;
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeployedSuccessfullyNotification extends Notification implements ShouldQueue
|
||||
class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
@@ -67,7 +67,7 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
|
||||
$fqdn = $this->preview->fqdn;
|
||||
$mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully");
|
||||
}
|
||||
$mail->view('emails.application-deployed-successfully', [
|
||||
$mail->view('emails.application-deployment-success', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'deployment_url' => $this->deployment_url,
|
||||
@@ -97,4 +97,4 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Notifications\Application;
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ApplicationStoppedNotification extends Notification implements ShouldQueue
|
||||
class StatusChanged extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
@@ -56,7 +56,7 @@ class ApplicationStoppedNotification extends Notification implements ShouldQueue
|
||||
$mail = new MailMessage();
|
||||
$fqdn = $this->fqdn;
|
||||
$mail->subject("⛔ {$this->application_name} has been stopped");
|
||||
$mail->view('emails.application-stopped', [
|
||||
$mail->view('emails.application-status-changes', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'application_url' => $this->application_url,
|
||||
@@ -72,4 +72,4 @@ class ApplicationStoppedNotification extends Notification implements ShouldQueue
|
||||
$message .= '[Application URL](' . $this->application_url . ')';
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ class EmailChannel
|
||||
public function send(SendsEmail $notifiable, Notification $notification): void
|
||||
{
|
||||
$this->bootConfigs($notifiable);
|
||||
ray($notification);
|
||||
$recepients = $notifiable->getRecepients($notification);
|
||||
|
||||
$bcc = $notifiable->routeNotificationForEmail('test_recipients');
|
||||
if (count($bcc) === 0) {
|
||||
if ($notifiable instanceof \App\Models\Team) {
|
||||
$bcc = $notifiable->members()->pluck('email')->toArray();
|
||||
}
|
||||
if (count($recepients) === 0) {
|
||||
throw new \Exception('No email recipients found');
|
||||
}
|
||||
|
||||
$mailMessage = $notification->toMail($notifiable);
|
||||
Mail::send(
|
||||
[],
|
||||
@@ -27,7 +27,7 @@ class EmailChannel
|
||||
data_get($notifiable, 'smtp_from_address'),
|
||||
data_get($notifiable, 'smtp_from_name'),
|
||||
)
|
||||
->bcc($bcc)
|
||||
->bcc($recepients)
|
||||
->subject($mailMessage->subject)
|
||||
->html((string)$mailMessage->render())
|
||||
);
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace App\Notifications\Channels;
|
||||
|
||||
interface SendsEmail
|
||||
{
|
||||
public function routeNotificationForEmail();
|
||||
}
|
||||
public function getRecepients($notification);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Notifications;
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Notifications\Channels\EmailChannel;
|
||||
use App\Notifications\Channels\DiscordChannel;
|
||||
@@ -9,30 +9,25 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TestNotification extends Notification implements ShouldQueue
|
||||
class Test extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public string|null $type = null;
|
||||
public function __construct(string|null $type = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
public function __construct(public string|null $emails = null)
|
||||
{}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
|
||||
$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');
|
||||
|
||||
if ($isEmailEnabled && $isSmtp) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($isDiscordEnabled && $isDiscord) {
|
||||
if ($isDiscordEnabled && empty($this->emails)) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
|
||||
if ($isEmailEnabled && !empty($this->emails)) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
}
|
||||
public function toMail(): MailMessage
|
||||
@@ -42,7 +37,6 @@ class TestNotification extends Notification implements ShouldQueue
|
||||
$mail->view('emails.test');
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function toDiscord(): string
|
||||
{
|
||||
$message = 'This is a test Discord notification from Coolify.';
|
||||
@@ -11,7 +11,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class InvitationLinkEmail extends Notification implements ShouldQueue
|
||||
class InvitationLink extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public function via()
|
||||
@@ -33,4 +33,4 @@ class InvitationLinkEmail extends Notification implements ShouldQueue
|
||||
]);
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
}
|
||||
83
app/Notifications/TransactionalEmails/ResetPassword.php
Normal file
83
app/Notifications/TransactionalEmails/ResetPassword.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\TransactionalEmails;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use App\Models\InstanceSettings;
|
||||
|
||||
class ResetPassword extends Notification
|
||||
{
|
||||
public $token;
|
||||
public InstanceSettings $settings;
|
||||
public static $createUrlCallback;
|
||||
public static $toMailCallback;
|
||||
|
||||
public function __construct($token)
|
||||
{
|
||||
$this->settings = InstanceSettings::get();
|
||||
$this->token = $token;
|
||||
}
|
||||
public function via($notifiable)
|
||||
{
|
||||
if ($this->settings->smtp_enabled){
|
||||
$password = data_get($this->settings, 'smtp_password');
|
||||
if ($password) $password = decrypt($password);
|
||||
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
"transport" => "smtp",
|
||||
"host" => data_get($this->settings, 'smtp_host'),
|
||||
"port" => data_get($this->settings, 'smtp_port'),
|
||||
"encryption" => data_get($this->settings, 'smtp_encryption'),
|
||||
"username" => data_get($this->settings, 'smtp_username'),
|
||||
"password" => $password,
|
||||
"timeout" => data_get($this->settings, 'smtp_timeout'),
|
||||
"local_domain" => null,
|
||||
]);
|
||||
return ['mail'];
|
||||
}
|
||||
throw new \Exception('SMTP is not enabled');
|
||||
|
||||
}
|
||||
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
if (static::$toMailCallback) {
|
||||
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
|
||||
}
|
||||
|
||||
return $this->buildMailMessage($this->resetUrl($notifiable));
|
||||
}
|
||||
protected function buildMailMessage($url)
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$mail->from(
|
||||
data_get($this->settings, 'smtp_from_address'),
|
||||
data_get($this->settings, 'smtp_from_name'),
|
||||
);
|
||||
$mail->subject('Reset Password');
|
||||
$mail->view('emails.reset-password', ['url' => $url,'count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]);
|
||||
return $mail;
|
||||
}
|
||||
protected function resetUrl($notifiable)
|
||||
{
|
||||
if (static::$createUrlCallback) {
|
||||
return call_user_func(static::$createUrlCallback, $notifiable, $this->token);
|
||||
}
|
||||
|
||||
return url(route('password.reset', [
|
||||
'token' => $this->token,
|
||||
'email' => $notifiable->getEmailForPasswordReset(),
|
||||
], false));
|
||||
}
|
||||
public static function createUrlUsing($callback)
|
||||
{
|
||||
static::$createUrlCallback = $callback;
|
||||
}
|
||||
public static function toMailUsing($callback)
|
||||
{
|
||||
static::$toMailCallback = $callback;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,18 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TestEmail extends Notification implements ShouldQueue
|
||||
class Test extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(public string $emails)
|
||||
{}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [EmailChannel::class];
|
||||
}
|
||||
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
@@ -22,4 +27,4 @@ class TestEmail extends Notification implements ShouldQueue
|
||||
$mail->view('emails.test');
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user