Custom SMTP Settings (#561)

* Custom SMTP Settings

* Fix lint

* Custom SMTP add in Pricing plan

* Allow reset email settings

* improve custom SMTP using seprate abstract class

* test case for custom SMTP

* fix test case

* UI improvement

* add CASHIER_KEY in phpunit for testcase

* Attempt to fix tests

* Run pint and attempt to fix cache tests

* Fix user management tests

* Fix code linters

* Merged main & fix linting

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-09-24 15:46:20 +05:30
committed by GitHub
parent 5dcd4ff8cb
commit 504c7a0f2f
31 changed files with 876 additions and 510 deletions

View File

@@ -27,7 +27,7 @@ class Google
public function getClient(): Client
{
if($this->client->isAccessTokenExpired()) {
if ($this->client->isAccessTokenExpired()) {
$this->refreshToken();
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Integrations\Handlers;
use App\Events\Forms\FormSubmitted;
use App\Models\Integration\FormIntegration;
use Illuminate\Support\Facades\Log;
abstract class AbstractEmailIntegrationHandler extends AbstractIntegrationHandler
{
protected $mailer;
public function __construct(FormSubmitted $event, FormIntegration $formIntegration, array $integration)
{
parent::__construct($event, $formIntegration, $integration);
$this->initializeMailer();
}
protected function initializeMailer()
{
$this->mailer = config('mail.default');
$this->setWorkspaceSMTPSettings();
if (!$this->mailer) {
Log::error('Mailer not specified', [
'form_id' => $this->form->id
]);
}
}
protected function setWorkspaceSMTPSettings()
{
$workspace = $this->form->workspace;
$emailSettings = $workspace->settings['email_settings'] ?? [];
if (!$workspace->is_pro || !$emailSettings || empty($emailSettings['host']) || empty($emailSettings['port']) || empty($emailSettings['username']) || empty($emailSettings['password'])) {
return;
}
config([
'mail.mailers.custom_smtp.host' => $emailSettings['host'],
'mail.mailers.custom_smtp.port' => $emailSettings['port'],
'mail.mailers.custom_smtp.username' => $emailSettings['username'],
'mail.mailers.custom_smtp.password' => $emailSettings['password']
]);
$this->mailer = 'custom_smtp';
}
}

View File

@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Notifications\Forms\FormSubmissionNotification;
class EmailIntegration extends AbstractIntegrationHandler
class EmailIntegration extends AbstractEmailIntegrationHandler
{
public static function getValidationRules(): array
{
@@ -36,10 +36,11 @@ class EmailIntegration extends AbstractIntegrationHandler
'recipients' => $subscribers->toArray(),
'form_id' => $this->form->id,
'form_slug' => $this->form->slug,
'mailer' => $this->mailer
]);
$subscribers->each(function ($subscriber) {
Notification::route('mail', $subscriber)->notify(
new FormSubmissionNotification($this->event, $this->integrationData)
new FormSubmissionNotification($this->event, $this->integrationData, $this->mailer)
);
});
}

View File

@@ -58,7 +58,7 @@ class GoogleSheetsIntegration extends AbstractIntegrationHandler
protected function getSpreadsheetId(): string
{
if(!isset($this->integrationData->spreadsheet_id)) {
if (!isset($this->integrationData->spreadsheet_id)) {
throw new Exception('The spreadsheed is not instantiated');
}

View File

@@ -10,7 +10,7 @@ use Stevebauman\Purify\Facades\Purify;
/**
* Sends a confirmation to form respondant that form was submitted
*/
class SubmissionConfirmationIntegration extends AbstractIntegrationHandler
class SubmissionConfirmationIntegration extends AbstractEmailIntegrationHandler
{
public const RISKY_USERS_LIMIT = 120;
@@ -54,8 +54,9 @@ class SubmissionConfirmationIntegration extends AbstractIntegrationHandler
'recipient' => $email,
'form_id' => $this->form->id,
'form_slug' => $this->form->slug,
'mailer' => $this->mailer
]);
Mail::to($email)->send(new SubmissionConfirmationMail($this->event, $this->integrationData));
Mail::mailer($this->mailer)->to($email)->send(new SubmissionConfirmationMail($this->event, $this->integrationData));
}
private function getRespondentEmail()