From ed8c880750d698c6da68c4491900b93cb4126955 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Mar 2021 20:15:24 +1100 Subject: [PATCH] add reconfirm route --- app/Http/Controllers/UserController.php | 59 ++++++++++++++++++- .../Requests/User/ReconfirmUserRequest.php | 2 +- app/Jobs/User/CreateUser.php | 4 +- app/Listeners/Payment/PaymentNotification.php | 13 +--- routes/api.php | 1 + 5 files changed, 64 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7291e6b8bd8d..202354eb4c54 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -209,6 +209,8 @@ class UserController extends BaseController $ct = CreateCompanyToken::dispatchNow($company, $user, $user_agent); + nlog("in the store method of the usercontroller class"); + event(new UserWasCreated($user, auth()->user(), $company, Ninja::eventVars())); return $this->itemResponse($user->fresh()); @@ -626,7 +628,7 @@ class UserController extends BaseController } /** - * Detach an existing user to a company. + * Invite an existing user to a company. * * @OA\Post( * path="/api/v1/users/{user}/invite", @@ -682,4 +684,59 @@ class UserController extends BaseController } + /** + * Invite an existing user to a company. + * + * @OA\Post( + * path="/api/v1/users/{user}/reconfirm", + * operationId="inviteUserReconfirm", + * tags={"users"}, + * summary="Reconfirm an existing user to a company", + * description="Reconfirm an existing user from a company", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="user", + * in="path", + * description="The user hashed_id", + * example="FD767dfd7", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Success response", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * @param ReconfirmUserRequest $request + * @param User $user + * @return \Illuminate\Http\JsonResponse + */ + public function reconfirm(ReconfirmUserRequest $request, User $user) + { + + $user->service()->invite($user->company()); + + return response()->json(['message' => ctrans('texts.confirmation_resent')], 200); + + } } diff --git a/app/Http/Requests/User/ReconfirmUserRequest.php b/app/Http/Requests/User/ReconfirmUserRequest.php index d7a966e5542a..2e16a5fff61d 100644 --- a/app/Http/Requests/User/ReconfirmUserRequest.php +++ b/app/Http/Requests/User/ReconfirmUserRequest.php @@ -23,6 +23,6 @@ class ReconfirmUserRequest extends Request */ public function authorize() : bool { - return auth()->user()->isAdmin(); + return auth()->user()->id == $this->user->id; } } diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index e08b403e1b95..da3209994584 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -82,8 +82,10 @@ class CreateUser 'settings' => null, ]); - if(!Ninja::isSelfHost()) + if(!Ninja::isSelfHost()){ + nlog("in the create user class"); event(new UserWasCreated($user, $user, $this->company, Ninja::eventVars())); + } return $user; } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 8503e6eee5f7..1876074ba1ca 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -59,7 +59,7 @@ class PaymentNotification implements ShouldQueue foreach ($payment->company->company_users as $company_user) { $user = $company_user->user; - $methods = $this->findUserEntityNotificationType($payment, $company_user, ['all_notifications']); + $methods = $this->findUserEntityNotificationType($payment, $company_user, ['payment_success_all', 'all_notifications']); if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); @@ -69,19 +69,8 @@ class PaymentNotification implements ShouldQueue NinjaMailerJob::dispatch($nmo); } - // $notification = new NewPaymentNotification($payment, $payment->company); - // $notification->method = $methods; - - // if ($user) { - // $user->notify($notification); - // } } - /*Company Notifications*/ - // if (isset($payment->company->slack_webhook_url)) { - // Notification::route('slack', $payment->company->slack_webhook_url) - // ->notify(new NewPaymentNotification($payment, $payment->company, true)); - // } /*Google Analytics Track Revenue*/ if (isset($payment->company->google_analytics_key)) { diff --git a/routes/api.php b/routes/api.php index 6c3877a345b8..e3359822d06d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -165,6 +165,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected'); Route::post('/users/{user}/invite', 'UserController@invite')->middleware('password_protected'); + Route::post('/users/{user}/reconfirm', 'UserController@reconfirm'); Route::resource('webhooks', 'WebhookController'); Route::post('webhooks/bulk', 'WebhookController@bulk')->name('webhooks.bulk');