diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index 506c7a91566a..abe82f44ef94 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -16,7 +16,6 @@ use App\Models\Client; use App\Utils\Ninja; use App\Utils\Traits\AppSetup; use App\Utils\Traits\ClientGroupSettingsSaver; -use Beganovich\Snappdf\Snappdf; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; diff --git a/app/Services/Email/EmailService.php b/app/Services/Email/EmailService.php index 7bc635d9d71b..2e2d46563608 100644 --- a/app/Services/Email/EmailService.php +++ b/app/Services/Email/EmailService.php @@ -89,24 +89,27 @@ class EmailService if($this->company->is_disabled && !$this->override) return true; + if(Ninja::isSelfHost()) + return false; + /* To handle spam users we drop all emails from flagged accounts */ - if(Ninja::isHosted() && $this->company->account && $this->company->account->is_flagged) + if($this->company->account && $this->company->account->is_flagged) return true; /* On the hosted platform we set default contacts a @example.com email address - we shouldn't send emails to these types of addresses */ - if(Ninja::isHosted() && $this->hasValidEmails()) + if($this->hasInValidEmails()) return true; /* GMail users are uncapped */ - if(Ninja::isHosted() && in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun'])) + if(in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun'])) return false; /* On the hosted platform, if the user is over the email quotas, we do not send the email. */ - if(Ninja::isHosted() && $this->company->account && $this->company->account->emailQuotaExceeded()) + if($this->company->account && $this->company->account->emailQuotaExceeded()) return true; /* If the account is verified, we allow emails to flow */ - if(Ninja::isHosted() && $this->company->account && $this->company->account->is_verified_account) { + if($this->company->account && $this->company->account->is_verified_account) { //11-01-2022 @@ -118,7 +121,7 @@ class EmailService } /* On the hosted platform if the user has not verified their account we fail here - but still check what they are trying to send! */ - if(Ninja::isHosted() && $this->company->account && !$this->company->account->account_sms_verified){ + if($this->company->account && !$this->company->account->account_sms_verified){ if(class_exists(\Modules\Admin\Jobs\Account\EmailFilter::class)) return (new \Modules\Admin\Jobs\Account\EmailFilter($this->email_object, $this->company))->run(); @@ -133,7 +136,7 @@ class EmailService return false; } - private function hasValidEmails(): bool + private function hasInValidEmails(): bool { foreach($this->email_object->to as $address_object) @@ -145,6 +148,8 @@ class EmailService if(!str_contains($address_object->address, "@")) return true; + if($address_object->address == " ") + return true; } diff --git a/tests/Feature/Email/EmailTest.php b/tests/Feature/Email/EmailTest.php new file mode 100644 index 000000000000..40dadc5ca6e4 --- /dev/null +++ b/tests/Feature/Email/EmailTest.php @@ -0,0 +1,84 @@ +markTestSkipped('Skip test not needed in this environment'); + + $this->makeTestData(); + + $this->email_object = new EmailObject(); + $this->email_object->to = [new Address("testing@gmail.com", "Cool Name")]; + $this->email_object->attachments = []; + $this->email_object->settings = $this->client->getMergedSettings(); + $this->email_object->company = $this->client->company; + $this->email_object->client = $this->client; + $this->email_object->email_template_subject = 'email_subject_statement'; + $this->email_object->email_template_body = 'email_template_statement'; + $this->email_object->variables = [ + '$client' => $this->client->present()->name(), + '$start_date' => '2022-01-01', + '$end_date' => '2023-01-01', + ]; + + $this->email_service = new EmailService($this->email_object, $this->company); + + } + + public function testPreFlightChecksHosted() + { + + config(['ninja.environment' => 'hosted']); + + $this->assertFalse($this->email_service->preFlightChecksFail()); + + } + + public function testPreFlightChecksSelfHost() + { + + config(['ninja.environment' => 'selfhost']); + + $this->assertFalse($this->email_service->preFlightChecksFail()); + + } + + + +}