From bf6436e350789099c4e09d591e0787c4987e89af Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 11:47:32 +1100 Subject: [PATCH 1/8] Catch exception in Authorize - failedResponse method --- .../Authorize/AuthorizeCreditCard.php | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index b2c34687ddc0..074619a05582 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -98,29 +98,8 @@ class AuthorizeCreditCard /*Refactor and push to BaseDriver*/ if ($data['response'] != null && $data['response']->getMessages()->getResultCode() == 'Ok') { - // $response = $data['response']; - - // $payment_record = []; - // $payment_record['amount'] = $amount; - // $payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER;; - // $payment_record['transaction_reference'] = $response->getTransactionResponse()->getTransId(); - - // $this->authorize->createPayment($payment_record); - $this->storePayment($payment_hash, $data); - // $payment = $this->createPaymentRecord($data, $amount); - // $payment->meta = $cgt->meta; - // $payment->save(); - - // $payment_hash->payment_id = $payment->id; - // $payment_hash->save(); - - // $this->authorize->attachInvoices($payment, $payment_hash); - // $payment->service()->updateInvoicePayment($payment_hash); - - // event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); - $vars = [ 'hashed_ids' => $invoice->hashed_id, 'amount' => $amount, @@ -212,8 +191,7 @@ class AuthorizeCreditCard private function processFailedResponse($data, $request) { - //dd($data); -// nlog(print_r($data, 1)); + throw new \Exception(ctrans('texts.error_title')); } private function formatGatewayResponse($data, $vars) From 502b8f336fd3f80509ce165200d38b0d7c050076 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 13:20:26 +1100 Subject: [PATCH 2/8] HTMLEngine clean up --- app/Utils/HtmlEngine.php | 59 ++-------------------------------------- 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 4ded8324fe62..7b26ff32f854 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -106,7 +106,7 @@ class HtmlEngine $data['$line_tax_labels'] = ['value' => $this->lineTaxLabels(), 'label' => ctrans('texts.taxes')]; $data['$line_tax_values'] = ['value' => $this->lineTaxValues(), 'label' => ctrans('texts.taxes')]; $data['$date'] = ['value' => $this->formatDate($this->entity->date, $this->entity->client->date_format()) ?: ' ', 'label' => ctrans('texts.date')]; - //$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')]; + $data['$invoice.date'] = &$data['$date']; $data['$due_date'] = ['value' => $this->formatDate($this->entity->due_date, $this->entity->client->date_format()) ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')]; $data['$payment_due'] = ['value' => $this->formatDate($this->entity->due_date, $this->entity->client->date_format()) ?: ' ', 'label' => ctrans('texts.payment_due')]; @@ -118,12 +118,6 @@ class HtmlEngine $data['$quote.datetime'] = &$data['$entity.datetime']; $data['$credit.datetime'] = &$data['$entity.datetime']; - // $data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: ' ', 'label' => ctrans('texts.taxes')]; - // $data['$invoice.line_taxes'] = &$data['$line_taxes']; - - // $data['$total_taxes'] = ['value' => $this->makeTotalTaxes() ?: ' ', 'label' => ctrans('texts.taxes')]; - // $data['$invoice.total_taxes'] = &$data['$total_taxes']; - if ($this->entity_string == 'invoice') { $data['$entity'] = ['value' => '', 'label' => ctrans('texts.invoice')]; $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; @@ -159,14 +153,14 @@ class HtmlEngine $data['$invoice.subtotal'] = &$data['$subtotal']; if ($this->entity->partial > 0) { - $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; + $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; } else { $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; } $data['$quote.balance_due'] = $data['$balance_due']; $data['$invoice.balance_due'] = $data['$balance_due']; - $data['$balance_due'] = $data['$balance_due']; + // $data['$balance_due'] = $data['$balance_due']; $data['$outstanding'] = $data['$balance_due']; $data['$partial_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; $data['$total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')]; @@ -212,15 +206,6 @@ class HtmlEngine $data['$credit_no'] = &$data['$number']; $data['$credit.credit_no'] = &$data['$number']; - // $data['$invoice_issued_to'] = ; - // $data['$quote_issued_to'] = ; - // $data['$rate'] = ; - // $data['$hours'] = ; - // $data['$from'] = ; - // $data['$to'] = ; - // $data['$invoice_to'] = ; - // $data['$quote_to'] = ; - // $data['$details'] = ; $data['$invoice_no'] = &$data['$number']; $data['$invoice.invoice_no'] = &$data['$number']; $data['$client1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'client1', $this->client->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'client1')]; @@ -362,44 +347,6 @@ class HtmlEngine $data['$entity_footer'] = ['value' => $this->client->getSetting("{$this->entity_string}_footer"), 'label' => '']; - // $data['custom_label1'] = ['value' => '', 'label' => ctrans('texts.')]; - // $data['custom_label2'] = ['value' => '', 'label' => ctrans('texts.')]; - // $data['custom_label3'] = ['value' => '', 'label' => ctrans('texts.')]; - // $data['custom_label4'] = ['value' => '', 'label' => ctrans('texts.')]; - //$data['$blank'] = ; - //$data['$surcharge'] = ; - /* - $data['$tax_invoice'] = - $data['$tax_quote'] = - $data['$statement'] = ; - $data['$statement_date'] = ; - $data['$your_statement'] = ; - $data['$statement_issued_to'] = ; - $data['$statement_to'] = ; - $data['$credit_note'] = ; - $data['$credit_date'] = ; - $data['$credit_issued_to'] = ; - $data['$credit_to'] = ; - $data['$your_credit'] = ; - $data['$phone'] = ; - - $data['$outstanding'] = ; - $data['$invoice_due_date'] = ; - $data['$quote_due_date'] = ; - $data['$service'] = ; - $data['$product_key'] = ; - $data['$unit_cost'] = ; - $data['$custom_value1'] = ; - $data['$custom_value2'] = ; - $data['$delivery_note'] = ; - $data['$date'] = ; - $data['$method'] = ; - $data['$payment_date'] = ; - $data['$reference'] = ; - $data['$amount'] = ; - $data['$amount_paid'] =; - */ - $arrKeysLength = array_map('strlen', array_keys($data)); array_multisort($arrKeysLength, SORT_DESC, $data); From 435365b32bd655983a96b95fe7eec914fce7dd01 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 13:43:08 +1100 Subject: [PATCH 3/8] Add youtube channel to client portal --- .../ninja2020/components/general/sidebar/desktop.blade.php | 5 +++++ .../ninja2020/components/general/sidebar/mobile.blade.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php b/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php index 9887232bd1f7..32cacf8a7c10 100644 --- a/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php +++ b/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php @@ -38,6 +38,11 @@ + + + + + @endif diff --git a/resources/views/portal/ninja2020/components/general/sidebar/mobile.blade.php b/resources/views/portal/ninja2020/components/general/sidebar/mobile.blade.php index 66d7d704596e..af1cad586954 100644 --- a/resources/views/portal/ninja2020/components/general/sidebar/mobile.blade.php +++ b/resources/views/portal/ninja2020/components/general/sidebar/mobile.blade.php @@ -44,6 +44,11 @@ + + + + + @endif From c49fbedcde5f13263cd661166849320d4fb1b438 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 13:57:05 +1100 Subject: [PATCH 4/8] Add entity number to header on client portal --- .../portal/ninja2020/credits/show.blade.php | 2 +- .../portal/ninja2020/invoices/show.blade.php | 14 ++++++++++- .../invoices/show/fullscreen.blade.php | 23 +++++++++++++------ .../portal/ninja2020/quotes/show.blade.php | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/resources/views/portal/ninja2020/credits/show.blade.php b/resources/views/portal/ninja2020/credits/show.blade.php index 22183f227580..077dd45601e5 100644 --- a/resources/views/portal/ninja2020/credits/show.blade.php +++ b/resources/views/portal/ninja2020/credits/show.blade.php @@ -1,5 +1,5 @@ @extends('portal.ninja2020.layout.app') -@section('meta_title', ctrans('texts.credit')) +@section('meta_title', ctrans('texts.entity_number_placeholder', ['entity' => ctrans('texts.credit'), 'entity_number' => $credit->number])) @push('head') diff --git a/resources/views/portal/ninja2020/invoices/show.blade.php b/resources/views/portal/ninja2020/invoices/show.blade.php index b57686358775..f2b64f7708ba 100644 --- a/resources/views/portal/ninja2020/invoices/show.blade.php +++ b/resources/views/portal/ninja2020/invoices/show.blade.php @@ -22,7 +22,7 @@

- {{ ctrans('texts.unpaid') }} + {{ ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice->number])}} - {{ ctrans('texts.unpaid') }}

