diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.php index ab3768643..d81535a80 100644 --- a/app/Livewire/Notifications/Email.php +++ b/app/Livewire/Notifications/Email.php @@ -19,9 +19,6 @@ class Email extends Component #[Validate(['boolean'])] public bool $smtpEnabled = false; - #[Validate(['boolean'])] - public bool $useInstanceEmailSettings = false; - #[Validate(['nullable', 'email'])] public ?string $smtpFromAddress = null; @@ -50,29 +47,47 @@ class Email extends Component public ?int $smtpTimeout = null; #[Validate(['boolean'])] - public bool $smtpNotificationsTest = false; - - #[Validate(['boolean'])] - public bool $smtpNotificationsDeployments = false; - - #[Validate(['boolean'])] - public bool $smtpNotificationsStatusChanges = false; - - #[Validate(['boolean'])] - public bool $smtpNotificationsDatabaseBackups = false; - - #[Validate(['boolean'])] - public bool $smtpNotificationsScheduledTasks = false; - - #[Validate(['boolean'])] - public bool $smtpNotificationsServerDiskUsage = false; - - #[Validate(['boolean'])] - public bool $resendEnabled; + public bool $resendEnabled = false; #[Validate(['nullable', 'string'])] public ?string $resendApiKey = null; + #[Validate(['boolean'])] + public bool $useInstanceEmailSettings = false; + + #[Validate(['boolean'])] + public bool $deploymentSuccessEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $deploymentFailureEmailNotifications = true; + + #[Validate(['boolean'])] + public bool $statusChangeEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $backupSuccessEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $backupFailureEmailNotifications = true; + + #[Validate(['boolean'])] + public bool $scheduledTaskSuccessEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $scheduledTaskFailureEmailNotifications = true; + + #[Validate(['boolean'])] + public bool $dockerCleanupEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $serverDiskUsageEmailNotifications = true; + + #[Validate(['boolean'])] + public bool $serverReachableEmailNotifications = false; + + #[Validate(['boolean'])] + public bool $serverUnreachableEmailNotifications = true; + #[Validate(['nullable', 'email'])] public ?string $testEmailAddress = null; @@ -91,47 +106,67 @@ class Email extends Component { if ($toModel) { $this->validate(); - $this->team->smtp_enabled = $this->smtpEnabled; - $this->team->smtp_from_address = $this->smtpFromAddress; - $this->team->smtp_from_name = $this->smtpFromName; - $this->team->smtp_host = $this->smtpHost; - $this->team->smtp_port = $this->smtpPort; - $this->team->smtp_encryption = $this->smtpEncryption; - $this->team->smtp_username = $this->smtpUsername; - $this->team->smtp_password = $this->smtpPassword; - $this->team->smtp_timeout = $this->smtpTimeout; - $this->team->smtp_recipients = $this->smtpRecipients; - $this->team->smtp_notifications_test = $this->smtpNotificationsTest; - $this->team->smtp_notifications_deployments = $this->smtpNotificationsDeployments; - $this->team->smtp_notifications_status_changes = $this->smtpNotificationsStatusChanges; - $this->team->smtp_notifications_database_backups = $this->smtpNotificationsDatabaseBackups; - $this->team->smtp_notifications_scheduled_tasks = $this->smtpNotificationsScheduledTasks; - $this->team->smtp_notifications_server_disk_usage = $this->smtpNotificationsServerDiskUsage; - $this->team->use_instance_email_settings = $this->useInstanceEmailSettings; - $this->team->resend_enabled = $this->resendEnabled; - $this->team->resend_api_key = $this->resendApiKey; - $this->team->save(); + $settings = $this->team->emailNotificationSettings; + $settings->smtp_enabled = $this->smtpEnabled; + $settings->smtp_from_address = $this->smtpFromAddress; + $settings->smtp_from_name = $this->smtpFromName; + $settings->smtp_recipients = $this->smtpRecipients; + $settings->smtp_host = $this->smtpHost; + $settings->smtp_port = $this->smtpPort; + $settings->smtp_encryption = $this->smtpEncryption; + $settings->smtp_username = $this->smtpUsername; + $settings->smtp_password = $this->smtpPassword; + $settings->smtp_timeout = $this->smtpTimeout; + + $settings->resend_enabled = $this->resendEnabled; + $settings->resend_api_key = $this->resendApiKey; + + $settings->use_instance_email_settings = $this->useInstanceEmailSettings; + + $settings->deployment_success_email_notifications = $this->deploymentSuccessEmailNotifications; + $settings->deployment_failure_email_notifications = $this->deploymentFailureEmailNotifications; + $settings->status_change_email_notifications = $this->statusChangeEmailNotifications; + $settings->backup_success_email_notifications = $this->backupSuccessEmailNotifications; + $settings->backup_failure_email_notifications = $this->backupFailureEmailNotifications; + $settings->scheduled_task_success_email_notifications = $this->scheduledTaskSuccessEmailNotifications; + $settings->scheduled_task_failure_email_notifications = $this->scheduledTaskFailureEmailNotifications; + $settings->docker_cleanup_email_notifications = $this->dockerCleanupEmailNotifications; + $settings->server_disk_usage_email_notifications = $this->serverDiskUsageEmailNotifications; + $settings->server_reachable_email_notifications = $this->serverReachableEmailNotifications; + $settings->server_unreachable_email_notifications = $this->serverUnreachableEmailNotifications; + + $settings->save(); refreshSession(); } else { - $this->smtpEnabled = $this->team->smtp_enabled; - $this->smtpFromAddress = $this->team->smtp_from_address; - $this->smtpFromName = $this->team->smtp_from_name; - $this->smtpHost = $this->team->smtp_host; - $this->smtpPort = $this->team->smtp_port; - $this->smtpEncryption = $this->team->smtp_encryption; - $this->smtpUsername = $this->team->smtp_username; - $this->smtpPassword = $this->team->smtp_password; - $this->smtpTimeout = $this->team->smtp_timeout; - $this->smtpRecipients = $this->team->smtp_recipients; - $this->smtpNotificationsTest = $this->team->smtp_notifications_test; - $this->smtpNotificationsDeployments = $this->team->smtp_notifications_deployments; - $this->smtpNotificationsStatusChanges = $this->team->smtp_notifications_status_changes; - $this->smtpNotificationsDatabaseBackups = $this->team->smtp_notifications_database_backups; - $this->smtpNotificationsScheduledTasks = $this->team->smtp_notifications_scheduled_tasks; - $this->smtpNotificationsServerDiskUsage = $this->team->smtp_notifications_server_disk_usage; - $this->useInstanceEmailSettings = $this->team->use_instance_email_settings; - $this->resendEnabled = $this->team->resend_enabled; - $this->resendApiKey = $this->team->resend_api_key; + $settings = $this->team->emailNotificationSettings; + + $this->smtpEnabled = $settings->smtp_enabled; + $this->smtpFromAddress = $settings->smtp_from_address; + $this->smtpFromName = $settings->smtp_from_name; + $this->smtpRecipients = $settings->smtp_recipients; + $this->smtpHost = $settings->smtp_host; + $this->smtpPort = $settings->smtp_port; + $this->smtpEncryption = $settings->smtp_encryption; + $this->smtpUsername = $settings->smtp_username; + $this->smtpPassword = $settings->smtp_password; + $this->smtpTimeout = $settings->smtp_timeout; + + $this->resendEnabled = $settings->resend_enabled; + $this->resendApiKey = $settings->resend_api_key; + + $this->useInstanceEmailSettings = $settings->use_instance_email_settings; + + $this->deploymentSuccessEmailNotifications = $settings->deployment_success_email_notifications; + $this->deploymentFailureEmailNotifications = $settings->deployment_failure_email_notifications; + $this->statusChangeEmailNotifications = $settings->status_change_email_notifications; + $this->backupSuccessEmailNotifications = $settings->backup_success_email_notifications; + $this->backupFailureEmailNotifications = $settings->backup_failure_email_notifications; + $this->scheduledTaskSuccessEmailNotifications = $settings->scheduled_task_success_email_notifications; + $this->scheduledTaskFailureEmailNotifications = $settings->scheduled_task_failure_email_notifications; + $this->dockerCleanupEmailNotifications = $settings->docker_cleanup_email_notifications; + $this->serverDiskUsageEmailNotifications = $settings->server_disk_usage_email_notifications; + $this->serverReachableEmailNotifications = $settings->server_reachable_email_notifications; + $this->serverUnreachableEmailNotifications = $settings->server_unreachable_email_notifications; } } @@ -178,13 +213,26 @@ class Email extends Component { try { $this->validate([ - 'smtpHost' => 'required', + 'smtpEnabled' => 'boolean', + 'smtpFromAddress' => 'required|email', + 'smtpFromName' => 'required|string', + 'smtpHost' => 'required|string', 'smtpPort' => 'required|numeric', + 'smtpEncryption' => 'required|string|in:tls,ssl,none', + 'smtpUsername' => 'nullable|string', + 'smtpPassword' => 'nullable|string', + 'smtpTimeout' => 'nullable|numeric', ], [ + 'smtpFromAddress.required' => 'From Address is required.', + 'smtpFromAddress.email' => 'Please enter a valid email address.', + 'smtpFromName.required' => 'From Name is required.', 'smtpHost.required' => 'SMTP Host is required.', 'smtpPort.required' => 'SMTP Port is required.', + 'smtpPort.numeric' => 'SMTP Port must be a number.', + 'smtpEncryption.required' => 'Encryption type is required.', ]); $this->resendEnabled = false; + $this->useInstanceEmailSettings = false; $this->saveModel(); } catch (\Throwable $e) { $this->smtpEnabled = false; @@ -197,11 +245,18 @@ class Email extends Component { try { $this->validate([ - 'resendApiKey' => 'required', + 'resendEnabled' => 'boolean', + 'resendApiKey' => 'required|string', + 'smtpFromAddress' => 'required|email', + 'smtpFromName' => 'required|string', ], [ 'resendApiKey.required' => 'Resend API Key is required.', + 'smtpFromAddress.required' => 'From Address is required.', + 'smtpFromAddress.email' => 'Please enter a valid email address.', + 'smtpFromName.required' => 'From Name is required.', ]); $this->smtpEnabled = false; + $this->useInstanceEmailSettings = false; $this->saveModel(); } catch (\Throwable $e) { $this->resendEnabled = false; @@ -258,6 +313,81 @@ class Email extends Component $this->dispatch('error', 'Instance SMTP/Resend settings are not enabled.'); } + public function submitSmtp() + { + try { + $this->resetErrorBag(); + $this->validate([ + 'smtpEnabled' => 'boolean', + 'smtpFromAddress' => 'required|email', + 'smtpFromName' => 'required|string', + 'smtpHost' => 'required|string', + 'smtpPort' => 'required|numeric', + 'smtpEncryption' => 'required|string|in:tls,ssl,none', + 'smtpUsername' => 'nullable|string', + 'smtpPassword' => 'nullable|string', + 'smtpTimeout' => 'nullable|numeric', + ], [ + 'smtpFromAddress.required' => 'From Address is required.', + 'smtpFromAddress.email' => 'Please enter a valid email address.', + 'smtpFromName.required' => 'From Name is required.', + 'smtpHost.required' => 'SMTP Host is required.', + 'smtpPort.required' => 'SMTP Port is required.', + 'smtpPort.numeric' => 'SMTP Port must be a number.', + 'smtpEncryption.required' => 'Encryption type is required.', + ]); + + $settings = $this->team->emailNotificationSettings; + + $settings->smtp_enabled = $this->smtpEnabled; + $settings->smtp_from_address = $this->smtpFromAddress; + $settings->smtp_from_name = $this->smtpFromName; + $settings->smtp_host = $this->smtpHost; + $settings->smtp_port = $this->smtpPort; + $settings->smtp_encryption = $this->smtpEncryption; + $settings->smtp_username = $this->smtpUsername; + $settings->smtp_password = $this->smtpPassword; + $settings->smtp_timeout = $this->smtpTimeout; + + $settings->save(); + refreshSession(); + $this->dispatch('success', 'SMTP settings saved.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + + public function submitResend() + { + try { + $this->resetErrorBag(); + $this->validate([ + 'resendEnabled' => 'boolean', + 'resendApiKey' => 'required|string', + 'smtpFromAddress' => 'required|email', + 'smtpFromName' => 'required|string', + ], [ + 'resendApiKey.required' => 'Resend API Key is required.', + 'smtpFromAddress.required' => 'From Address is required.', + 'smtpFromAddress.email' => 'Please enter a valid email address.', + 'smtpFromName.required' => 'From Name is required.', + ]); + + $settings = $this->team->emailNotificationSettings; + + $settings->resend_enabled = $this->resendEnabled; + $settings->resend_api_key = $this->resendApiKey; + $settings->smtp_from_address = $this->smtpFromAddress; + $settings->smtp_from_name = $this->smtpFromName; + + $settings->save(); + refreshSession(); + $this->dispatch('success', 'Resend settings saved.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() { return view('livewire.notifications.email'); diff --git a/resources/views/livewire/notifications/email.blade.php b/resources/views/livewire/notifications/email.blade.php index fba21d0b2..4e5d3a647 100644 --- a/resources/views/livewire/notifications/email.blade.php +++ b/resources/views/livewire/notifications/email.blade.php @@ -1,54 +1,50 @@
Notifications | Coolify - - -
-
-

