mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
0c86855392
|
@ -5,8 +5,10 @@ namespace App\Http\Controllers\Api;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Transformers\AssetsTransformer;
|
||||||
use App\Http\Transformers\LocationsTransformer;
|
use App\Http\Transformers\LocationsTransformer;
|
||||||
use App\Http\Transformers\SelectlistTransformer;
|
use App\Http\Transformers\SelectlistTransformer;
|
||||||
|
use App\Models\Asset;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
@ -222,6 +224,15 @@ class LocationsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assets(Request $request, Location $location) : JsonResponse | array
|
||||||
|
{
|
||||||
|
$this->authorize('view', Asset::class);
|
||||||
|
$this->authorize('view', $location);
|
||||||
|
$assets = Asset::where('assigned_to', '=', $location->id)->where('assigned_type', '=', Location::class)->with('model', 'model.category', 'assetstatus', 'location', 'company', 'defaultLoc');
|
||||||
|
$assets = $assets->get();
|
||||||
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
|
|
|
@ -712,7 +712,7 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
||||||
Route::get('{location}/assets',
|
Route::get('{location}/assets',
|
||||||
[
|
[
|
||||||
Api\LocationsController::class,
|
Api\LocationsController::class,
|
||||||
'getDataViewAssets'
|
'assets'
|
||||||
]
|
]
|
||||||
)->name('api.locations.viewassets');
|
)->name('api.locations.viewassets');
|
||||||
|
|
||||||
|
|
44
tests/Feature/Locations/Api/LocationsViewTest.php
Normal file
44
tests/Feature/Locations/Api/LocationsViewTest.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Consumables\Api;
|
||||||
|
|
||||||
|
use App\Models\Location;
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class LocationsViewTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testViewingLocationRequiresPermission()
|
||||||
|
{
|
||||||
|
$location = Location::factory()->create();
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->getJson(route('api.locations.show', $location->id))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testViewingLocationAssetIndexRequiresPermission()
|
||||||
|
{
|
||||||
|
$location = Location::factory()->create();
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->getJson(route('api.locations.viewassets', $location->id))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testViewingLocationAssetIndex()
|
||||||
|
{
|
||||||
|
$location = Location::factory()->create();
|
||||||
|
Asset::factory()->count(3)->assignedToLocation($location)->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->getJson(route('api.locations.viewassets', $location->id))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonStructure([
|
||||||
|
'total',
|
||||||
|
'rows',
|
||||||
|
])
|
||||||
|
->assertJson([
|
||||||
|
'total' => 3,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue