diff --git a/app/Http/Controllers/LocationsFilesController.php b/app/Http/Controllers/LocationsFilesController.php index 41425124c..3aaec0e08 100644 --- a/app/Http/Controllers/LocationsFilesController.php +++ b/app/Http/Controllers/LocationsFilesController.php @@ -26,17 +26,16 @@ class LocationsFilesController extends Controller */ public function store(UploadFileRequest $request, Location $location) : RedirectResponse { - $this->authorize('update', $location); if ($request->hasFile('file')) { + if (! Storage::exists('private_uploads/locations')) { Storage::makeDirectory('private_uploads/locations', 775); } foreach ($request->file('file') as $file) { - - $file_name = $request->handleFile('private_uploads/locations/','model-'.$location->id,$file); + $file_name = $request->handleFile('private_uploads/locations/','location-'.$location->id, $file); $location->logUpload($file_name, $request->get('notes')); } diff --git a/resources/views/partials/forms/edit/minimum_quantity.blade.php b/resources/views/partials/forms/edit/minimum_quantity.blade.php index 7a444583d..26c032116 100644 --- a/resources/views/partials/forms/edit/minimum_quantity.blade.php +++ b/resources/views/partials/forms/edit/minimum_quantity.blade.php @@ -3,7 +3,10 @@
- +
diff --git a/tests/Feature/Locations/Ui/UpdateLocationsTest.php b/tests/Feature/Locations/Ui/UpdateLocationsTest.php index 22d9ce577..a4c6e9c6b 100644 --- a/tests/Feature/Locations/Ui/UpdateLocationsTest.php +++ b/tests/Feature/Locations/Ui/UpdateLocationsTest.php @@ -4,7 +4,10 @@ namespace Tests\Feature\Locations\Ui; use App\Models\Location; use App\Models\User; +use App\Models\Actionlog; use Tests\TestCase; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\Storage; class UpdateLocationsTest extends TestCase { @@ -75,5 +78,36 @@ class UpdateLocationsTest extends TestCase } + public function testFileIsUploadedAndLogged() + { + $location = Location::factory()->create(); + Storage::fake('local'); + $file = UploadedFile::fake()->image('file.jpg', 100, 100)->size(100); + + $this->actingAs(User::factory()->superuser()->create()) + ->post(route('upload/locations', $location), [ + 'file' => [$file], + 'notes' => 'Test Upload', + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors(); + + + $location->refresh(); + + $logentry = Actionlog::where('item_type', Location::class) + ->where('item_id', $location->id) + ->where('action_type', 'uploaded') + ->first(); + + $this->assertTrue(Actionlog::where('item_type', Location:: class)->where('item_id', $location->id)->where('filename', $logentry->filename)->exists()); + + + // Assert the file was stored... + // This doesn't work with the way we handle files :( Should try to fix this. + // Storage::disk('local')->assertExists($logentry->filename); + + } + }