diff --git a/app/Http/Middleware/BindFileModelMiddleware.php b/app/Http/Middleware/BindFileModelMiddleware.php index d83d258..2758445 100644 --- a/app/Http/Middleware/BindFileModelMiddleware.php +++ b/app/Http/Middleware/BindFileModelMiddleware.php @@ -57,7 +57,7 @@ class BindFileModelMiddleware } if ($request->route()->action['as'] == 'api.files.destroy') { - $file = File::findOrFail($request->route('uuid')); + $file = File::withTrashed()->findOrFail($request->route('uuid')); $Collection = Collection::withTrashed()->where('name', $request->route('collection_name'))->firstOrFail(); if (Storage::disk($Collection->disk)->exists($file->server_path . $file->uuid . '.' . $Collection->ext)) { app()->bind('file', function () use ($file) { diff --git a/tests/Feature/FileDeleteTest.php b/tests/Feature/FileDeleteTest.php index 442b10f..0578939 100644 --- a/tests/Feature/FileDeleteTest.php +++ b/tests/Feature/FileDeleteTest.php @@ -41,6 +41,6 @@ class FileDeleteTest extends TestCase $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext)); $response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext])); - $response->assertok(); + $response->assertok(); } } diff --git a/tests/Feature/FileRestoreTest.php b/tests/Feature/FileRestoreTest.php new file mode 100644 index 0000000..bede701 --- /dev/null +++ b/tests/Feature/FileRestoreTest.php @@ -0,0 +1,47 @@ +assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy"); + } + + + public function test_user_with_permission_can_restore_file() + { + $collection = Collection::factory()->createQuietly([ + 'alt_required' => false, + 'description_required' => false, + 'tmp_support' => true, + 'max_width' => 2000, + 'max_height' => 2000, + 'min_width' => 1, + 'min_height' => 1, + 'min_file_size' => 0 + ]); + $uuid = app()->uuid; + $file = File::factory()->createQuietly([ + 'uuid' => $uuid, + 'server_path' => '/' . date('y') . '/' . date('m') . '/', + 'user_id' => auth()->id(), + 'collection_id' => $collection->id + ]); + $imageProcessor = new ImageProcessor; + $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext)); + + $file->delete(); + $response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext])); + $response->assertok(); + } +}