mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
added it_rename_file, it_move_file_to_another_folder, it_delete_multiple_files_softly
This commit is contained in:
@@ -188,13 +188,13 @@ class EditItemsController extends Controller
|
||||
return Demo::response_204();
|
||||
}
|
||||
|
||||
foreach ($request->input('items') as $file) {
|
||||
foreach ($request->input('items') as $item) {
|
||||
|
||||
// Check permission to delete item for authenticated editor
|
||||
if ($request->user()->tokenCan('editor')) {
|
||||
|
||||
// Prevent force delete for non-master users
|
||||
if ($file['force_delete']) abort('401');
|
||||
if ($item['force_delete']) abort('401');
|
||||
|
||||
// check if shared_token cookie exist
|
||||
if (!$request->hasCookie('shared_token')) abort('401');
|
||||
@@ -203,10 +203,10 @@ class EditItemsController extends Controller
|
||||
$shared = get_shared($request->cookie('shared_token'));
|
||||
|
||||
// Get file|folder item
|
||||
$item = get_item($file['type'], $file['id']);
|
||||
$item = get_item($item['type'], $item['id']);
|
||||
|
||||
// Check access to requested directory
|
||||
if ($file['type'] === 'folder') {
|
||||
if ($item['type'] === 'folder') {
|
||||
Guardian::check_item_access($item->id, $shared);
|
||||
} else {
|
||||
Guardian::check_item_access($item->folder_id, $shared);
|
||||
@@ -214,7 +214,7 @@ class EditItemsController extends Controller
|
||||
}
|
||||
|
||||
// Delete item
|
||||
Editor::delete_item($file, $file['id']);
|
||||
Editor::delete_item($item, $item['id']);
|
||||
}
|
||||
|
||||
return response(null, 204);
|
||||
|
||||
@@ -337,18 +337,15 @@ class Editor
|
||||
}
|
||||
|
||||
// Delete item
|
||||
if ($item['type'] !== 'folder') {
|
||||
if ($item['type'] === 'file') {
|
||||
|
||||
// Get file
|
||||
$item = File::withTrashed()
|
||||
->where('user_id', $user->id)
|
||||
->where('unique_id', $unique_id)
|
||||
->first();
|
||||
$item = UserFile::withTrashed()
|
||||
->find($id);
|
||||
|
||||
// Get folder shared record
|
||||
$shared = Share::where('user_id', $user->id)
|
||||
->where('type', '=', 'file')
|
||||
->where('item_id', $unique_id)
|
||||
$shared = Share::where('type', 'file')
|
||||
->where('item_id', $id)
|
||||
->first();
|
||||
|
||||
// Delete file shared record
|
||||
@@ -357,7 +354,7 @@ class Editor
|
||||
}
|
||||
|
||||
// Force delete file
|
||||
if ($file['force_delete']) {
|
||||
if ($item['force_delete']) {
|
||||
|
||||
// Delete file
|
||||
Storage::delete('/file-manager/' . $item->basename);
|
||||
@@ -370,7 +367,7 @@ class Editor
|
||||
}
|
||||
|
||||
// Soft delete file
|
||||
if (!$file['force_delete']) {
|
||||
if (!$item['force_delete']) {
|
||||
|
||||
// Soft delete file
|
||||
$item->delete();
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Folder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FileTest extends TestCase
|
||||
@@ -28,12 +31,106 @@ class FileTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_rename_file()
|
||||
{
|
||||
$file = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->patchJson("/api/rename/{$file->id}", [
|
||||
'name' => 'Renamed Item',
|
||||
'type' => 'file',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Item',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'name' => 'Renamed Item'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_move_file_to_another_folder()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/move", [
|
||||
'to_id' => $folder->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'file',
|
||||
'id' => $file->id,
|
||||
]
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'id' => $file->id,
|
||||
'folder_id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_multiple_files_softly()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$file_1 = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
$file_2 = File::factory(File::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $file_1->id,
|
||||
'type' => 'file',
|
||||
'force_delete' => false,
|
||||
],
|
||||
[
|
||||
'id' => $file_2->id,
|
||||
'type' => 'file',
|
||||
'force_delete' => false,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertSoftDeleted('files', [
|
||||
'id' => $file_1->id,
|
||||
]);
|
||||
|
||||
$this->assertSoftDeleted('files', [
|
||||
'id' => $file_2->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function it_delete_multiple_files_hardly()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -42,24 +139,4 @@ class FileTest extends TestCase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_delete_single_file()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_delete_multiple_files()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_delete_file_softly()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_delete_file_hardly()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class FolderTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_set_folder_icon()
|
||||
public function it_set_folder_emoji()
|
||||
{
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create();
|
||||
@@ -145,37 +145,6 @@ class FolderTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_move_folder_to_another_folder()
|
||||
{
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/move", [
|
||||
'to_id' => $root->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'folder',
|
||||
'id' => $children->id,
|
||||
]
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertEquals(
|
||||
$root->id, Folder::find($children->id)->parent_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@@ -227,6 +196,37 @@ class FolderTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_move_folder_to_another_folder()
|
||||
{
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/move", [
|
||||
'to_id' => $root->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'folder',
|
||||
'id' => $children->id,
|
||||
]
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertEquals(
|
||||
$root->id, Folder::find($children->id)->parent_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user