From 97b49f8df69f657b604bc13c07fa117d45b0ae0f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 14 May 2021 13:32:37 +1000 Subject: [PATCH 1/4] Fixes for download export button --- .../ClientPortal/ContactHashLoginController.php | 4 ++-- app/Http/Middleware/ContactKeyLogin.php | 2 +- app/Jobs/Company/CompanyExport.php | 6 ++++-- resources/views/email/admin/download_files.blade.php | 7 ++++++- tests/Feature/Export/ExportCompanyTest.php | 4 ++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/ContactHashLoginController.php b/app/Http/Controllers/ClientPortal/ContactHashLoginController.php index bffbf0ff6450..4a6a7470cf71 100644 --- a/app/Http/Controllers/ClientPortal/ContactHashLoginController.php +++ b/app/Http/Controllers/ClientPortal/ContactHashLoginController.php @@ -24,12 +24,12 @@ class ContactHashLoginController extends Controller */ public function login(string $contact_key) { - return redirect('/client/login'); + return redirect('/client/invoices'); } public function magicLink(string $magic_link) { - return redirect('/client/login'); + return redirect('/client/invoices'); } public function errorPage() diff --git a/app/Http/Middleware/ContactKeyLogin.php b/app/Http/Middleware/ContactKeyLogin.php index 9de9034bda2f..4ababf873a0b 100644 --- a/app/Http/Middleware/ContactKeyLogin.php +++ b/app/Http/Middleware/ContactKeyLogin.php @@ -42,7 +42,7 @@ class ContactKeyLogin if (MultiDB::findAndSetDbByContactKey($request->segment(3))) { if($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()){ - auth()->guard('contact')->login($client_contact, true); + Auth::guard('contact')->login($client_contact, true); return redirect()->to('client/dashboard'); } diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 935b088c401b..8a4fede84ca5 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -66,7 +66,7 @@ class CompanyExport implements ShouldQueue * * @return CompanyToken|null */ - public function handle() : void + public function handle() { MultiDB::setDb($this->company->db); @@ -405,7 +405,9 @@ class CompanyExport implements ShouldQueue //write to tmp and email to owner(); - $this->zipAndSend(); + $this->zipAndSend(); + + return true; } private function transformBasicEntities($model) diff --git a/resources/views/email/admin/download_files.blade.php b/resources/views/email/admin/download_files.blade.php index d1f58b786d25..f1ca9d417c62 100644 --- a/resources/views/email/admin/download_files.blade.php +++ b/resources/views/email/admin/download_files.blade.php @@ -1,7 +1,7 @@ @component('email.template.master', ['design' => 'light', 'settings' =>$settings]) @slot('header') - @component('email.components.header', ['p' => '', 'logo' => $url]) + @component('email.components.header', ['p' => '', 'logo' => $logo]) @lang('texts.download') @endcomponent @@ -12,6 +12,11 @@ @lang('texts.download_timeframe') + + @component('email.components.button', ['url' => $url]) + @lang('texts.download') + @endcomponent + @slot('signature') InvoiceNinja (contact@invoiceninja.com) @endslot diff --git a/tests/Feature/Export/ExportCompanyTest.php b/tests/Feature/Export/ExportCompanyTest.php index c30e85417a0e..82bb57e9f318 100644 --- a/tests/Feature/Export/ExportCompanyTest.php +++ b/tests/Feature/Export/ExportCompanyTest.php @@ -44,8 +44,8 @@ class ExportCompanyTest extends TestCase public function testCompanyExport() { - CompanyExport::dispatchNow($this->company, $this->company->users->first()); + $res = CompanyExport::dispatchNow($this->company, $this->company->users->first()); - $this->assertTrue(true); + $this->assertTrue($res); } } From 8e682f474cbcedfb7bc2886f129301939fc0f919 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 14 May 2021 15:23:00 +1000 Subject: [PATCH 2/4] Import Company --- app/Exceptions/NonExistingBackupFile.php | 10 ++ app/Jobs/Company/CompanyImport.php | 127 +++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 app/Exceptions/NonExistingBackupFile.php create mode 100644 app/Jobs/Company/CompanyImport.php diff --git a/app/Exceptions/NonExistingBackupFile.php b/app/Exceptions/NonExistingBackupFile.php new file mode 100644 index 000000000000..77c29936d6e6 --- /dev/null +++ b/app/Exceptions/NonExistingBackupFile.php @@ -0,0 +1,10 @@ +company = $company; + $this->file_path = $file_path; + $this->options = $options; + } + + public function handle() + { + MultiDB::setDb($this->company->db); + + $this->company =Company::where('company_key', $this->company->company_key)->firstOrFail(); + + $this->unzipFile() + ->preFlightChecks(); + + } + + + //check if this is a complete company import OR if it is selective + /* + Company and settings only + Data + */ + + private function preFlightChecks() + { + //check the file version and perform any necessary adjustments to the file in order to proceed - needed when we change schema + // + $app_version = $this->backup_file->app_version; + + nlog($app_version); + + return $this; + } + + private function unzipFile() + { + $zip = new ZipArchive(); + $archive = $zip->open(public_path("storage/backups/{$this->file_path}")); + $filename = pathinfo($this->filepath, PATHINFO_FILENAME); + $zip->extractTo(public_path("storage/backups/{$filename}")); + $zip->close(); + $file_location = public_path("storage/backups/$filename/backup.json"); + + if (! file_exists($file_location)) { + throw new NonExistingMigrationFile('Backup file does not exist, or it is corrupted.'); + } + + $this->backup_file = json_decode(file_get_contents($file_location)); + + return $this; + } + + private function importCompany() + { + + //$this->import_company = .. + return $this; + } + + private function importData() + { + // $this->import_company = Company::where('company_key', $this->company->company_key)->firstOrFail(); + + return $this; + } +} \ No newline at end of file From f61ba70b148d7119d0a72f733da1ff896cd0217f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 14 May 2021 16:00:25 +1000 Subject: [PATCH 3/4] Tests for company import --- app/Jobs/Company/CompanyExport.php | 3 +- tests/Feature/Import/ImportCompanyTest.php | 56 ++++++++++++++++++++++ tests/Feature/Import/backup.json | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/Import/ImportCompanyTest.php create mode 100644 tests/Feature/Import/backup.json diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 8a4fede84ca5..5a410a070c34 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -149,7 +149,8 @@ class CompanyExport implements ShouldQueue $this->export_data['company_gateways'] = $this->company->company_gateways->map(function ($company_gateway){ $company_gateway = $this->transformArrayOfKeys($company_gateway, ['company_id', 'user_id']); - + $company_gateway->config = decrypt($company_gateway->config); + return $company_gateway; })->toArray(); diff --git a/tests/Feature/Import/ImportCompanyTest.php b/tests/Feature/Import/ImportCompanyTest.php new file mode 100644 index 000000000000..01b4e9f916c5 --- /dev/null +++ b/tests/Feature/Import/ImportCompanyTest.php @@ -0,0 +1,56 @@ +withoutMiddleware( + ThrottleRequests::class + ); + + + $this->withoutExceptionHandling(); + } + + public function testBackupJsonRead() + { + $backup_json_file = base_path().'/tests/Feature/Import/backup.json'; + + $this->assertTrue(is_array(json_decode(file_get_contents($backup_json_file),1))); + } + +} diff --git a/tests/Feature/Import/backup.json b/tests/Feature/Import/backup.json new file mode 100644 index 000000000000..a49c25849b4b --- /dev/null +++ b/tests/Feature/Import/backup.json @@ -0,0 +1 @@ +{"app_version":"5.1.62","activities":[{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"VWPe9OYbLy","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":5,"ip":"","is_system":false,"notes":"","created_at":1620971761,"updated_at":1620971761,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"VWPe9OYbLy","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":4,"ip":"","is_system":false,"notes":"","created_at":1620971762,"updated_at":1620971762,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"QnXe0O3dxr","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":5,"ip":"","is_system":false,"notes":"","created_at":1620971762,"updated_at":1620971762,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"QnXe0O3dxr","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":4,"ip":"","is_system":false,"notes":"","created_at":1620971763,"updated_at":1620971763,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"Wjneg6DdwZ","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":5,"ip":"","is_system":false,"notes":"","created_at":1620971763,"updated_at":1620971763,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"Wjneg6DdwZ","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":4,"ip":"","is_system":false,"notes":"","created_at":1620971764,"updated_at":1620971764,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"VolejLBbjN","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":5,"ip":"","is_system":false,"notes":"","created_at":1620971764,"updated_at":1620971764,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"VolejLBbjN","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":4,"ip":"","is_system":false,"notes":"","created_at":1620971765,"updated_at":1620971765,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"WpmbkDKdzJ","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":5,"ip":"","is_system":false,"notes":"","created_at":1620971765,"updated_at":1620971765,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"VWPe9xdLyw","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"WpmbkDKdzJ","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":4,"ip":"","is_system":false,"notes":"","created_at":1620971766,"updated_at":1620971766,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""},{"user_id":"WJxbojagwO","company_id":"gl9avmeG1v","client_id":"","client_contact_id":"","account_id":"","project_id":"","vendor_id":"","payment_id":"","invoice_id":"","credit_id":"","invitation_id":"","task_id":"","expense_id":"","activity_type_id":49,"ip":"","is_system":false,"notes":"Noe Reynolds Beatrice Reichel Updated user Noe Reynolds Beatrice Reichel","created_at":1620971766,"updated_at":1620971766,"token_id":"","quote_id":"","subscription_id":"","recurring_invoice_id":""}],"backups":[{"id":68,"activity_id":"kQBeXqoayK","json_backup":"","html_backup":"\n