Email

- - Save - - @if (isInstanceAdmin() && !$useInstanceEmailSettings) + + + +
+

Email

+ + Save + + @if (isInstanceAdmin() && !$useInstanceEmailSettings) Copy from Instance Settings - @endif - @if (isEmailEnabled($team) && auth()->user()->isAdminFromSession() && isTestEmailEnabled($team)) + @endif + @if (isEmailEnabled($team) && auth()->user()->isAdminFromSession()) - + Send Email - @endif -
- @if (!isCloud()) -
- + @endif
- @endif - @if (!$useInstanceEmailSettings) + @if (!isCloud()) +
+ +
+ @endif + @if (!$useInstanceEmailSettings)
- +
- @endif - - @if (isCloud()) + @endif + + @if (isCloud())
- +
- @endif - @if (!$useInstanceEmailSettings) + @endif + @if (!$useInstanceEmailSettings)
-
+

SMTP Server

@@ -72,13 +68,12 @@
- +
-
+

Resend

@@ -91,28 +86,50 @@
- +
- @endif - @if (isEmailEnabled($team) || $useInstanceEmailSettings) -

Subscribe to events

-
- @if (isDev()) - - @endif - - - - - + @endif + @if (isEmailEnabled($team) || $useInstanceEmailSettings) +

Notification Settings

+

+ Select events for which you would like to receive email notifications. +

+
+
+

Deployments

+
+ + + +
+
+
+

Backups

+
+ + +
+
+
+

Scheduled Tasks

+
+ + +
+
+
+

Server

+
+ + + + +
+
- @endif + @endif