From b68fcf1de5958b4739eb34856626709ad09f6f11 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 12 Jul 2024 12:19:40 +0100 Subject: [PATCH 1/5] Added unaccepted asset test Signed-off-by: snipe --- .../Reporting/UnacceptedAssetReportTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/Feature/Reporting/UnacceptedAssetReportTest.php diff --git a/tests/Feature/Reporting/UnacceptedAssetReportTest.php b/tests/Feature/Reporting/UnacceptedAssetReportTest.php new file mode 100644 index 0000000000..b3ec0b2e0b --- /dev/null +++ b/tests/Feature/Reporting/UnacceptedAssetReportTest.php @@ -0,0 +1,61 @@ +streamedContent())->getRecords()) + ->pluck(0) + ->contains($needle) + ); + + return $this; + } + ); + + TestResponse::macro( + 'assertDontSeeTextInStreamedResponse', + function (string $needle) { + Assert::assertFalse( + collect(Reader::createFromString($this->streamedContent())->getRecords()) + ->pluck(0) + ->contains($needle) + ); + + return $this; + } + ); + } + + + public function testPermissionRequiredToViewUnacceptedAssetReport() + { + $this->actingAs(User::factory()->create()) + ->get(route('reports/unaccepted_assets')) + ->assertForbidden(); + } + + public function testUserCanListUnacceptedAssets() + { + $this->actingAs(User::factory()->superuser()->create()) + ->get(route('reports/unaccepted_assets')) + ->assertOk(); + } + +} From 431da6c903aa9062a7f6e102dec1c04a27d7df3f Mon Sep 17 00:00:00 2001 From: Daniel Albertsen Date: Fri, 12 Jul 2024 21:58:04 +0200 Subject: [PATCH 2/5] add test to ensure artisan optimize works --- tests/Feature/Console/OptimizeTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/Feature/Console/OptimizeTest.php diff --git a/tests/Feature/Console/OptimizeTest.php b/tests/Feature/Console/OptimizeTest.php new file mode 100644 index 0000000000..93db05627a --- /dev/null +++ b/tests/Feature/Console/OptimizeTest.php @@ -0,0 +1,14 @@ +artisan('optimize')->assertSuccessful(); + } +} From a175b6a38bb2cbe727ce57566c27924369a7527b Mon Sep 17 00:00:00 2001 From: Daniel Albertsen Date: Fri, 12 Jul 2024 21:58:17 +0200 Subject: [PATCH 3/5] fix routes and tests --- routes/api.php | 8 ++++---- tests/Feature/Assets/Api/AssetFilesTest.php | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/routes/api.php b/routes/api.php index 1f43af7431..5f122b2a18 100644 --- a/routes/api.php +++ b/routes/api.php @@ -549,28 +549,28 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi Api\AssetFilesController::class, 'store' ] - )->name('api.assets.files'); + )->name('api.assets.files.store'); Route::get('{asset_id}/files', [ Api\AssetFilesController::class, 'list' ] - )->name('api.assets.files'); + )->name('api.assets.files.index'); Route::get('{asset_id}/file/{file_id}', [ Api\AssetFilesController::class, 'show' ] - )->name('api.assets.file'); + )->name('api.assets.files.show'); Route::delete('{asset_id}/file/{file_id}', [ Api\AssetFilesController::class, 'destroy' ] - )->name('api.assets.file'); + )->name('api.assets.files.destroy'); }); diff --git a/tests/Feature/Assets/Api/AssetFilesTest.php b/tests/Feature/Assets/Api/AssetFilesTest.php index 199c67e118..bc5b6043e4 100644 --- a/tests/Feature/Assets/Api/AssetFilesTest.php +++ b/tests/Feature/Assets/Api/AssetFilesTest.php @@ -22,7 +22,7 @@ class AssetFilesTest extends TestCase //Upload a file $this->actingAsForApi($user) ->post( - route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [ + route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] ]) ->assertOk(); @@ -41,7 +41,7 @@ class AssetFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.assets.files', ['asset_id' => $asset[0]["id"]])) + route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) ->assertOk() ->assertJsonStructure([ 'status', @@ -63,7 +63,7 @@ class AssetFilesTest extends TestCase //Upload a file $this->actingAsForApi($user) ->post( - route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [ + route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] ]) ->assertOk(); @@ -71,13 +71,13 @@ class AssetFilesTest extends TestCase // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.assets.files', ['asset_id' => $asset[0]["id"]])) + route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) ->assertOk(); // Get the file $this->actingAsForApi($user) ->get( - route('api.assets.file', [ + route('api.assets.files.show', [ 'asset_id' => $asset[0]["id"], 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], ])) @@ -97,7 +97,7 @@ class AssetFilesTest extends TestCase //Upload a file $this->actingAsForApi($user) ->post( - route('api.assets.files', ['asset_id' => $asset[0]["id"]]), [ + route('api.assets.files.store', ['asset_id' => $asset[0]["id"]]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] ]) ->assertOk(); @@ -105,13 +105,13 @@ class AssetFilesTest extends TestCase // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.assets.files', ['asset_id' => $asset[0]["id"]])) + route('api.assets.files.index', ['asset_id' => $asset[0]["id"]])) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.assets.file', [ + route('api.assets.files.destroy', [ 'asset_id' => $asset[0]["id"], 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], ])) From 99be9ddb4727f5b43e17ab802c0659bab2e4e620 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 13 Jul 2024 16:08:56 +0100 Subject: [PATCH 4/5] Add @dbakan as a contributor --- .all-contributorsrc | 9 +++++++++ CONTRIBUTORS.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 8ccce80edf..86badb5661 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3145,6 +3145,15 @@ "contributions": [ "code" ] + }, + { + "login": "dbakan", + "name": "Daniel Albertsen", + "avatar_url": "https://avatars.githubusercontent.com/u/4498077?v=4", + "profile": "https://ditscheri.com", + "contributions": [ + "code" + ] } ] } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 54ab4d8ac1..361f973842 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -51,7 +51,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken | [
NojoudAlshehri](https://github.com/NojoudAlshehri)
[💻](https://github.com/snipe/snipe-it/commits?author=NojoudAlshehri "Code") | [
Stefan Stidl](https://github.com/stefanstidlffg)
[💻](https://github.com/snipe/snipe-it/commits?author=stefanstidlffg "Code") | [
Quentin Aymard](https://github.com/qay21)
[💻](https://github.com/snipe/snipe-it/commits?author=qay21 "Code") | [
Grant Le Roux](https://github.com/cram42)
[💻](https://github.com/snipe/snipe-it/commits?author=cram42 "Code") | [
Bogdan](http://@singrity)
[💻](https://github.com/snipe/snipe-it/commits?author=Singrity "Code") | [
mmanjos](https://github.com/mmanjos)
[💻](https://github.com/snipe/snipe-it/commits?author=mmanjos "Code") | [
Abdelaziz Faki](https://azooz2014.github.io/)
[💻](https://github.com/snipe/snipe-it/commits?author=Azooz2014 "Code") | | [
bilias](https://github.com/bilias)
[💻](https://github.com/snipe/snipe-it/commits?author=bilias "Code") | [
coach1988](https://github.com/coach1988)
[💻](https://github.com/snipe/snipe-it/commits?author=coach1988 "Code") | [
MrM](https://github.com/mauro-miatello)
[💻](https://github.com/snipe/snipe-it/commits?author=mauro-miatello "Code") | [
koiakoia](https://github.com/koiakoia)
[💻](https://github.com/snipe/snipe-it/commits?author=koiakoia "Code") | [
Mustafa Online](https://github.com/mustafa-online)
[💻](https://github.com/snipe/snipe-it/commits?author=mustafa-online "Code") | [
franceslui](https://github.com/franceslui)
[💻](https://github.com/snipe/snipe-it/commits?author=franceslui "Code") | [
Q4kK](https://github.com/Q4kK)
[💻](https://github.com/snipe/snipe-it/commits?author=Q4kK "Code") | | [
squintfox](https://github.com/squintfox)
[💻](https://github.com/snipe/snipe-it/commits?author=squintfox "Code") | [
Jeff Clay](https://github.com/jeffclay)
[💻](https://github.com/snipe/snipe-it/commits?author=jeffclay "Code") | [
Phil J R](https://github.com/PP-JN-RL)
[💻](https://github.com/snipe/snipe-it/commits?author=PP-JN-RL "Code") | [
i_virus](https://www.corelight.com/)
[💻](https://github.com/snipe/snipe-it/commits?author=chandanchowdhury "Code") | [
Paul Grime](https://github.com/gitgrimbo)
[💻](https://github.com/snipe/snipe-it/commits?author=gitgrimbo "Code") | [
Lee Porte](https://leeporte.co.uk)
[💻](https://github.com/snipe/snipe-it/commits?author=LeePorte "Code") | [
BRYAN ](https://github.com/bryanlopezinc)
[💻](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Code") [⚠️](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Tests") | -| [
U-H-T](https://github.com/U-H-T)
[💻](https://github.com/snipe/snipe-it/commits?author=U-H-T "Code") | [
Matt Tyree](https://github.com/Tyree)
[📖](https://github.com/snipe/snipe-it/commits?author=Tyree "Documentation") | [
Florent Bervas](http://spoontux.net)
[💻](https://github.com/snipe/snipe-it/commits?author=FlorentDotMe "Code") | +| [
U-H-T](https://github.com/U-H-T)
[💻](https://github.com/snipe/snipe-it/commits?author=U-H-T "Code") | [
Matt Tyree](https://github.com/Tyree)
[📖](https://github.com/snipe/snipe-it/commits?author=Tyree "Documentation") | [
Florent Bervas](http://spoontux.net)
[💻](https://github.com/snipe/snipe-it/commits?author=FlorentDotMe "Code") | [
Daniel Albertsen](https://ditscheri.com)
[💻](https://github.com/snipe/snipe-it/commits?author=dbakan "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! From 35160f88e0e909a7d20beeac2c75d730a9d25378 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 16 Jul 2024 16:09:08 +0100 Subject: [PATCH 5/5] Corrected return type Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetsController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 331bd07125..c929306184 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -475,7 +475,7 @@ class AssetsController extends Controller * @param int $assetId * @since [v1.0] */ - public function getQrCode($assetId = null) : Response | BinaryFileResponse + public function getQrCode($assetId = null) : Response | BinaryFileResponse | string | bool { $settings = Setting::getSettings(); @@ -502,6 +502,7 @@ class AssetsController extends Controller return 'That asset is invalid'; } + return false; } /**