From 3141a33ced2805f32b9516ed7b8c6f357ba82f40 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 19:15:31 +1000 Subject: [PATCH 1/9] Appropriately refresh sending tokens --- app/Http/Controllers/Auth/LoginController.php | 5 ++- app/Jobs/Mail/NinjaMailerJob.php | 43 +++++++++++++------ app/Models/User.php | 1 + ...0_fixes_for_description_in_pdf_designs.php | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 8e34d1c072b1..a557e8915654 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -772,6 +772,8 @@ class LoginController extends BaseController $oauth_user_token = $socialite_user->accessTokenResponseBody['access_token']; + $oauth_expiry = now()->addSeconds($socialite_user->accessTokenResponseBody['expires_in']) ?: now()->addSeconds(300); + if($user = OAuth::handleAuth($socialite_user, $provider)) { @@ -785,7 +787,8 @@ class LoginController extends BaseController 'oauth_user_id' => $socialite_user->getId(), 'oauth_provider_id' => $provider, 'oauth_user_token' => $oauth_user_token, - 'oauth_user_refresh_token' => $socialite_user->accessTokenResponseBody['refresh_token'] + 'oauth_user_refresh_token' => $socialite_user->accessTokenResponseBody['refresh_token'], + 'oauth_user_token_expiry' => $oauth_expiry, ]; $user->update($update_user); diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 2a2a7ee22a1a..5e2b55ba19f6 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -342,23 +342,38 @@ class NinjaMailerJob implements ShouldQueue private function refreshOfficeToken($user) { - $guzzle = new \GuzzleHttp\Client(); - $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; - $token = json_decode($guzzle->post($url, [ - 'form_params' => [ - 'client_id' => config('ninja.o365.client_id') , - 'client_secret' => config('ninja.o365.client_secret') , - 'scope' => 'email Mail.ReadWrite Mail.Send offline_access profile User.Read openid', - 'grant_type' => 'refresh_token', - 'refresh_token' => $user->oauth_user_refresh_token - ], - ])->getBody()->getContents()); + if($user->oauth_user_token_expiry->lt(now())) + { + $guzzle = new \GuzzleHttp\Client(); + $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; - if($token) - return $token->access_token; + $token = json_decode($guzzle->post($url, [ + 'form_params' => [ + 'client_id' => config('ninja.o365.client_id') , + 'client_secret' => config('ninja.o365.client_secret') , + 'scope' => 'email Mail.ReadWrite Mail.Send offline_access profile User.Read openid', + 'grant_type' => 'refresh_token', + 'refresh_token' => $user->oauth_user_refresh_token + ], + ])->getBody()->getContents()); - return false; + if($token){ + + nlog($token); + + $user->oauth_user_token = $token->access_token; + $user->oauth_user_token_expiry = now()->addSeconds($token->expires_in); + $user->save(); + + return $token->access_token; + } + + return false; + } + + return $user->oauth_user_refresh_token; + } } \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index 473d0059ca2f..a58c6e4caac1 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -106,6 +106,7 @@ class User extends Authenticatable implements MustVerifyEmail 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', + 'oauth_user_token_expiry' => 'datetime', ]; diff --git a/database/migrations/2022_06_21_104350_fixes_for_description_in_pdf_designs.php b/database/migrations/2022_06_21_104350_fixes_for_description_in_pdf_designs.php index 9c92973221e0..ded6a204c18d 100644 --- a/database/migrations/2022_06_21_104350_fixes_for_description_in_pdf_designs.php +++ b/database/migrations/2022_06_21_104350_fixes_for_description_in_pdf_designs.php @@ -13,7 +13,7 @@ class FixesForDescriptionInPdfDesigns extends Migration */ public function up() { - \Illuminate\Support\Facades\Artisan::call('ninja:design-update'); + \Illuminate\Support\Facades\Artisan::call('ninja:design-update'); } /** From 386c3bff0e3663369fe128c236a64079be097fa9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 19:16:01 +1000 Subject: [PATCH 2/9] Appropriately refresh sending tokens --- ...2_06_22_090547_set_oauth_expiry_column.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 database/migrations/2022_06_22_090547_set_oauth_expiry_column.php diff --git a/database/migrations/2022_06_22_090547_set_oauth_expiry_column.php b/database/migrations/2022_06_22_090547_set_oauth_expiry_column.php new file mode 100644 index 000000000000..9ccd5cde296e --- /dev/null +++ b/database/migrations/2022_06_22_090547_set_oauth_expiry_column.php @@ -0,0 +1,30 @@ +datetime('oauth_user_token_expiry')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} From 551342273969027a863e1564e254e69f26cfe401 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 19:18:00 +1000 Subject: [PATCH 3/9] Appropriately refresh sending tokens --- app/Jobs/Mail/NinjaMailerJob.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 5e2b55ba19f6..9694a82b56fb 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -342,8 +342,9 @@ class NinjaMailerJob implements ShouldQueue private function refreshOfficeToken($user) { + $expiry = $user->oauth_user_token_expiry ?: now()->subDay(); - if($user->oauth_user_token_expiry->lt(now())) + if($expiry->lt(now())) { $guzzle = new \GuzzleHttp\Client(); $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; From 3391ad54e0253357ce1b8e6a85328bf080586be3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 19:21:58 +1000 Subject: [PATCH 4/9] Appropriately refresh sending tokens --- app/Jobs/Mail/NinjaMailerJob.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 9694a82b56fb..fa4784f694a2 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -361,8 +361,7 @@ class NinjaMailerJob implements ShouldQueue if($token){ - nlog($token); - + $user->oauth_user_refresh_token = property_exists($token, 'refresh_token') ? $token->refresh_token : $user->oauth_user_refresh_token; $user->oauth_user_token = $token->access_token; $user->oauth_user_token_expiry = now()->addSeconds($token->expires_in); $user->save(); From 5670abe224a1e2077d4c3475d486d2dabbfefc66 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 19:26:14 +1000 Subject: [PATCH 5/9] Appropriately refresh sending tokens --- app/Jobs/Mail/NinjaMailerJob.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index fa4784f694a2..4f94b0fd9ed9 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -359,6 +359,8 @@ class NinjaMailerJob implements ShouldQueue ], ])->getBody()->getContents()); + nlog($token); + if($token){ $user->oauth_user_refresh_token = property_exists($token, 'refresh_token') ? $token->refresh_token : $user->oauth_user_refresh_token; From 93ebf3a767d533236e068d843d33300f3bd3d648 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Jun 2022 20:55:14 +1000 Subject: [PATCH 6/9] Response handling with microsoft --- app/Http/Controllers/Auth/LoginController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index a557e8915654..113675dae44e 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -332,11 +332,6 @@ class LoginController extends BaseController if (request()->input('provider') == 'google') { return $this->handleGoogleOauth(); } elseif (request()->input('provider') == 'microsoft') { - // if (request()->has('token')) { - // return $this->handleSocialiteLogin('microsoft', request()->get('token')); - // } else { - // $message = 'Bearer token missing for the microsoft login'; - // } return $this->handleMicrosoftOauth(); } elseif (request()->input('provider') == 'apple') { // if (request()->has('token')) { @@ -501,7 +496,7 @@ class LoginController extends BaseController elseif(request()->has('access_token')) $accessToken = request()->input('access_token'); else - return response()->json(['message' => 'Invalid response from oauth server'], 400); + return response()->json(['message' => 'Invalid response from oauth server, no access token in response.'], 400); $graph = new \Microsoft\Graph\Graph(); $graph->setAccessToken($accessToken); @@ -512,7 +507,6 @@ class LoginController extends BaseController if($user){ - $account = request()->input('account'); $email = $user->getMail() ?: $user->getUserPrincipalName(); $query = [ @@ -553,6 +547,8 @@ class LoginController extends BaseController } + return response()->json(['message' => 'Unable to authenticate this user'], 400); + } private function existingOauthUser($existing_user) From 922747d681b6ea6b48b1db8668c2383e0a0fb7ef Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Jun 2022 09:39:32 +1000 Subject: [PATCH 7/9] Updates for composer lock --- composer.lock | 157 +++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/composer.lock b/composer.lock index 36f2634ab10b..b0444b4bcc65 100644 --- a/composer.lock +++ b/composer.lock @@ -434,16 +434,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.225.5", + "version": "3.228.1", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "09b404c6b80b9c31be15fa245e647a2f9fb5e733" + "reference": "53b7f43945b19bb0700c75d4c5f130055096e817" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/09b404c6b80b9c31be15fa245e647a2f9fb5e733", - "reference": "09b404c6b80b9c31be15fa245e647a2f9fb5e733", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/53b7f43945b19bb0700c75d4c5f130055096e817", + "reference": "53b7f43945b19bb0700c75d4c5f130055096e817", "shasum": "" }, "require": { @@ -451,9 +451,9 @@ "ext-json": "*", "ext-pcre": "*", "ext-simplexml": "*", - "guzzlehttp/guzzle": "^5.3.3 || ^6.2.1 || ^7.0", + "guzzlehttp/guzzle": "^6.5.7 || ^7.4.4", "guzzlehttp/promises": "^1.4.0", - "guzzlehttp/psr7": "^1.7.0 || ^2.1.1", + "guzzlehttp/psr7": "^1.8.5 || ^2.3", "mtdowling/jmespath.php": "^2.6", "php": ">=5.5" }, @@ -519,9 +519,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.225.5" + "source": "https://github.com/aws/aws-sdk-php/tree/3.228.1" }, - "time": "2022-06-15T19:35:13+00:00" + "time": "2022-06-22T18:16:48+00:00" }, { "name": "bacon/bacon-qr-code", @@ -1303,16 +1303,16 @@ }, { "name": "doctrine/dbal", - "version": "3.3.6", + "version": "3.3.7", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "9e7f76dd1cde81c62574fdffa5a9c655c847ad21" + "reference": "9f79d4650430b582f4598fe0954ef4d52fbc0a8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/9e7f76dd1cde81c62574fdffa5a9c655c847ad21", - "reference": "9e7f76dd1cde81c62574fdffa5a9c655c847ad21", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/9f79d4650430b582f4598fe0954ef4d52fbc0a8a", + "reference": "9f79d4650430b582f4598fe0954ef4d52fbc0a8a", "shasum": "" }, "require": { @@ -1327,11 +1327,11 @@ "require-dev": { "doctrine/coding-standard": "9.0.0", "jetbrains/phpstorm-stubs": "2022.1", - "phpstan/phpstan": "1.6.3", + "phpstan/phpstan": "1.7.13", "phpstan/phpstan-strict-rules": "^1.2", "phpunit/phpunit": "9.5.20", "psalm/plugin-phpunit": "0.16.1", - "squizlabs/php_codesniffer": "3.6.2", + "squizlabs/php_codesniffer": "3.7.0", "symfony/cache": "^5.2|^6.0", "symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0", "vimeo/psalm": "4.23.0" @@ -1394,7 +1394,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.3.6" + "source": "https://github.com/doctrine/dbal/tree/3.3.7" }, "funding": [ { @@ -1410,7 +1410,7 @@ "type": "tidelift" } ], - "time": "2022-05-02T17:21:01+00:00" + "time": "2022-06-13T21:43:03+00:00" }, { "name": "doctrine/deprecations", @@ -2294,16 +2294,16 @@ }, { "name": "google/apiclient-services", - "version": "v0.253.0", + "version": "v0.254.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client-services.git", - "reference": "70c62b17f7821526cb52c6f125254dc51f256109" + "reference": "e1b16659df899f3bdf5c798358c256a9cc01efeb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/70c62b17f7821526cb52c6f125254dc51f256109", - "reference": "70c62b17f7821526cb52c6f125254dc51f256109", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/e1b16659df899f3bdf5c798358c256a9cc01efeb", + "reference": "e1b16659df899f3bdf5c798358c256a9cc01efeb", "shasum": "" }, "require": { @@ -2332,9 +2332,9 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client-services/issues", - "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.253.0" + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.254.0" }, - "time": "2022-06-13T01:06:12+00:00" + "time": "2022-06-19T01:16:11+00:00" }, { "name": "google/auth", @@ -2516,22 +2516,22 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.4.4", + "version": "7.4.5", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8" + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8", - "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.5", - "guzzlehttp/psr7": "^1.8.3 || ^2.1", + "guzzlehttp/psr7": "^1.9 || ^2.4", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" @@ -2620,7 +2620,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.4" + "source": "https://github.com/guzzle/guzzle/tree/7.4.5" }, "funding": [ { @@ -2636,7 +2636,7 @@ "type": "tidelift" } ], - "time": "2022-06-09T21:39:15+00:00" + "time": "2022-06-20T22:16:13+00:00" }, { "name": "guzzlehttp/promises", @@ -2724,16 +2724,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.3.0", + "version": "2.4.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee" + "reference": "13388f00956b1503577598873fffb5ae994b5737" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/83260bb50b8fc753c72d14dc1621a2dac31877ee", - "reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737", + "reference": "13388f00956b1503577598873fffb5ae994b5737", "shasum": "" }, "require": { @@ -2757,7 +2757,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.4-dev" } }, "autoload": { @@ -2819,7 +2819,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.3.0" + "source": "https://github.com/guzzle/psr7/tree/2.4.0" }, "funding": [ { @@ -2835,7 +2835,7 @@ "type": "tidelift" } ], - "time": "2022-06-09T08:26:02+00:00" + "time": "2022-06-20T21:43:11+00:00" }, { "name": "halaxa/json-machine", @@ -3332,17 +3332,17 @@ "source": { "type": "git", "url": "https://github.com/invoiceninja/inspector.git", - "reference": "3f5beb9854c0d1d6f65bc0d9ba847503e6e84583" + "reference": "307b0e4b90dd0ebf062f90ece4d46399202aa73e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/invoiceninja/inspector/zipball/3f5beb9854c0d1d6f65bc0d9ba847503e6e84583", - "reference": "3f5beb9854c0d1d6f65bc0d9ba847503e6e84583", + "url": "https://api.github.com/repos/invoiceninja/inspector/zipball/307b0e4b90dd0ebf062f90ece4d46399202aa73e", + "reference": "307b0e4b90dd0ebf062f90ece4d46399202aa73e", "shasum": "" }, "require": { "doctrine/dbal": "^3.1", - "illuminate/support": "^8.0", + "illuminate/support": "^8.0|^9.0", "php": "^7.4|^8.0" }, "require-dev": { @@ -3385,9 +3385,9 @@ ], "support": { "issues": "https://github.com/invoiceninja/inspector/issues", - "source": "https://github.com/invoiceninja/inspector/tree/main" + "source": "https://github.com/invoiceninja/inspector/tree/v1.0" }, - "time": "2021-09-11T11:35:02+00:00" + "time": "2022-06-22T11:16:55+00:00" }, { "name": "jean85/pretty-package-versions", @@ -3500,16 +3500,16 @@ }, { "name": "laravel/framework", - "version": "v8.83.16", + "version": "v8.83.17", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "6be5abd144faf517879af7298e9d79f06f250f75" + "reference": "2cf142cd5100b02da248acad3988bdaba5635e16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/6be5abd144faf517879af7298e9d79f06f250f75", - "reference": "6be5abd144faf517879af7298e9d79f06f250f75", + "url": "https://api.github.com/repos/laravel/framework/zipball/2cf142cd5100b02da248acad3988bdaba5635e16", + "reference": "2cf142cd5100b02da248acad3988bdaba5635e16", "shasum": "" }, "require": { @@ -3669,7 +3669,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-06-07T15:09:06+00:00" + "time": "2022-06-21T14:38:31+00:00" }, { "name": "laravel/serializable-closure", @@ -4930,16 +4930,16 @@ }, { "name": "microsoft/microsoft-graph", - "version": "1.69.0", + "version": "1.70.0", "source": { "type": "git", "url": "https://github.com/microsoftgraph/msgraph-sdk-php.git", - "reference": "dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4" + "reference": "7d85293be037c4a2891a03cb953eb204bf68387e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/microsoftgraph/msgraph-sdk-php/zipball/dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4", - "reference": "dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4", + "url": "https://api.github.com/repos/microsoftgraph/msgraph-sdk-php/zipball/7d85293be037c4a2891a03cb953eb204bf68387e", + "reference": "7d85293be037c4a2891a03cb953eb204bf68387e", "shasum": "" }, "require": { @@ -4975,9 +4975,9 @@ "homepage": "https://developer.microsoft.com/en-us/graph", "support": { "issues": "https://github.com/microsoftgraph/msgraph-sdk-php/issues", - "source": "https://github.com/microsoftgraph/msgraph-sdk-php/tree/1.69.0" + "source": "https://github.com/microsoftgraph/msgraph-sdk-php/tree/1.70.0" }, - "time": "2022-06-15T11:11:33+00:00" + "time": "2022-06-21T13:37:02+00:00" }, { "name": "mollie/mollie-api-php", @@ -5324,16 +5324,16 @@ }, { "name": "nelexa/zip", - "version": "4.0.1", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/Ne-Lexa/php-zip.git", - "reference": "a18f80db509b1b6e9798e2745dc100759107f50c" + "reference": "88a1b6549be813278ff2dd3b6b2ac188827634a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ne-Lexa/php-zip/zipball/a18f80db509b1b6e9798e2745dc100759107f50c", - "reference": "a18f80db509b1b6e9798e2745dc100759107f50c", + "url": "https://api.github.com/repos/Ne-Lexa/php-zip/zipball/88a1b6549be813278ff2dd3b6b2ac188827634a7", + "reference": "88a1b6549be813278ff2dd3b6b2ac188827634a7", "shasum": "" }, "require": { @@ -5391,9 +5391,9 @@ ], "support": { "issues": "https://github.com/Ne-Lexa/php-zip/issues", - "source": "https://github.com/Ne-Lexa/php-zip/tree/4.0.1" + "source": "https://github.com/Ne-Lexa/php-zip/tree/4.0.2" }, - "time": "2021-12-12T09:50:45+00:00" + "time": "2022-06-17T11:17:46+00:00" }, { "name": "nesbot/carbon", @@ -5778,16 +5778,16 @@ }, { "name": "nyholm/psr7", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/Nyholm/psr7.git", - "reference": "1461e07a0f2a975a52082ca3b769ca912b816226" + "reference": "f734364e38a876a23be4d906a2a089e1315be18a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Nyholm/psr7/zipball/1461e07a0f2a975a52082ca3b769ca912b816226", - "reference": "1461e07a0f2a975a52082ca3b769ca912b816226", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a", + "reference": "f734364e38a876a23be4d906a2a089e1315be18a", "shasum": "" }, "require": { @@ -5839,7 +5839,7 @@ ], "support": { "issues": "https://github.com/Nyholm/psr7/issues", - "source": "https://github.com/Nyholm/psr7/tree/1.5.0" + "source": "https://github.com/Nyholm/psr7/tree/1.5.1" }, "funding": [ { @@ -5851,7 +5851,7 @@ "type": "github" } ], - "time": "2022-02-02T18:37:57+00:00" + "time": "2022-06-22T07:13:36+00:00" }, { "name": "omnipay/common", @@ -11440,21 +11440,21 @@ }, { "name": "turbo124/beacon", - "version": "1.1.1", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/turbo124/beacon.git", - "reference": "e2e1e83b54699051783a8f1dbd36a33c45130ee2" + "reference": "3e3bd337f91666ae793b6682ef40fd228aa6f185" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/turbo124/beacon/zipball/e2e1e83b54699051783a8f1dbd36a33c45130ee2", - "reference": "e2e1e83b54699051783a8f1dbd36a33c45130ee2", + "url": "https://api.github.com/repos/turbo124/beacon/zipball/3e3bd337f91666ae793b6682ef40fd228aa6f185", + "reference": "3e3bd337f91666ae793b6682ef40fd228aa6f185", "shasum": "" }, "require": { "guzzlehttp/guzzle": "^7", - "illuminate/support": "^6.0|^7.0|^8.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0", "php": "^7.3|^7.4|^8" }, "require-dev": { @@ -11497,9 +11497,9 @@ "turbo124" ], "support": { - "source": "https://github.com/turbo124/beacon/tree/1.1.1" + "source": "https://github.com/turbo124/beacon/tree/v1.2.0" }, - "time": "2022-04-16T14:05:40+00:00" + "time": "2022-06-22T11:22:46+00:00" }, { "name": "turbo124/laravel-gmail", @@ -14244,16 +14244,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.20", + "version": "9.5.21", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba" + "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba", - "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0e32b76be457de00e83213528f6bb37e2a38fcb1", + "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1", "shasum": "" }, "require": { @@ -14287,7 +14287,6 @@ "sebastian/version": "^3.0.2" }, "require-dev": { - "ext-pdo": "*", "phpspec/prophecy-phpunit": "^2.0.1" }, "suggest": { @@ -14331,7 +14330,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.21" }, "funding": [ { @@ -14343,7 +14342,7 @@ "type": "github" } ], - "time": "2022-04-01T12:37:26+00:00" + "time": "2022-06-19T12:14:25+00:00" }, { "name": "sebastian/cli-parser", From e7ab088e90eddf37114abfc27de448be05fb552d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Jun 2022 10:52:41 +1000 Subject: [PATCH 8/9] admin notifications --- .../ClientPortal/NinjaPlanController.php | 4 + .../Ninja/NewAccountNotification.php | 93 +++++++++++++++ app/Notifications/Ninja/SpamNotification.php | 111 ++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 app/Notifications/Ninja/NewAccountNotification.php create mode 100644 app/Notifications/Ninja/SpamNotification.php diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index b76e09ede7ec..144834898480 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -25,6 +25,7 @@ use App\Models\GatewayType; use App\Models\Invoice; use App\Models\RecurringInvoice; use App\Models\Subscription; +use App\Notifications\Ninja\NewAccountNotification; use App\Repositories\SubscriptionRepository; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; @@ -165,6 +166,9 @@ class NinjaPlanController extends Controller ->increment() ->queue(); + $ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id')); + $ninja_company->notification(new NewAccountNotification($account, $client))->ninja(); + return $this->render('plan.trial_confirmed', $data); } diff --git a/app/Notifications/Ninja/NewAccountNotification.php b/app/Notifications/Ninja/NewAccountNotification.php new file mode 100644 index 000000000000..52648d36066f --- /dev/null +++ b/app/Notifications/Ninja/NewAccountNotification.php @@ -0,0 +1,93 @@ +account = $account; + $this->client = $client; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['slack']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } + + public function toSlack($notifiable) + { + $content = "New Trial Started\n"; + $content = "{$this->client->name}\n"; + $content = "Account key: {$this->account->key}\n"; + $content = "Users: {$this->account->users()->pluck('email')}\n"; + $content = "Contacts: {$this->client->contacts()->pluck('email')}\n"; + + + return (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content($content); + } +} diff --git a/app/Notifications/Ninja/SpamNotification.php b/app/Notifications/Ninja/SpamNotification.php new file mode 100644 index 000000000000..6c94a33849ac --- /dev/null +++ b/app/Notifications/Ninja/SpamNotification.php @@ -0,0 +1,111 @@ +spam_list = $spam_list; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['slack']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } + + public function toSlack($notifiable) + { + $content = ''; + + foreach($this->spam_list as $spam_list) + { + + if(array_key_exists('companies', $spam_list)) + { + $content .= " Companies \n"; + + foreach($spam_list['companies'] as $company) + { + $content .= "{$company['name']} - c_key={$company['company_key']} - a_key={$company['account_key']} - {$company['owner']} \n"; + } + } + + + if(array_key_exists('users', $spam_list)) + { + + $content .= ' Users \n'; + + foreach($spam_list['users'] as $user) + { + $content .= "{$user['email']} - a_key={$user['account_key']} - created={$user['created']} \n"; + } + + } + + } + + return (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content($content); + } +} From f84e760c1fe83ae0ff5b89275e953379dd645bd8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Jun 2022 12:30:38 +1000 Subject: [PATCH 9/9] Spam notifications --- app/Notifications/Ninja/SpamNotification.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Notifications/Ninja/SpamNotification.php b/app/Notifications/Ninja/SpamNotification.php index 6c94a33849ac..061c720e3865 100644 --- a/app/Notifications/Ninja/SpamNotification.php +++ b/app/Notifications/Ninja/SpamNotification.php @@ -87,6 +87,16 @@ class SpamNotification extends Notification } } + if(array_key_exists('templates', $spam_list)) + { + $content .= " Templates \n"; + + foreach($spam_list['templates'] as $company) + { + $content .= "{$company['name']} - c_key={$company['company_key']} - a_key={$company['account_key']} - {$company['owner']} \n"; + } + } + if(array_key_exists('users', $spam_list)) {