From 779fc6d1951c5abe4967a4a273253799ccf516cc Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 19 Dec 2019 18:00:36 -0800 Subject: [PATCH] Added license endpoint for users --- app/Http/Controllers/Api/UsersController.php | 18 ++++++++++++++++++ routes/api.php | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index cd5bc0997c..1e693c0916 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -13,6 +13,7 @@ use App\Models\Asset; use App\Http\Transformers\AssetsTransformer; use App\Http\Transformers\SelectlistTransformer; use App\Http\Transformers\AccessoriesTransformer; +use App\Http\Transformers\LicensesTransformer; class UsersController extends Controller { @@ -355,6 +356,23 @@ class UsersController extends Controller return (new AccessoriesTransformer)->transformAccessories($accessories, $accessories->count()); } + /** + * Return JSON containing a list of licenses assigned to a user. + * + * @author [N. Mathar] [] + * @since [v5.0] + * @param $userId + * @return string JSON + */ + public function licenses($id) + { + $this->authorize('view', User::class); + $this->authorize('view', License::class); + $user = User::where('id', $id)->withTrashed()->first(); + $licenses = $user->licenses()->get(); + return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); + } + /** * Reset the user's two-factor status * diff --git a/routes/api.php b/routes/api.php index 1cd028444c..509b957f1b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -741,6 +741,13 @@ Route::group(['prefix' => 'v1','namespace' => 'Api', 'middleware' => 'api'], fun ] ); + Route::get('{user}/licenses', + [ + 'as' => 'api.users.licenselist', + 'uses' => 'UsersController@licenses' + ] + ); + Route::post('{user}/upload', [ 'as' => 'api.users.uploads',