Added license endpoint for users

This commit is contained in:
snipe 2019-12-19 18:00:36 -08:00
parent db59106c3e
commit 779fc6d195
2 changed files with 25 additions and 0 deletions

View file

@ -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] [<snipe@snipe.net>]
* @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
*

View file

@ -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',