@@ -42,6 +42,18 @@

+ @else +
+
+
+
+

+ {{ ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice->number])}} - {{ ctrans('texts.unpaid') }} +

+
+
+
+
@endif
diff --git a/resources/views/portal/ninja2020/invoices/show/fullscreen.blade.php b/resources/views/portal/ninja2020/invoices/show/fullscreen.blade.php index 5a49f24d905e..6499f3996e27 100644 --- a/resources/views/portal/ninja2020/invoices/show/fullscreen.blade.php +++ b/resources/views/portal/ninja2020/invoices/show/fullscreen.blade.php @@ -5,25 +5,22 @@ @if($invoice->isPayable())
@csrf -
+

- {{ ctrans('texts.unpaid') }} + {{ ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice->number])}} - {{ ctrans('texts.unpaid') }}

{{ ctrans('texts.invoice_still_unpaid') }} +

- - ← {{ ctrans('texts.client_portal') }} - - -
+
@@ -33,6 +30,18 @@
+ @else +
+
+
+
+

+ {{ ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice->number])}} - {{ ctrans('texts.unpaid') }} +

+
+
+
+
@endif diff --git a/resources/views/portal/ninja2020/quotes/show.blade.php b/resources/views/portal/ninja2020/quotes/show.blade.php index e0705c981b40..b0fac3c64c28 100644 --- a/resources/views/portal/ninja2020/quotes/show.blade.php +++ b/resources/views/portal/ninja2020/quotes/show.blade.php @@ -1,5 +1,5 @@ @extends('portal.ninja2020.layout.app') -@section('meta_title', ctrans('texts.view_quote')) +@section('meta_title', ctrans('texts.entity_number_placeholder', ['entity' => ctrans('texts.quote'), 'entity_number' => $quote->number])) @push('head') From 7d46ec489a5ec72a37f9b3cedd7ba4f6625f18d3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 14:44:52 +1100 Subject: [PATCH 5/8] User Activities --- app/Events/User/UserWasArchived.php | 5 +++- app/Events/User/UserWasCreated.php | 5 +++- app/Events/User/UserWasDeleted.php | 5 +++- app/Events/User/UserWasRestored.php | 6 ++-- app/Events/User/UserWasUpdated.php | 5 +++- app/Http/Controllers/UserController.php | 8 +++++- app/Listeners/User/ArchivedUserActivity.php | 9 ++---- app/Listeners/User/CreatedUserActivity.php | 10 ++----- app/Listeners/User/DeletedUserActivity.php | 8 ++---- app/Listeners/User/RestoredUserActivity.php | 9 ++---- app/Listeners/User/UpdatedUserActivity.php | 11 ++------ app/Models/Activity.php | 10 +++---- app/Models/SystemLog.php | 10 ++++++- app/Providers/EventServiceProvider.php | 21 ++++++++++++-- app/Repositories/ActivityRepository.php | 8 +++++- app/Repositories/UserRepository.php | 31 ++++++++++++++++++++- 16 files changed, 110 insertions(+), 51 deletions(-) diff --git a/app/Events/User/UserWasArchived.php b/app/Events/User/UserWasArchived.php index def181fc2b60..f617daaae91b 100644 --- a/app/Events/User/UserWasArchived.php +++ b/app/Events/User/UserWasArchived.php @@ -31,6 +31,8 @@ class UserWasArchived */ public $user; + public $creating_user; + public $company; public $event_vars; @@ -42,9 +44,10 @@ class UserWasArchived * @param Company $company * @param array $event_vars */ - public function __construct(User $user, Company $company, array $event_vars) + public function __construct(User $user, User $creating_user, Company $company, array $event_vars) { $this->user = $user; + $this->creating_user = $creating_user; $this->company = $company; $this->event_vars = $event_vars; } diff --git a/app/Events/User/UserWasCreated.php b/app/Events/User/UserWasCreated.php index 49d2a901b764..101706fe002d 100644 --- a/app/Events/User/UserWasCreated.php +++ b/app/Events/User/UserWasCreated.php @@ -31,6 +31,8 @@ class UserWasCreated */ public $user; + public $creating_user; + public $company; public $event_vars; @@ -42,9 +44,10 @@ class UserWasCreated * @param Company $company * @param array $event_vars */ - public function __construct(User $user, Company $company, array $event_vars) + public function __construct(User $user, User $creating_user, Company $company, array $event_vars) { $this->user = $user; + $this->creating_user = $creating_user; $this->company = $company; $this->event_vars = $event_vars; } diff --git a/app/Events/User/UserWasDeleted.php b/app/Events/User/UserWasDeleted.php index 2ebc78ce32b2..c0010ec9aa89 100644 --- a/app/Events/User/UserWasDeleted.php +++ b/app/Events/User/UserWasDeleted.php @@ -31,6 +31,8 @@ class UserWasDeleted */ public $user; + public $creating_user; + public $company; public $event_vars; @@ -42,9 +44,10 @@ class UserWasDeleted * @param Company $company * @param array $event_vars */ - public function __construct(User $user, Company $company, array $event_vars) + public function __construct(User $user, User $creating_user, Company $company, array $event_vars) { $this->user = $user; + $this->creating_user = $creating_user; $this->company = $company; $this->event_vars = $event_vars; } diff --git a/app/Events/User/UserWasRestored.php b/app/Events/User/UserWasRestored.php index b880d799af7d..9f60470842df 100644 --- a/app/Events/User/UserWasRestored.php +++ b/app/Events/User/UserWasRestored.php @@ -35,7 +35,7 @@ class UserWasRestored public $event_vars; - public $fromDeleted; + public $creating_user; /** * Create a new event instance. @@ -44,12 +44,12 @@ class UserWasRestored * @param Company $company * @param array $event_vars */ - public function __construct(User $user, bool $fromDeleted, Company $company, array $event_vars) + public function __construct(User $user, User $creating_user, Company $company, array $event_vars) { $this->user = $user; $this->company = $company; $this->event_vars = $event_vars; - $this->fromDeleted = $fromDeleted; + $this->creating_user = $creating_user; } /** diff --git a/app/Events/User/UserWasUpdated.php b/app/Events/User/UserWasUpdated.php index ac2c953ff32b..fa3c5c45dbb0 100644 --- a/app/Events/User/UserWasUpdated.php +++ b/app/Events/User/UserWasUpdated.php @@ -31,6 +31,8 @@ class UserWasUpdated */ public $user; + public $creating_user; + public $company; public $event_vars; @@ -42,9 +44,10 @@ class UserWasUpdated * @param Company $company * @param array $event_vars */ - public function __construct(User $user, Company $company, array $event_vars) + public function __construct(User $user, User $creating_user, Company $company, array $event_vars) { $this->user = $user; + $this->creating_user = $creating_user; $this->company = $company; $this->event_vars = $event_vars; } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 5b2a1ebf2ad3..80509d283e13 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -13,6 +13,8 @@ namespace App\Http\Controllers; use App\DataMapper\CompanySettings; use App\Events\User\UserWasCreated; +use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasUpdated; use App\Factory\UserFactory; use App\Filters\UserFilters; use App\Http\Controllers\Traits\VerifiesUserEmail; @@ -202,7 +204,7 @@ class UserController extends BaseController $ct = CreateCompanyToken::dispatchNow($company, $user, $user_agent); - event(new UserWasCreated($user, $company, Ninja::eventVars())); + event(new UserWasCreated($user, auth()->user(), $company, Ninja::eventVars())); return $this->itemResponse($user->fresh()); } @@ -376,6 +378,8 @@ class UserController extends BaseController UserEmailChanged::dispatch($new_email, $old_email, auth()->user()->company()); } + event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars())); + return $this->itemResponse($user); } @@ -444,6 +448,8 @@ class UserController extends BaseController /* If the user passes the company user we archive the company user */ $user = $this->user_repo->destroy($request->all(), $user); + event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars())); + return $this->itemResponse($user->fresh()); } diff --git a/app/Listeners/User/ArchivedUserActivity.php b/app/Listeners/User/ArchivedUserActivity.php index 1b52cb3db0d8..baad1fcf549d 100644 --- a/app/Listeners/User/ArchivedUserActivity.php +++ b/app/Listeners/User/ArchivedUserActivity.php @@ -43,13 +43,10 @@ class ArchivedUserActivity implements ShouldQueue $fields = new stdClass; - if (auth()->user()->id) { - $fields->user_id = auth()->user()->id; - } else { - $fields->user_id = $event->user->id; - } + $fields->user_id = $event->user->id; + $fields->notes = $event->creating_user->present()->name . " Archived User"; - $fields->company_id = $event->user->company_id; + $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::ARCHIVE_USER; $this->activityRepo->save($fields, $event->user, $event->event_vars); diff --git a/app/Listeners/User/CreatedUserActivity.php b/app/Listeners/User/CreatedUserActivity.php index 4e7612e736bc..757253f0e744 100644 --- a/app/Listeners/User/CreatedUserActivity.php +++ b/app/Listeners/User/CreatedUserActivity.php @@ -43,13 +43,9 @@ class CreatedUserActivity implements ShouldQueue $fields = new stdClass; - if (auth()->user()) { - $fields->user_id = auth()->user()->id; - } else { - $fields->user_id = $event->user->id; - } - - $fields->company_id = $event->user->company_id; + $fields->user_id = $event->user->id; + $fields->notes = $event->creating_user->present()->name() . " Created the user"; + $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::CREATE_USER; $this->activityRepo->save($fields, $event->user, $event->event_vars); diff --git a/app/Listeners/User/DeletedUserActivity.php b/app/Listeners/User/DeletedUserActivity.php index a319b09430d3..c530fa2c204a 100644 --- a/app/Listeners/User/DeletedUserActivity.php +++ b/app/Listeners/User/DeletedUserActivity.php @@ -48,12 +48,8 @@ class DeletedUserActivity implements ShouldQueue $fields = new stdClass; - if (auth()->check()) { - $fields->user_id = auth()->user()->id; - } else { - $fields->user_id = $event->user->id; - } - + $fields->user_id = $event->user->id; + $fields->notes = $event->creating_user->present()->name . " Deleted User"; $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::DELETE_USER; diff --git a/app/Listeners/User/RestoredUserActivity.php b/app/Listeners/User/RestoredUserActivity.php index 6977b8e3f970..77fbc99870d1 100644 --- a/app/Listeners/User/RestoredUserActivity.php +++ b/app/Listeners/User/RestoredUserActivity.php @@ -43,13 +43,10 @@ class RestoredUserActivity implements ShouldQueue $fields = new stdClass; - if (auth()->user()->id) { - $fields->user_id = auth()->user()->id; - } else { - $fields->user_id = $event->user->id; - } + $fields->user_id = $event->user->id; + $fields->notes = $event->creating_user->present()->name() . " Restored user"; - $fields->company_id = $event->user->company_id; + $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::RESTORE_USER; $this->activityRepo->save($fields, $event->user, $event->event_vars); diff --git a/app/Listeners/User/UpdatedUserActivity.php b/app/Listeners/User/UpdatedUserActivity.php index cf628e40be35..a94121dcd61d 100644 --- a/app/Listeners/User/UpdatedUserActivity.php +++ b/app/Listeners/User/UpdatedUserActivity.php @@ -42,14 +42,9 @@ class UpdatedUserActivity implements ShouldQueue MultiDB::setDb($event->company->db); $fields = new stdClass; - - if (auth()->user()->id) { - $fields->user_id = auth()->user()->id; - } else { - $fields->user_id = $event->user->id; - } - - $fields->company_id = $event->user->company_id; + $fields->user_id = $event->user->id; + $fields->notes = $event->creating_user->present()->name . " Updated user"; + $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::UPDATE_USER; $this->activityRepo->save($fields, $event->user, $event->event_vars); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 159cff11b7e5..9197606460ff 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -65,11 +65,11 @@ class Activity extends StaticModel const RESTORE_TASK = 46; // const UPDATE_EXPENSE = 47;// - const CREATE_USER = 48; // only used in CreateUser::job - const UPDATE_USER = 49; // not needed? - const ARCHIVE_USER = 50; // not needed? - const DELETE_USER = 51; // not needed? - const RESTORE_USER = 52; // not needed? + const CREATE_USER = 48; + const UPDATE_USER = 49; + const ARCHIVE_USER = 50; + const DELETE_USER = 51; + const RESTORE_USER = 52; const MARK_SENT_INVOICE = 53; // not needed? const PAID_INVOICE = 54; // const EMAIL_INVOICE_FAILED = 57; diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php index 0be18903a7d6..5134967a4630 100644 --- a/app/Models/SystemLog.php +++ b/app/Models/SystemLog.php @@ -34,7 +34,8 @@ class SystemLog extends Model const CATEGORY_GATEWAY_RESPONSE = 1; const CATEGORY_MAIL = 2; const CATEGORY_WEBHOOK = 3; - const CATEGORY_PDF = 3; + const CATEGORY_PDF = 4; + const CATEGORY_SECURITY = 5; /* Event IDs*/ const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10; @@ -50,6 +51,9 @@ class SystemLog extends Model const EVENT_WEBHOOK_RESPONSE = 40; const EVENT_PDF_RESPONSE = 50; + const EVENT_AUTHENTICATION_FAILURE = 60; + const EVENT_USER = 61; + /*Type IDs*/ const TYPE_PAYPAL = 300; const TYPE_STRIPE = 301; @@ -62,9 +66,13 @@ class SystemLog extends Model const TYPE_UPSTREAM_FAILURE = 401; const TYPE_WEBHOOK_RESPONSE = 500; + const TYPE_PDF_FAILURE = 600; const TYPE_PDF_SUCCESS = 601; + const TYPE_MODIFIED = 701; + const TYPE_DELETED = 702; + protected $fillable = [ 'client_id', 'company_id', diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9392b87c3349..b77a47db3c4f 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -72,8 +72,11 @@ use App\Events\Task\TaskWasDeleted; use App\Events\Task\TaskWasRestored; use App\Events\Task\TaskWasUpdated; use App\Events\User\UserLoggedIn; +use App\Events\User\UserWasArchived; use App\Events\User\UserWasCreated; use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasRestored; +use App\Events\User\UserWasUpdated; use App\Events\Vendor\VendorWasArchived; use App\Events\Vendor\VendorWasCreated; use App\Events\Vendor\VendorWasDeleted; @@ -123,8 +126,8 @@ use App\Listeners\Invoice\InvoiceArchivedActivity; use App\Listeners\Invoice\InvoiceCancelledActivity; use App\Listeners\Invoice\InvoiceDeletedActivity; use App\Listeners\Invoice\InvoiceEmailActivity; -use App\Listeners\Invoice\InvoiceEmailedNotification; use App\Listeners\Invoice\InvoiceEmailFailedActivity; +use App\Listeners\Invoice\InvoiceEmailedNotification; use App\Listeners\Invoice\InvoicePaidActivity; use App\Listeners\Invoice\InvoiceReminderEmailActivity; use App\Listeners\Invoice\InvoiceRestoredActivity; @@ -132,8 +135,8 @@ use App\Listeners\Invoice\InvoiceReversedActivity; use App\Listeners\Invoice\InvoiceViewedActivity; use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Misc\InvitationViewedListener; -use App\Listeners\Payment\PaymentEmailedActivity; use App\Listeners\Payment\PaymentEmailFailureActivity; +use App\Listeners\Payment\PaymentEmailedActivity; use App\Listeners\Payment\PaymentNotification; use App\Listeners\Payment\PaymentRestoredActivity; use App\Listeners\Quote\QuoteApprovedActivity; @@ -145,8 +148,12 @@ use App\Listeners\Quote\QuoteRestoredActivity; use App\Listeners\Quote\QuoteViewedActivity; use App\Listeners\Quote\ReachWorkflowSettings; use App\Listeners\SendVerificationNotification; +use App\Listeners\User\ArchivedUserActivity; +use App\Listeners\User\CreatedUserActivity; use App\Listeners\User\DeletedUserActivity; +use App\Listeners\User\RestoredUserActivity; use App\Listeners\User\UpdateUserLastLogin; +use App\Listeners\User\UpdatedUserActivity; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider @@ -158,14 +165,24 @@ class EventServiceProvider extends ServiceProvider */ protected $listen = [ UserWasCreated::class => [ + CreatedUserActivity::class, SendVerificationNotification::class, ], UserWasDeleted::class => [ DeletedUserActivity::class, ], + UserWasArchived::class => [ + ArchivedUserActivity::class, + ], UserLoggedIn::class => [ UpdateUserLastLogin::class, ], + UserWasUpdated::class => [ + UpdatedUserActivity::class, + ], + UserWasRestored::class => [ + RestoredUserActivity::class, + ], ContactLoggedIn::class => [ UpdateContactLastLogin::class, ], diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index d5eb91a8e27c..2f36415a1b73 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -19,6 +19,7 @@ use App\Models\Design; use App\Models\Invoice; use App\Models\Quote; use App\Models\RecurringInvoice; +use App\Models\User; use App\Services\PdfMaker\Design as PdfDesignModel; use App\Services\PdfMaker\Design as PdfMakerDesign; use App\Services\PdfMaker\PdfMaker as PdfMakerService; @@ -69,7 +70,12 @@ class ActivityRepository extends BaseRepository */ public function createBackup($entity, $activity) { - if ($entity->company->is_disabled) { + nlog($entity); + + if($entity instanceof User){ + + } + else if ($entity->company->is_disabled) { return; } diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 294c07f7962e..74dd0fe05b4f 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -12,7 +12,9 @@ namespace App\Repositories; use App\DataMapper\CompanySettings; +use App\Events\User\UserWasArchived; use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasRestored; use App\Models\CompanyUser; use App\Models\User; use App\Utils\Ninja; @@ -137,7 +139,7 @@ class UserRepository extends BaseRepository $cu->delete(); } - event(new UserWasDeleted($user, $company, Ninja::eventVars())); + event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars())); $user->is_deleted = true; $user->save(); @@ -146,4 +148,31 @@ class UserRepository extends BaseRepository return $user->fresh(); } + + public function archive($user) + { + if ($user->trashed()) { + return; + } + + $user->delete(); + + event(new UserWasArchived($user, auth()->user(), auth()->user()->company, Ninja::eventVars())); + + } + + /** + * @param $entity + */ + public function restore($user) + { + if (! $user->trashed()) { + return; + } + + $user->restore(); + + event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars())); + + } } From 29038a16fa39ae033a39b1a01974cdd20634efea Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 14:56:21 +1100 Subject: [PATCH 6/8] Fixes for tests --- app/Repositories/ActivityRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 2f36415a1b73..1e81e79acc26 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -70,7 +70,6 @@ class ActivityRepository extends BaseRepository */ public function createBackup($entity, $activity) { - nlog($entity); if($entity instanceof User){ From 8b22fa5a47e0e044314e342069e5647b153860c8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 15:31:45 +1100 Subject: [PATCH 7/8] Fixes for user events --- .../ClientPortal/PaymentController.php | 2 +- app/Http/Controllers/TaskStatusController.php | 2 +- app/Mail/Admin/EntitySentObject.php | 2 +- tests/Feature/InvoiceTest.php | 4 +- tests/Integration/EventTest.php | 100 +++++++++++++++++- tests/MockAccountData.php | 1 + 6 files changed, 105 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 4f2b70846389..a5abd4e8a51b 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -175,7 +175,7 @@ class PaymentController extends Controller foreach($payable_invoices as $payable_invoice) { - nlog($payable_invoice); + // nlog($payable_invoice); $payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']); diff --git a/app/Http/Controllers/TaskStatusController.php b/app/Http/Controllers/TaskStatusController.php index ccb9533a06ec..7bae5b0f4b18 100644 --- a/app/Http/Controllers/TaskStatusController.php +++ b/app/Http/Controllers/TaskStatusController.php @@ -174,7 +174,7 @@ class TaskStatusController extends BaseController */ public function store(StoreTaskStatusRequest $request) { - nlog($request->all()); + // nlog($request->all()); $task_status = TaskStatusFactory::create(auth()->user()->company()->id, auth()->user()->id); $task_status->fill($request->all()); diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index f8cd6a2a8e3b..3e0f9c8f76e2 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -60,7 +60,7 @@ class EntitySentObject private function setTemplate() { - nlog($this->template); + // nlog($this->template); switch ($this->template) { case 'invoice': diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index fc091bbefc14..8ad15adfc832 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -184,8 +184,8 @@ class InvoiceTest extends TestCase ->assertStatus(302); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); - nlog('inside update invoice validator'); - nlog($message); + // nlog('inside update invoice validator'); + // nlog($message); $this->assertNotNull($message); } diff --git a/tests/Integration/EventTest.php b/tests/Integration/EventTest.php index 6fd67587e1be..d161bc41b11e 100644 --- a/tests/Integration/EventTest.php +++ b/tests/Integration/EventTest.php @@ -46,14 +46,23 @@ use App\Events\Task\TaskWasCreated; use App\Events\Task\TaskWasDeleted; use App\Events\Task\TaskWasRestored; use App\Events\Task\TaskWasUpdated; +use App\Events\User\UserWasArchived; +use App\Events\User\UserWasCreated; +use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasRestored; +use App\Events\User\UserWasUpdated; use App\Events\Vendor\VendorWasArchived; use App\Events\Vendor\VendorWasCreated; use App\Events\Vendor\VendorWasDeleted; use App\Events\Vendor\VendorWasRestored; use App\Events\Vendor\VendorWasUpdated; +use App\Http\Middleware\PasswordProtection; use App\Models\Invoice; use App\Models\Quote; use App\Utils\Traits\MakesHash; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Testing\DatabaseTransactions; +use Illuminate\Routing\Middleware\ThrottleRequests; use Tests\MockAccountData; use Tests\TestCase; @@ -64,6 +73,7 @@ class EventTest extends TestCase { use MockAccountData; use MakesHash; + use DatabaseTransactions; public function setUp() :void { @@ -72,6 +82,13 @@ class EventTest extends TestCase $this->faker = \Faker\Factory::create(); $this->makeTestData(); + + Model::reguard(); + + $this->withoutMiddleware( + ThrottleRequests::class, + PasswordProtection::class + ); } public function testExpenseEvents() @@ -134,6 +151,7 @@ class EventTest extends TestCase public function testVendorEvents() { + $this->expectsEvents([ VendorWasCreated::class, VendorWasUpdated::class, @@ -456,7 +474,6 @@ class EventTest extends TestCase public function testInvoiceEvents() { - /* Test fire new invoice */ $data = [ 'client_id' => $this->client->hashed_id, @@ -573,4 +590,85 @@ class EventTest extends TestCase ])->post('/api/v1/clients/bulk?action=delete', $data) ->assertStatus(200); } + + + public function testUserEvents() + { + $this->withoutMiddleware(PasswordProtection::class); + + + $this->expectsEvents([ + UserWasCreated::class, + UserWasUpdated::class, + UserWasArchived::class, + UserWasRestored::class, + UserWasDeleted::class, + ]); + + $data = [ + 'first_name' => 'hey', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users?include=company_user', $data) + ->assertStatus(200); + + $arr = $response->json(); + + $data = [ + 'first_name' => 'hasdasdy', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->put('/api/v1/users/' . $arr['data']['id'], $data) + ->assertStatus(200); + + + $data = [ + 'ids' => [$arr['data']['id']], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=archive', $data) + ->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=restore', $data) + ->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=delete', $data) + ->assertStatus(200); + } + + } diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index aad2f31056d7..db300ab645e4 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -189,6 +189,7 @@ trait MockAccountData $this->user = User::factory()->create([ 'account_id' => $this->account->id, 'confirmation_code' => $this->createDbHash(config('database.default')), + 'email' => 'user@example.com', ]); } From 1ff29a2d55511d926094bea8090d1f0a96a5de8e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 14 Jan 2021 20:31:27 +1100 Subject: [PATCH 8/8] Fix for usercreated event --- .github/workflows/release.yml | 2 +- app/Helpers/Generic.php | 4 ++++ app/Jobs/User/CreateUser.php | 2 +- public/css/card-js.min.css | 0 tests/Feature/Export/ExportCsvTest.php | 4 ++-- tests/Feature/LoginTest.php | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) mode change 100644 => 100755 public/css/card-js.min.css diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9b5164999ec..9e08efd48a7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,7 @@ jobs: - name: Cleanup Builds run: | sudo rm -rf bootstrap/cache/* - + sudo rm -rf node_modules - name: Build project # This would actually build your project, using zip for an example artifact run: | zip -r ./invoiceninja.zip ./ diff --git a/app/Helpers/Generic.php b/app/Helpers/Generic.php index d6fca896f94c..fc3444176fed 100644 --- a/app/Helpers/Generic.php +++ b/app/Helpers/Generic.php @@ -21,6 +21,10 @@ */ function nlog($output, $context = []): void { + $trace = debug_backtrace(); + + \Illuminate\Support\Facades\Log::channel('invoiceninja')->info(print_r($trace[1]['class'],1), []); + if (config('ninja.expanded_logging')) { if (gettype($output) == 'object') { $output = print_r($output, 1); diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index f517267ed7e9..4a81aad3d5c3 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -78,7 +78,7 @@ class CreateUser 'settings' => null, ]); - event(new UserWasCreated($user, $this->company, Ninja::eventVars())); + event(new UserWasCreated($user, $user, $this->company, Ninja::eventVars())); return $user; } diff --git a/public/css/card-js.min.css b/public/css/card-js.min.css old mode 100644 new mode 100755 diff --git a/tests/Feature/Export/ExportCsvTest.php b/tests/Feature/Export/ExportCsvTest.php index abe2e610087f..d1ac66b6e91f 100644 --- a/tests/Feature/Export/ExportCsvTest.php +++ b/tests/Feature/Export/ExportCsvTest.php @@ -58,8 +58,8 @@ class ExportCsvTest extends TestCase $merged_values = array_merge($header_invoice_values, (array)$header_item_values); $merged_keys = array_merge($header_invoice_keys, (array)$header_item_keys); - nlog(print_r($merged_keys, 1)); - nlog(print_r($merged_values, 1)); + // nlog(print_r($merged_keys, 1)); + // nlog(print_r($merged_values, 1)); foreach ($merged_keys as &$key) { diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index b9d3648c8254..ae2289fbd00d 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -195,7 +195,7 @@ class LoginTest extends TestCase $arr = $response->json(); - nlog(print_r($arr, 1)); + // nlog(print_r($arr, 1)); $response->assertStatus(200); }