From 173fd42cbf9b7ac8afd5866ebabe384766c781a4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 May 2023 14:15:50 +1000 Subject: [PATCH] rate limiting for hosteD --- app/Exceptions/Handler.php | 8 ++++++-- app/Jobs/Mail/NinjaMailerJob.php | 6 ------ app/Models/Account.php | 7 ++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 2b6b02ff93..2df86c581f 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -79,7 +79,7 @@ class Handler extends ExceptionHandler /** * A list of the inputs that are never flashed for validation exceptions. * - * @var array + * @var array<1, string> */ protected $dontFlash = [ 'current_password', @@ -102,6 +102,11 @@ class Handler extends ExceptionHandler } if (Ninja::isHosted()) { + + if($exception instanceof ThrottleRequestsException && class_exists(\Modules\Admin\Events\ThrottledExceptionRaised::class)) { + event(new \Modules\Admin\Events\ThrottledExceptionRaised(auth()->user()->account->key)); + } + Integration::configureScope(function (Scope $scope): void { $name = 'hosted@invoiceninja.com'; @@ -202,7 +207,6 @@ class Handler extends ExceptionHandler * * @param Request $request * @param Throwable $exception - * @return Response * @throws Throwable */ public function render($request, Throwable $exception) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 45a6b4a857..437cc7233f 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -518,12 +518,6 @@ class NinjaMailerJob implements ShouldQueue /* If the account is verified, we allow emails to flow */ if (Ninja::isHosted() && $this->company->account && $this->company->account->is_verified_account) { - //11-01-2022 - - /* Continue to analyse verified accounts in case they later start sending poor quality emails*/ - // if(class_exists(\Modules\Admin\Jobs\Account\EmailQuality::class)) - // (new \Modules\Admin\Jobs\Account\EmailQuality($this->nmo, $this->company))->run(); - return false; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 9853886c36..ab58b32973 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -64,7 +64,7 @@ use Laracasts\Presenter\PresentableTrait; * @property int|null $hosted_company_count * @property string|null $inapp_transaction_id * @property bool $set_react_as_default_ap - * @property int $is_flagged + * @property bool $is_flagged * @property int $is_verified_account * @property string|null $account_sms_verification_code * @property string|null $account_sms_verification_number @@ -262,6 +262,11 @@ class Account extends BaseModel return $this->hasMany(CompanyUser::class)->where('is_owner', true)->first() ? $this->hasMany(CompanyUser::class)->where('is_owner', true)->first()->user : false; } + public function tokens() + { + return $this->hasMany(CompanyToken::class)->withTrashed(); + } + public function getPlan() { if (Carbon::parse($this->plan_expires)->lt(now())) {