From 127e9f723f5814ce3ccde13619fd05a9557982bb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 30 Jun 2022 10:11:55 +1000 Subject: [PATCH] Add flagging abilities to accounts table --- app/Factory/UserFactory.php | 1 + app/Jobs/Mail/NinjaMailerJob.php | 6 +++- app/Models/Account.php | 2 ++ ...6_30_000126_add_flag_to_accounts_table.php | 30 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2022_06_30_000126_add_flag_to_accounts_table.php diff --git a/app/Factory/UserFactory.php b/app/Factory/UserFactory.php index baba2fff2588..da56a183875e 100644 --- a/app/Factory/UserFactory.php +++ b/app/Factory/UserFactory.php @@ -11,6 +11,7 @@ namespace App\Factory; +use App\Models\CompanyUser; use App\Models\User; class UserFactory diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index fe5576fbc53b..6e7296e96c52 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -308,8 +308,9 @@ class NinjaMailerJob implements ShouldQueue private function preFlightChecksFail() { + /* If we are migrating data we don't want to fire any emails */ - if ($this->nmo->company->is_disabled && !$this->override) + if($this->nmo->company->is_disabled && !$this->override) 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 */ @@ -324,6 +325,9 @@ class NinjaMailerJob implements ShouldQueue if(Ninja::isHosted() && $this->company->account && $this->company->account->emailQuotaExceeded()) return true; + if(Ninja::isHosted() && $this->company->account && $this->nmo->company->account->is_flagged) + return true; + /* Ensure the user has a valid email address */ if(!str_contains($this->nmo->to_user->email, "@")) return true; diff --git a/app/Models/Account.php b/app/Models/Account.php index d41ec4e95267..a9ff4020ca07 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -373,6 +373,8 @@ class Account extends BaseModel public function getDailyEmailLimit() { + if($this->is_flagged) + return 0; if(Carbon::createFromTimestamp($this->created_at)->diffInWeeks() == 0) return 20; diff --git a/database/migrations/2022_06_30_000126_add_flag_to_accounts_table.php b/database/migrations/2022_06_30_000126_add_flag_to_accounts_table.php new file mode 100644 index 000000000000..7118a7d7f564 --- /dev/null +++ b/database/migrations/2022_06_30_000126_add_flag_to_accounts_table.php @@ -0,0 +1,30 @@ +boolean('is_flagged')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +}