diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f5d146506f1f..60dbcf4d735f 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -69,37 +69,6 @@ class UserController extends BaseController * @param UserFilters $filters * @return Response * - * - * @OA\Get( - * path="/api/v1/users", - * operationId="getUsers", - * tags={"users"}, - * summary="Gets a list of users", - * description="Lists users, search and filters allow fine grained lists to be generated. - * - *Query parameters can be added to performed more fine grained filtering of the users, these are handled by the UserFilters class which defines the methods available", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Response( - * response=200, - * description="A list of users", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function index(UserFilters $filters) { @@ -114,37 +83,6 @@ class UserController extends BaseController * @param CreateUserRequest $request * @return Response * - * - * - * @OA\Get( - * path="/api/v1/users/create", - * operationId="getUsersCreate", - * tags={"users"}, - * summary="Gets a new blank User object", - * description="Returns a blank object with default values", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Response( - * response=200, - * description="A blank User object", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function create(CreateUserRequest $request) { @@ -159,41 +97,13 @@ class UserController extends BaseController * @param StoreUserRequest $request * @return Response * - * - * - * @OA\Post( - * path="/api/v1/users", - * operationId="storeUser", - * tags={"users"}, - * summary="Adds a User", - * description="Adds an User to the system", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Response( - * response=200, - * description="Returns the saved User object", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function store(StoreUserRequest $request) { - $company = auth()->user()->company(); + /** @var \App\Models\User $logged_in_user */ + $logged_in_user = auth()->user(); + + $company = $logged_in_user->company(); $user = $this->user_repo->save($request->all(), $request->fetchUser()); @@ -216,47 +126,6 @@ class UserController extends BaseController * @param User $user * @return Response * - * - * @OA\Get( - * path="/api/v1/users/{id}", - * operationId="showUser", - * tags={"users"}, - * summary="Shows an User", - * description="Displays an User by id", - * @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="id", - * in="path", - * description="The User Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the User object", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function show(ShowUserRequest $request, User $user) { @@ -270,47 +139,6 @@ class UserController extends BaseController * @param User $user * @return Response * - * - * @OA\Get( - * path="/api/v1/users/{id}/edit", - * operationId="editUser", - * tags={"users"}, - * summary="Shows an User for editting", - * description="Displays an User by id", - * @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="id", - * in="path", - * description="The User Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the User object", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function edit(EditUserRequest $request, User $user) { @@ -320,53 +148,16 @@ class UserController extends BaseController /** * Update the specified resource in storage. * - * @OA\Put( - * path="/api/v1/users/{id}", - * operationId="updateUser", - * tags={"users"}, - * summary="Updates an User", - * description="Handles the updating of an User by id", - * @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="id", - * in="path", - * description="The User Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the User object", - * @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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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 UpdateUserRequest $request * @param User $user * @return Response|mixed */ public function update(UpdateUserRequest $request, User $user) { - $old_company_user = $user->company_users()->where('company_id', auth()->user()->company()->id)->first(); + /** @var \App\Models\User $logged_in_user */ + $logged_in_user = auth()->user(); + + $old_company_user = $user->company_users()->where('company_id', $logged_in_user->company()->id)->first(); $old_user = json_encode($user); $old_user_email = $user->getOriginal('email'); @@ -384,10 +175,10 @@ class UserController extends BaseController $user->oauth_user_refresh_token = null; $user->oauth_user_token = null; $user->save(); - UserEmailChanged::dispatch($new_user, json_decode($old_user), auth()->user()->company()); + UserEmailChanged::dispatch($new_user, json_decode($old_user), $logged_in_user->company()); } - event(new UserWasUpdated($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event(new UserWasUpdated($user, $logged_in_user, $logged_in_user->company(), Ninja::eventVars($logged_in_user->id))); return $this->itemResponse($user); } @@ -397,59 +188,8 @@ class UserController extends BaseController * * @param DestroyUserRequest $request * @param User $user - * @return Response + * @return JsonResponse | Response * - * - * @OA\Delete( - * path="/api/v1/users/{id}", - * operationId="deleteUser", - * tags={"users"}, - * summary="Deletes a User", - * description="Handles the deletion of an User by id", - * @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="token_name", - * in="query", - * required=false, - * description="Customized name for the Users API Token", - * example="iOS Device 11 iPad", - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Parameter( - * name="id", - * in="path", - * description="The User Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns a HTTP status", - * @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"), - * ), - * ) */ public function destroy(DestroyUserRequest $request, User $user) { @@ -460,7 +200,10 @@ class UserController extends BaseController /* If the user passes the company user we archive the company user */ $user = $this->user_repo->delete($request->all(), $user); - event(new UserWasDeleted($user, auth()->user(), auth()->user()->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + /** @var \App\Models\User $logged_in_user */ + $logged_in_user = auth()->user(); + + event(new UserWasDeleted($user, $logged_in_user, $logged_in_user->company(), Ninja::eventVars($logged_in_user->id))); return $this->itemResponse($user->fresh()); } @@ -468,54 +211,8 @@ class UserController extends BaseController /** * Perform bulk actions on the list view. * - * @return Collection + * @return Response * - * - * - * @OA\Post( - * path="/api/v1/users/bulk", - * operationId="bulkUsers", - * tags={"users"}, - * summary="Performs bulk actions on an array of users", - * description="", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/index"), - * @OA\RequestBody( - * description="Hashed ids", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="array", - * @OA\Items( - * type="integer", - * description="Array of hashed IDs to be bulk 'actioned", - * example="[0,1,2,3]", - * ), - * ) - * ) - * ), - * @OA\Response( - * response=200, - * description="The User 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\JsonContent(ref="#/components/schemas/User"), - * ), - * @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"), - * ), - * ) */ public function bulk(BulkUserRequest $request) { @@ -548,45 +245,6 @@ class UserController extends BaseController /** * Detach an existing user to a company. * - * @OA\Delete( - * path="/api/v1/users/{user}/detach_from_company", - * operationId="detachUser", - * tags={"users"}, - * summary="Detach an existing user to a company", - * description="Detach an existing user from a company", - * @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 DetachCompanyUserRequest $request * @param User $user * @return \Illuminate\Http\JsonResponse @@ -622,52 +280,16 @@ class UserController extends BaseController /** * Invite an existing user to a company. * - * @OA\Post( - * path="/api/v1/users/{user}/invite", - * operationId="inviteUser", - * 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-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 invite(ReconfirmUserRequest $request, User $user) { - $user->service()->invite($user->company()); + /** @var \App\Models\User $logged_in_user */ + $logged_in_user = auth()->user(); + + $user->service()->invite($logged_in_user->company()); return response()->json(['message' => ctrans('texts.confirmation_resent')], 200); } @@ -676,52 +298,16 @@ 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-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()); + /** @var \App\Models\User $logged_in_user */ + $logged_in_user = auth()->user(); + + $user->service()->invite($logged_in_user->company()); return response()->json(['message' => ctrans('texts.confirmation_resent')], 200); } diff --git a/tests/Feature/UpdatePaymentTest.php b/tests/Feature/UpdatePaymentTest.php index c3d169205a35..7c89e86afcb6 100644 --- a/tests/Feature/UpdatePaymentTest.php +++ b/tests/Feature/UpdatePaymentTest.php @@ -14,8 +14,6 @@ namespace Tests\Feature; use Carbon\Carbon; use Tests\TestCase; use App\Models\Client; -use App\Models\Invoice; -use App\Models\Payment; use Tests\MockAccountData; use App\Factory\InvoiceFactory; use App\Utils\Traits\MakesHash;