From 430d42b2e0554db9cb8a31ffa994bd5306829f26 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 May 2023 13:16:34 +1000 Subject: [PATCH 1/8] Minor fixes for imports in appserviceprovider --- .../Controllers/HostedMigrationController.php | 1 + app/Providers/AppServiceProvider.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/HostedMigrationController.php b/app/Http/Controllers/HostedMigrationController.php index 386722ca6e1f..4ddc57d5593f 100644 --- a/app/Http/Controllers/HostedMigrationController.php +++ b/app/Http/Controllers/HostedMigrationController.php @@ -36,6 +36,7 @@ class HostedMigrationController extends Controller $account = (new CreateAccount($request->all(), $request->getClientIp()))->handle(); $account->hosted_client_count = 100; $account->hosted_company_count = 10; + $account->created_at = now()->subYears(2); $account->save(); MultiDB::findAndSetDbByAccountKey($account->key); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index b28db7336dc4..40fb55b80022 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -11,25 +11,25 @@ namespace App\Providers; -use App\Helpers\Mail\GmailTransport; -use App\Helpers\Mail\Office365MailTransport; -use App\Http\Middleware\SetDomainNameDb; +use App\Utils\Ninja; +use Livewire\Livewire; use App\Models\Invoice; use App\Models\Proposal; -use App\Utils\Ninja; use App\Utils\TruthSource; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Mail\Mailer; -use Illuminate\Queue\Events\JobProcessing; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Blade; +use App\Helpers\Mail\GmailTransport; use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\ParallelTesting; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\ServiceProvider; -use Livewire\Livewire; +use App\Http\Middleware\SetDomainNameDb; +use Illuminate\Queue\Events\JobProcessing; +use App\Helpers\Mail\Office365MailTransport; +use Illuminate\Support\Facades\ParallelTesting; +use Illuminate\Database\Eloquent\Relations\Relation; class AppServiceProvider extends ServiceProvider { From 173fd42cbf9b7ac8afd5866ebabe384766c781a4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 May 2023 14:15:50 +1000 Subject: [PATCH 2/8] 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 2b6b02ff938a..2df86c581f9d 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 45a6b4a85767..437cc7233fe9 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 9853886c36dc..ab58b329738e 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())) { From eaee83623fd1e75e62c3eeb8a8f260b97a2e35fa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 6 May 2023 22:19:55 +1000 Subject: [PATCH 3/8] Add all send email contacts to statements --- app/Services/Client/ClientService.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 5167c4af0938..a26fc8c7a13b 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -179,8 +179,23 @@ class ClientService */ public function buildStatementMailableData($pdf) :EmailObject { + $email = $this->client->present()->email(); + $email_object = new EmailObject; - $email_object->to = [new Address($this->client->present()->email(), $this->client->present()->name())]; + $email_object->to = [new Address($email, $this->client->present()->name())]; + + $cc_contacts = $this->client + ->contacts() + ->where('send_email', true) + ->where('email', '!=', $email) + ->get(); + + foreach ($cc_contacts as $contact) { + + $email_object->cc[] = new Address($contact->email, $contact->present()->name()); + + } + $email_object->attachments = [['file' => base64_encode($pdf), 'name' => ctrans('texts.statement') . ".pdf"]]; $email_object->client_id = $this->client->id; $email_object->email_template_subject = 'email_subject_statement'; @@ -191,6 +206,8 @@ class ClientService '$end_date' => $this->client_end_date, ]; + nlog($email_object); + return $email_object; } From d7b315f62fcceff6115c30ad5f33f8c08a8da625 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 6 May 2023 22:20:12 +1000 Subject: [PATCH 4/8] Add all send email contacts to statements --- app/Services/Client/ClientService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index a26fc8c7a13b..d2fc9795099f 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -206,8 +206,6 @@ class ClientService '$end_date' => $this->client_end_date, ]; - nlog($email_object); - return $email_object; } From 6a6c831f86121daa83b83ac5af33b1b8483bb17a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 May 2023 07:51:10 +1000 Subject: [PATCH 5/8] Fixes for event definition --- app/Events/Invoice/InvoiceWasViewed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Events/Invoice/InvoiceWasViewed.php b/app/Events/Invoice/InvoiceWasViewed.php index 81a64574a4ea..965d31b0b8f7 100644 --- a/app/Events/Invoice/InvoiceWasViewed.php +++ b/app/Events/Invoice/InvoiceWasViewed.php @@ -30,7 +30,7 @@ class InvoiceWasViewed * @param Company $company * @param array $event_vars */ - public function __construct(public InvoiceInvitation $invitation, Company $company, array $event_vars) + public function __construct(public InvoiceInvitation $invitation, public Company $company, public array $event_vars) { } } From 0b46508684b17f9002abc2634ccf177a00dc8e23 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 May 2023 07:58:39 +1000 Subject: [PATCH 6/8] Fixes for event definitions --- app/Events/Account/AccountCreated.php | 3 --- app/Events/Contact/ContactLoggedIn.php | 3 --- app/Events/Credit/CreditWasEmailed.php | 2 +- app/Events/Credit/CreditWasRestored.php | 2 +- app/Events/Invoice/InvoiceWasEmailed.php | 2 +- app/Events/Payment/Methods/MethodDeleted.php | 2 +- app/Events/RecurringQuote/RecurringQuoteWasArchived.php | 4 ++-- app/Events/User/UserWasDeleted.php | 3 --- app/Events/User/UserWasRestored.php | 3 --- app/Events/User/UserWasUpdated.php | 3 --- 10 files changed, 6 insertions(+), 21 deletions(-) diff --git a/app/Events/Account/AccountCreated.php b/app/Events/Account/AccountCreated.php index f2149b2a82d2..0761cdf4b9ed 100644 --- a/app/Events/Account/AccountCreated.php +++ b/app/Events/Account/AccountCreated.php @@ -24,9 +24,6 @@ class AccountCreated { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ public $user; public $company; diff --git a/app/Events/Contact/ContactLoggedIn.php b/app/Events/Contact/ContactLoggedIn.php index 577ebed0cde3..0e98a54449c6 100644 --- a/app/Events/Contact/ContactLoggedIn.php +++ b/app/Events/Contact/ContactLoggedIn.php @@ -25,9 +25,6 @@ class ContactLoggedIn { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ public $client_contact; public $company; diff --git a/app/Events/Credit/CreditWasEmailed.php b/app/Events/Credit/CreditWasEmailed.php index 85024f7a99e7..5991e738c5f6 100644 --- a/app/Events/Credit/CreditWasEmailed.php +++ b/app/Events/Credit/CreditWasEmailed.php @@ -32,7 +32,7 @@ class CreditWasEmailed /** * Create a new event instance. * - * @param Credit $credit + * @param CreditInvitation $invitation * @param Company $company * @param array $event_vars */ diff --git a/app/Events/Credit/CreditWasRestored.php b/app/Events/Credit/CreditWasRestored.php index 5480641803e0..47e61522a4c2 100644 --- a/app/Events/Credit/CreditWasRestored.php +++ b/app/Events/Credit/CreditWasRestored.php @@ -23,7 +23,7 @@ class CreditWasRestored use SerializesModels; /** - * @var Client + * @var Credit */ public $credit; diff --git a/app/Events/Invoice/InvoiceWasEmailed.php b/app/Events/Invoice/InvoiceWasEmailed.php index d27aea3501cc..c33179095b43 100644 --- a/app/Events/Invoice/InvoiceWasEmailed.php +++ b/app/Events/Invoice/InvoiceWasEmailed.php @@ -23,7 +23,7 @@ class InvoiceWasEmailed use SerializesModels; /** - * @var Invoice + * @var InvoiceInvitation */ public $invitation; diff --git a/app/Events/Payment/Methods/MethodDeleted.php b/app/Events/Payment/Methods/MethodDeleted.php index 4b1d3d710397..5e80e20f8aea 100644 --- a/app/Events/Payment/Methods/MethodDeleted.php +++ b/app/Events/Payment/Methods/MethodDeleted.php @@ -26,7 +26,7 @@ class MethodDeleted /** * @var ClientGatewayToken */ - private $payment_method; + public $payment_method; public $company; diff --git a/app/Events/RecurringQuote/RecurringQuoteWasArchived.php b/app/Events/RecurringQuote/RecurringQuoteWasArchived.php index ba99fd7da48c..be35962d6d13 100644 --- a/app/Events/RecurringQuote/RecurringQuoteWasArchived.php +++ b/app/Events/RecurringQuote/RecurringQuoteWasArchived.php @@ -23,7 +23,7 @@ class RecurringQuoteWasArchived use SerializesModels; /** - * @var Invoice + * @var RecurringQuote */ public $recurring_quote; @@ -34,7 +34,7 @@ class RecurringQuoteWasArchived /** * Create a new event instance. * - * @param Invoice $recurring_quote + * @param RecurringQuote $recurring_quote * @param Company $company * @param array $event_vars */ diff --git a/app/Events/User/UserWasDeleted.php b/app/Events/User/UserWasDeleted.php index 04e6e68a2651..cae639e2088d 100644 --- a/app/Events/User/UserWasDeleted.php +++ b/app/Events/User/UserWasDeleted.php @@ -26,9 +26,6 @@ class UserWasDeleted { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ public $user; public $creating_user; diff --git a/app/Events/User/UserWasRestored.php b/app/Events/User/UserWasRestored.php index 10870b0b09ed..2d722fd189a0 100644 --- a/app/Events/User/UserWasRestored.php +++ b/app/Events/User/UserWasRestored.php @@ -26,9 +26,6 @@ class UserWasRestored { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ public $user; public $company; diff --git a/app/Events/User/UserWasUpdated.php b/app/Events/User/UserWasUpdated.php index 79bf871eaa56..a4eda9752c79 100644 --- a/app/Events/User/UserWasUpdated.php +++ b/app/Events/User/UserWasUpdated.php @@ -26,9 +26,6 @@ class UserWasUpdated { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var - */ public $user; public $creating_user; From 3e56aa6ae7d22c5ca20866b3fae4ff95694f2782 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 May 2023 07:58:59 +1000 Subject: [PATCH 7/8] v5.5.115 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index f74778e9a38a..425ff09f9bf7 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.114 \ No newline at end of file +5.5.115 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index ffb043ad8f62..833ee2a79fed 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,8 +15,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.114', - 'app_tag' => '5.5.114', + 'app_version' => '5.5.115', + 'app_tag' => '5.5.115', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), From 16b48508fb5ba909fea68300bd70f2bcdff06505 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 May 2023 08:17:58 +1000 Subject: [PATCH 8/8] Static analysis cleanup --- app/Listeners/Document/DeleteCompanyDocuments.php | 2 +- app/Listeners/Mail/MailSentListener.php | 2 +- app/Listeners/Payment/PaymentEmailFailureActivity.php | 4 ++-- .../PurchaseOrder/PurchaseOrderCreatedListener.php | 2 +- app/Models/ClientContact.php | 8 -------- app/Models/PurchaseOrderInvitation.php | 8 -------- 6 files changed, 5 insertions(+), 21 deletions(-) diff --git a/app/Listeners/Document/DeleteCompanyDocuments.php b/app/Listeners/Document/DeleteCompanyDocuments.php index 8b8d5bcdbd58..d46d12b52fcf 100644 --- a/app/Listeners/Document/DeleteCompanyDocuments.php +++ b/app/Listeners/Document/DeleteCompanyDocuments.php @@ -21,7 +21,7 @@ class DeleteCompanyDocuments /** * Handle the event. * - * @param CompanyWasDeleted $event + * @param $event * @return void */ public function handle($event) diff --git a/app/Listeners/Mail/MailSentListener.php b/app/Listeners/Mail/MailSentListener.php index 9978f076068b..b6228b8bf1d8 100644 --- a/app/Listeners/Mail/MailSentListener.php +++ b/app/Listeners/Mail/MailSentListener.php @@ -36,7 +36,7 @@ class MailSentListener implements ShouldQueue /** * Handle the event. * - * @param object $event + * @param MessageSent $event * @return void */ public function handle(MessageSent $event) diff --git a/app/Listeners/Payment/PaymentEmailFailureActivity.php b/app/Listeners/Payment/PaymentEmailFailureActivity.php index bcf9ca95983c..f9e725d52860 100644 --- a/app/Listeners/Payment/PaymentEmailFailureActivity.php +++ b/app/Listeners/Payment/PaymentEmailFailureActivity.php @@ -32,7 +32,7 @@ class PaymentEmailFailureActivity implements ShouldQueue * Handle the event. * * @param object $event - * @return bool + * @return void */ public function handle($event) { @@ -41,6 +41,6 @@ class PaymentEmailFailureActivity implements ShouldQueue $payment = $event->payment; nlog("i failed emailing {$payment->number}"); - // nlog(print_r($event->errors,1)); + } } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php index 057743942d93..61a686de03b4 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php @@ -34,7 +34,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue /** * Handle the event. * - * @param object $event + * @param PurchaseOrderWasCreated $event * @return void */ public function handle(PurchaseOrderWasCreated $event) diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 5f3254d14cf5..c51e9bddf662 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -415,9 +415,6 @@ class ClientContact extends Authenticatable implements HasLocalePreference */ public function getLoginLink() { - // $domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain(); - - // return $domain.'/client/key_login/'.$this->contact_key; if (Ninja::isHosted()) { $domain = $this->company->domain(); @@ -428,18 +425,13 @@ class ClientContact extends Authenticatable implements HasLocalePreference switch ($this->company->portal_mode) { case 'subdomain': return $domain.'/client/key_login/'.$this->contact_key; - break; case 'iframe': return $domain.'/client/key_login/'.$this->contact_key; - //return $domain . $entity_type .'/'. $this->contact->client->client_hash .'/'. $this->key; - break; case 'domain': return $domain.'/client/key_login/'.$this->contact_key; - break; default: return ''; - break; } } } diff --git a/app/Models/PurchaseOrderInvitation.php b/app/Models/PurchaseOrderInvitation.php index c83a20aa25f2..8f22058d0712 100644 --- a/app/Models/PurchaseOrderInvitation.php +++ b/app/Models/PurchaseOrderInvitation.php @@ -153,17 +153,13 @@ class PurchaseOrderInvitation extends BaseModel switch ($this->company->portal_mode) { case 'subdomain': return $domain.'/vendor/'; - break; case 'iframe': return $domain.'/vendor/'; - break; case 'domain': return $domain.'/vendor/'; - break; default: return ''; - break; } } @@ -180,17 +176,13 @@ class PurchaseOrderInvitation extends BaseModel switch ($this->company->portal_mode) { case 'subdomain': return $domain.'/vendor/'.$entity_type.'/'.$this->key; - break; case 'iframe': return $domain.'/vendor/'.$entity_type.'/'.$this->key; - break; case 'domain': return $domain.'/vendor/'.$entity_type.'/'.$this->key; - break; default: return ''; - break; } }