From f98319a1c1eb832a29130feda96b44f8629b1b9b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Sep 2020 09:29:46 +1000 Subject: [PATCH 1/5] Fixes for phpunit --- .github/workflows/phpunit.yml | 2 +- app/Http/Middleware/QueryLogging.php | 4 +++- composer.lock | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 59e4b797b1d0..74964b338637 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -30,7 +30,7 @@ jobs: MULTI_DB_ENABLED: false NINJA_LICENSE: 123456 TRAVIS: true - MAIL_DRIVER: log + MAIL_MAILER: log services: mariadb: diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 64f8742da083..4841c12bbc8b 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -31,10 +31,12 @@ class QueryLogging */ public function handle(Request $request, Closure $next) { + + $timeStart = microtime(true); + // Enable query logging for development if (config('ninja.app_env') != 'production') { DB::enableQueryLog(); - $timeStart = microtime(true); } $response = $next($request); diff --git a/composer.lock b/composer.lock index e8f87a8c7615..88e234c82257 100644 --- a/composer.lock +++ b/composer.lock @@ -1541,16 +1541,16 @@ }, { "name": "egulias/email-validator", - "version": "2.1.19", + "version": "2.1.20", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "840d5603eb84cc81a6a0382adac3293e57c1c64c" + "reference": "f46887bc48db66c7f38f668eb7d6ae54583617ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/840d5603eb84cc81a6a0382adac3293e57c1c64c", - "reference": "840d5603eb84cc81a6a0382adac3293e57c1c64c", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/f46887bc48db66c7f38f668eb7d6ae54583617ff", + "reference": "f46887bc48db66c7f38f668eb7d6ae54583617ff", "shasum": "" }, "require": { @@ -1595,7 +1595,7 @@ "validation", "validator" ], - "time": "2020-08-08T21:28:19+00:00" + "time": "2020-09-06T13:44:32+00:00" }, { "name": "fedeisas/laravel-mail-css-inliner", @@ -4364,16 +4364,16 @@ }, { "name": "opis/closure", - "version": "3.5.6", + "version": "3.5.7", "source": { "type": "git", "url": "https://github.com/opis/closure.git", - "reference": "e8d34df855b0a0549a300cb8cb4db472556e8aa9" + "reference": "4531e53afe2fc660403e76fb7644e95998bff7bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opis/closure/zipball/e8d34df855b0a0549a300cb8cb4db472556e8aa9", - "reference": "e8d34df855b0a0549a300cb8cb4db472556e8aa9", + "url": "https://api.github.com/repos/opis/closure/zipball/4531e53afe2fc660403e76fb7644e95998bff7bf", + "reference": "4531e53afe2fc660403e76fb7644e95998bff7bf", "shasum": "" }, "require": { @@ -4421,7 +4421,7 @@ "serialization", "serialize" ], - "time": "2020-08-11T08:46:50+00:00" + "time": "2020-09-06T17:02:15+00:00" }, { "name": "paragonie/random_compat", @@ -11053,7 +11053,6 @@ "keywords": [ "tokenizer" ], - "abandoned": true, "time": "2019-09-17T06:23:10+00:00" }, { From d909b4939cd98fc0cf4820d1777ea1a41564e520 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Sep 2020 13:14:43 +1000 Subject: [PATCH 2/5] Minor fixes for PayPal --- app/Jobs/Invoice/CreateInvoicePdf.php | 2 +- app/PaymentDrivers/PayPalExpressPaymentDriver.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index b85b3309d6c0..acc644594a98 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -111,7 +111,7 @@ class CreateInvoicePdf implements ShouldQueue //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0775); - info($maker->getCompiledHTML(true)); + //info($maker->getCompiledHTML(true)); $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index 76f6d0a817cc..76b8600efd63 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -262,6 +262,13 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment { + $payment_meta = new \stdClass; + $payment_meta->exp_month = 'xx'; + $payment_meta->exp_year = 'xx'; + $payment_meta->brand = 'PayPal'; + $payment_meta->last4 = 'xxxx'; + $payment_meta->type = GatewayType::PAYPAL; + $payment = parent::createPayment($data, $status); $client_contact = $this->getContact(); @@ -271,6 +278,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver $payment->type_id = PaymentType::PAYPAL; $payment->transaction_reference = $data['PAYMENTINFO_0_TRANSACTIONID']; $payment->client_contact_id = $client_contact_id; + $payment->meta = $payment_meta; $payment->save(); return $payment; From 18282acbd7af9944bac2909bc96faf82c57ee2f2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Sep 2020 14:49:57 +1000 Subject: [PATCH 3/5] Allow circumvention of client portal passwords using designated hash --- .../ClientPortal/EntityViewController.php | 9 ++-- .../ClientPortal/InvitationController.php | 45 ++++++++++--------- config/filesystems.php | 2 +- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/EntityViewController.php b/app/Http/Controllers/ClientPortal/EntityViewController.php index e16b0c7f5a7d..f65230ca4dc7 100644 --- a/app/Http/Controllers/ClientPortal/EntityViewController.php +++ b/app/Http/Controllers/ClientPortal/EntityViewController.php @@ -33,17 +33,18 @@ class EntityViewController extends Controller $key = $entity_type.'_id'; - $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key])->firstOrFail(); + $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key]) + ->with('contact.client') + ->firstOrFail(); $contact = $invitation->contact; + $client = $contact->client; + $entity = $invitation->{$entity_type}; if (is_null($contact->password) || empty($contact->password)) { return redirect("/client/password/reset?email={$contact->email}"); } - $entity_class = sprintf('App\\Models\\%s', ucfirst($entity_type)); - $entity = $entity_class::findOrFail($invitation->{$key}); - if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { session()->flash("{$entity_type}_VIEW_{$entity->hashed_id}", true); } diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index aba552eed1b0..e891f57691b7 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -37,29 +37,34 @@ class InvitationController extends Controller $entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation'; - $invitation = $entity_obj::whereRaw('BINARY `key`= ?', [$invitation_key])->first(); + $invitation = $entity_obj::whereRaw('BINARY `key`= ?', [$invitation_key]) + ->with('contact.client') + ->firstOrFail(); - if ($invitation) { - if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { - $this->middleware('auth:contact'); - } else { - auth()->guard('contact')->login($invitation->contact, true); - } + /* Return early if we have the correct client_hash embedded */ - if (! request()->has('silent') && ! $invitation->viewed_date) { -// if (!request()->has('silent')) { - - $invitation->markViewed(); - - event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars())); - - $this->fireEntityViewedEvent($invitation, $entity); - } - - return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); - } else { - abort(404); + if(request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { + auth()->guard('contact')->login($invitation->contact, true); } + else if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { + $this->middleware('auth:contact'); + } + else { + auth()->guard('contact')->login($invitation->contact, true); + } + + if (auth()->guard('contact') && ! request()->has('silent') && ! $invitation->viewed_date) { + + $invitation->markViewed(); + + event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars())); + + $this->fireEntityViewedEvent($invitation, $entity); + } + + return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); + + } private function fireEntityViewedEvent($invitation, $entity_string) diff --git a/config/filesystems.php b/config/filesystems.php index 88314fa6121d..816d65b2b38c 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -13,7 +13,7 @@ return [ | */ - 'default' => env('FILESYSTEM_DRIVER', 'local'), + 'default' => env('FILESYSTEM_DRIVER', 'public'), /* |-------------------------------------------------------------------------- From 94508a30b3d631afc7ebf6f20e0cbe5568d25a7f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Sep 2020 20:00:20 +1000 Subject: [PATCH 4/5] Composer install --- app/Console/Commands/PostUpdate.php | 86 ++++++++++++++++------------- app/Http/Kernel.php | 4 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/app/Console/Commands/PostUpdate.php b/app/Console/Commands/PostUpdate.php index a675503c709c..425c3cee1ac1 100644 --- a/app/Console/Commands/PostUpdate.php +++ b/app/Console/Commands/PostUpdate.php @@ -51,49 +51,61 @@ class PostUpdate extends Command \Log::error("I wasn't able to optimize."); } - $composer_data = [ - 'url' => 'https://getcomposer.org/composer.phar', - 'dir' => __DIR__.'/.code', - 'bin' => __DIR__.'/.code/composer.phar', - 'json' => __DIR__.'/.code/composer.json', - 'conf' => [ - 'autoload' => [ - 'psr-4' => [ - '' => 'local/', - ], - ], - ], - ]; +// Composer\Factory::getHomeDir() method +// needs COMPOSER_HOME environment variable set + putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer'); - if (! is_dir($composer_data['dir'])) { - mkdir($composer_data['dir'], 0777, true); - } + // call `composer install` command programmatically + $input = new ArrayInput(array('command' => 'install')); + $application = new Application(); + $application->setAutoExit(false); + $application->run($input); - if (! is_dir("{$composer_data['dir']}/local")) { - mkdir("{$composer_data['dir']}/local", 0777, true); - } + echo "Done."; - copy($composer_data['url'], $composer_data['bin']); - require_once "phar://{$composer_data['bin']}/src/bootstrap.php"; + // $composer_data = [ + // 'url' => 'https://getcomposer.org/composer.phar', + // 'dir' => __DIR__.'/.code', + // 'bin' => __DIR__.'/.code/composer.phar', + // 'json' => __DIR__.'/.code/composer.json', + // 'conf' => [ + // 'autoload' => [ + // 'psr-4' => [ + // '' => 'local/', + // ], + // ], + // ], + // ]; - $conf_json = json_encode($composer_data['conf'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - file_put_contents($composer_data['json'], $conf_json); - chdir($composer_data['dir']); - putenv("COMPOSER_HOME={$composer_data['dir']}"); - putenv('OSTYPE=OS400'); - $app = new \Composer\Console\Application(); + // if (! is_dir($composer_data['dir'])) { + // mkdir($composer_data['dir'], 0777, true); + // } - $factory = new \Composer\Factory(); - $output = $factory->createOutput(); + // if (! is_dir("{$composer_data['dir']}/local")) { + // mkdir("{$composer_data['dir']}/local", 0777, true); + // } - $input = new \Symfony\Component\Console\Input\ArrayInput([ - 'command' => 'install', - ]); - $input->setInteractive(false); - echo '
';
-        $cmdret = $app->doRun($input, $output);
-        echo 'end!';
+        // copy($composer_data['url'], $composer_data['bin']);
+        // require_once "phar://{$composer_data['bin']}/src/bootstrap.php";
 
-        \Log::error(print_r($cmdret, 1));
+        // $conf_json = json_encode($composer_data['conf'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
+        // file_put_contents($composer_data['json'], $conf_json);
+        // chdir($composer_data['dir']);
+        // putenv("COMPOSER_HOME={$composer_data['dir']}");
+        // putenv('OSTYPE=OS400');
+        // $app = new \Composer\Console\Application();
+
+        // $factory = new \Composer\Factory();
+        // $output = $factory->createOutput();
+
+        // $input = new \Symfony\Component\Console\Input\ArrayInput([
+        //   'command' => 'install',
+        // ]);
+        // $input->setInteractive(false);
+        // echo '
';
+        // $cmdret = $app->doRun($input, $output);
+        // echo 'end!';
+
+        // \Log::error(print_r($cmdret, 1));
     }
 }
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 9365e1d547bc..4f69d563d31b 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -29,8 +29,8 @@ class Kernel extends HttpKernel
         \App\Http\Middleware\TrimStrings::class,
         \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
         \App\Http\Middleware\TrustProxies::class,
-        \Fruitcake\Cors\HandleCors::class,
-             \App\Http\Middleware\Cors::class,
+        //\Fruitcake\Cors\HandleCors::class,
+        \App\Http\Middleware\Cors::class,
 
     ];
 

From 4a85081f3a9cf4caae4badb36abc9dc885292c3b Mon Sep 17 00:00:00 2001
From: David Bomba 
Date: Mon, 7 Sep 2020 20:03:47 +1000
Subject: [PATCH 5/5] Composer install

---
 app/Console/Commands/PostUpdate.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/Console/Commands/PostUpdate.php b/app/Console/Commands/PostUpdate.php
index 425c3cee1ac1..def9f4237c37 100644
--- a/app/Console/Commands/PostUpdate.php
+++ b/app/Console/Commands/PostUpdate.php
@@ -59,8 +59,9 @@ class PostUpdate extends Command
         $input = new ArrayInput(array('command' => 'install'));
         $application = new Application();
         $application->setAutoExit(false); 
-        $application->run($input);
+        $out = $application->run($input);
 
+        print_r($out);
         echo "Done.";
 
         // $composer_data = [