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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: Email Notification saving
peaklabs-devee7a901a77dd
diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.phpindex d81535a807..a4a16e5e57 100644--- a/app/Livewire/Notifications/Email.php+++ b/app/Livewire/Notifications/Email.php@@ -31,11 +31,11 @@ class Email extends Component#[Validate(['nullable', 'string'])]public ?string $smtpHost = null;- #[Validate(['nullable', 'numeric'])]+ #[Validate(['nullable', 'numeric', 'min:1', 'max:65535'])]public ?int $smtpPort = null;#[Validate(['nullable', 'string', 'in:tls,ssl,none'])]- public ?string $smtpEncryption = null;+ public ?string $smtpEncryption = 'tls';#[Validate(['nullable', 'string'])]public ?string $smtpUsername = null;@@ -170,48 +170,54 @@ class Email extends Component}}- public function sendTestEmail()+ public function submit(){try {- $this->validate([- 'testEmailAddress' => 'required|email',- ], [- 'testEmailAddress.required' => 'Test email address is required.',- 'testEmailAddress.email' => 'Please enter a valid email address.',- ]);-- $executed = RateLimiter::attempt(- 'test-email:'.$this->team->id,- $perMinute = 0,- function () {- $this->team?->notify(new Test($this->testEmailAddress));- $this->dispatch('success', 'Test Email sent.');- },- $decaySeconds = 10,- );-- if (! $executed) {- throw new \Exception('Too many messages sent!');- }+ $this->resetErrorBag();+ $this->saveModel();} catch (\Throwable $e) {return handleError($e, $this);}}- public function instantSaveInstance()+ public function saveModel()+ {+ $this->syncData(true);+ refreshSession();+ $this->dispatch('success', 'Email notifications settings updated.');+ }++ public function instantSave(?string $type = null){try {- $this->smtpEnabled = false;- $this->resendEnabled = false;- $this->saveModel();+ $this->resetErrorBag();++ if ($type === 'SMTP') {+ $this->submitSmtp();+ } elseif ($type === 'Resend') {+ $this->submitResend();+ } else {+ $this->smtpEnabled = false;+ $this->resendEnabled = false;+ $this->saveModel();++ return;+ }} catch (\Throwable $e) {+ if ($type === 'SMTP') {+ $this->smtpEnabled = false;+ } elseif ($type === 'Resend') {+ $this->resendEnabled = false;+ }+return handleError($e, $this);}}- public function instantSaveSmtpEnabled()+ public function submitSmtp(){try {+ $this->resetErrorBag();$this->validate(['smtpEnabled' => 'boolean','smtpFromAddress' => 'required|email',@@ -231,19 +237,38 @@ class Email extends Component'smtpPort.numeric' => 'SMTP Port must be a number.','smtpEncryption.required' => 'Encryption type is required.',]);++ $settings = $this->team->emailNotificationSettings;++ $settings->resend_enabled = false;+ $settings->use_instance_email_settings = false;$this->resendEnabled = false;$this->useInstanceEmailSettings = false;- $this->saveModel();++ $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 updated.');} catch (\Throwable $e) {$this->smtpEnabled = false;- return handleError($e, $this);+ return handleError($e);}}- public function instantSaveResend()+ public function submitResend(){try {+ $this->resetErrorBag();$this->validate(['resendEnabled' => 'boolean','resendApiKey' => 'required|string',@@ -255,28 +280,49 @@ class Email extends Component'smtpFromAddress.email' => 'Please enter a valid email address.','smtpFromName.required' => 'From Name is required.',]);+ $settings = $this->team->emailNotificationSettings;++ $settings->smtp_enabled = false;+ $settings->use_instance_email_settings = false;$this->smtpEnabled = false;$this->useInstanceEmailSettings = false;- $this->saveModel();- } catch (\Throwable $e) {- $this->resendEnabled = false;+ $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 updated.');+ } catch (\Throwable $e) {return handleError($e, $this);}}- public function saveModel()- {- $this->syncData(true);- refreshSession();- $this->dispatch('success', 'Settings saved.');- }-- public function submit()+ public function sendTestEmail(){try {- $this->resetErrorBag();- $this->saveModel();+ $this->validate([+ 'testEmailAddress' => 'required|email',+ ], [+ 'testEmailAddress.required' => 'Test email address is required.',+ 'testEmailAddress.email' => 'Please enter a valid email address.',+ ]);++ $executed = RateLimiter::attempt(+ 'test-email:'.$this->team->id,+ $perMinute = 0,+ function () {+ $this->team?->notify(new Test($this->testEmailAddress));+ $this->dispatch('success', 'Test Email sent.');+ },+ $decaySeconds = 10,+ );++ if (! $executed) {+ throw new \Exception('Too many messages sent!');+ }} catch (\Throwable $e) {return handleError($e, $this);}@@ -313,81 +359,6 @@ 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.phpindex 64530c1d46..868e27ce88 100644--- a/resources/views/livewire/notifications/email.blade.php+++ b/resources/views/livewire/notifications/email.blade.php@@ -9,11 +9,6 @@<x-forms.button type="submit">Save</x-forms.button>- @if (isInstanceAdmin() && !$useInstanceEmailSettings)- <x-forms.button wire:click='copyFromInstanceSettings'>- Copy from Instance Settings- </x-forms.button>- @endif@if ($team->isNotificationEnabled('email') && 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">@@ -24,10 +19,15 @@</form></x-modal-input>@endif+ @if (isInstanceAdmin() && !$useInstanceEmailSettings)+ <x-forms.button wire:click='copyFromInstanceSettings'>+ Copy from Instance Settings+ </x-forms.button>+ @endif</div>@if (!isCloud())<div class="w-96">- <x-forms.checkbox instantSave="instantSaveInstance" id="useInstanceEmailSettings" label="Use system wide (transactional) email settings" />+ <x-forms.checkbox instantSave="instantSave()" id="useInstanceEmailSettings" label="Use system wide (transactional) email settings" /></div>@endif@if (!$useInstanceEmailSettings)@@ -39,7 +39,7 @@</form>@if (isCloud())<div class="w-64 py-4">- <x-forms.checkbox instantSave="instantSaveInstance" id="useInstanceEmailSettings" label="Use Hosted Email Service" />+ <x-forms.checkbox instantSave="instantSave()" id="useInstanceEmailSettings" label="Use Hosted Email Service" /></div>@endif@if (!$useInstanceEmailSettings)@@ -52,7 +52,7 @@</x-forms.button></div><div class="w-32">- <x-forms.checkbox instantSave="instantSaveSmtpEnabled" id="smtpEnabled" label="Enabled" />+ <x-forms.checkbox wire:model="smtpEnabled" instantSave="instantSave('SMTP')" id="smtpEnabled" label="Enabled" /></div><div class="flex flex-col"><div class="flex flex-col gap-4">@@ -81,7 +81,7 @@</x-forms.button></div><div class="w-32">- <x-forms.checkbox instantSave='instantSaveResend' id="resendEnabled" label="Enabled" />+ <x-forms.checkbox wire:model="resendEnabled" instantSave="instantSave('Resend')" id="resendEnabled" label="Enabled" /></div><div class="flex flex-col"><div class="flex flex-col gap-4">