mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-13 08:45:01 +00:00
added editor_move_file_to_another_folder, editor_move_folder_to_another_folder test
This commit is contained in:
@@ -330,8 +330,8 @@ class EditItemsController extends Controller
|
||||
return $new_file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* User download folder via zip
|
||||
*
|
||||
* @param $id
|
||||
@@ -341,7 +341,7 @@ class EditItemsController extends Controller
|
||||
{
|
||||
// Get user id
|
||||
$user_id = Auth::id();
|
||||
|
||||
|
||||
// Check permission to download for authenticated editor
|
||||
if ($request->user()->tokenCan('editor')) {
|
||||
|
||||
@@ -359,7 +359,7 @@ class EditItemsController extends Controller
|
||||
$folder = Folder::whereUserId($user_id)
|
||||
->where('id', $id);
|
||||
|
||||
if (! $folder->exists()) {
|
||||
if (!$folder->exists()) {
|
||||
abort(404, 'Requested folder doesn\'t exists.');
|
||||
}
|
||||
|
||||
@@ -391,8 +391,8 @@ class EditItemsController extends Controller
|
||||
// Get folder
|
||||
$folder = Folder::whereUserId($shared->user_id)
|
||||
->where('id', $id);
|
||||
|
||||
if (! $folder->exists()) {
|
||||
|
||||
if (!$folder->exists()) {
|
||||
abort(404, 'Requested folder doesn\'t exists.');
|
||||
}
|
||||
|
||||
@@ -535,39 +535,38 @@ class EditItemsController extends Controller
|
||||
// Get shared record
|
||||
$shared = get_shared($token);
|
||||
|
||||
//Unique id of Folder where move
|
||||
$to_id = $request->input('to_id');
|
||||
|
||||
// Demo preview
|
||||
if (is_demo(Auth::id())) {
|
||||
return Demo::response_204();
|
||||
}
|
||||
|
||||
// Check shared permission
|
||||
if (!is_editor($shared)) abort(403);
|
||||
if (is_visitor($shared)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
foreach ($request->input('items') as $item) {
|
||||
foreach ($request->items as $item) {
|
||||
|
||||
$id = $item['id'];
|
||||
$moving_id = $id;
|
||||
if ($item['type'] === 'folder') {
|
||||
|
||||
Guardian::check_item_access([
|
||||
$request->to_id, $item['id']
|
||||
], $shared);
|
||||
}
|
||||
|
||||
if ($item['type'] !== 'folder') {
|
||||
$file = File::where('id', $id)
|
||||
|
||||
$file = File::where('id', $item['id'])
|
||||
->where('user_id', $shared->user_id)
|
||||
->firstOrFail();
|
||||
|
||||
$moving_id = $file->folder_id;
|
||||
Guardian::check_item_access([
|
||||
$request->to_id, $file->folder_id
|
||||
], $shared);
|
||||
}
|
||||
|
||||
// Check access to requested item
|
||||
Guardian::check_item_access([
|
||||
$to_id, $moving_id
|
||||
], $shared);
|
||||
}
|
||||
|
||||
// Move item
|
||||
Editor::move($request, $to_id, $shared);
|
||||
Editor::move($request, $request->to_id);
|
||||
|
||||
return response('Done!', 204);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapShareRoutes();
|
||||
|
||||
$this->mapAdminApiRoutes();
|
||||
|
||||
$this->mapSetupWizardApiRoutes();
|
||||
@@ -98,6 +100,14 @@ class RouteServiceProvider extends ServiceProvider
|
||||
->group(base_path('routes/api.php'));
|
||||
}
|
||||
|
||||
protected function mapShareRoutes()
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/share.php'));
|
||||
}
|
||||
|
||||
protected function mapAdminApiRoutes()
|
||||
{
|
||||
Route::prefix('api/admin')
|
||||
|
||||
@@ -11,28 +11,6 @@ use App\Http\Controllers\FileFunctions\TrashController;
|
||||
use App\Http\Controllers\General\PricingController;
|
||||
use App\Http\Controllers\Sharing\FileSharingController;
|
||||
|
||||
// Edit Functions
|
||||
Route::group(['prefix' => 'editor'], function () {
|
||||
Route::patch('/rename/{id}/public/{token}', [EditItemsController::class, 'guest_rename_item']);
|
||||
Route::post('/create-folder/public/{token}', [EditItemsController::class, 'guest_create_folder']);
|
||||
Route::post('/remove/public/{token}', [EditItemsController::class, 'guest_delete_item']);
|
||||
Route::post('/upload/public/{token}', [EditItemsController::class, 'guest_upload']);
|
||||
Route::post('/move/public/{token}', [EditItemsController::class, 'guest_move']);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'zip'], function () {
|
||||
Route::get('/folder/{id}/public/{token}', [EditItemsController::class, 'guest_zip_folder']);
|
||||
Route::post('/files/public/{token}', [EditItemsController::class, 'guest_zip_multiple_files']);
|
||||
});
|
||||
|
||||
// Sharing page browsing
|
||||
Route::get('/folders/{unique_id}/public/{token}', [FileSharingController::class, 'get_public_folders']);
|
||||
Route::get('/navigation/public/{token}', [FileSharingController::class, 'get_public_navigation_tree']);
|
||||
Route::post('/shared/authenticate/{token}', [FileSharingController::class, 'authenticate']);
|
||||
Route::get('/search/public/{token}', [FileSharingController::class, 'search_public']);
|
||||
Route::get('/files/{token}/public', [FileSharingController::class, 'file_public']);
|
||||
Route::get('/shared/{token}', [ShareController::class, 'show']);
|
||||
|
||||
// Pages
|
||||
Route::post('/contact', [AppFunctionsController::class, 'contact_form']);
|
||||
Route::get('/page/{slug}', [AppFunctionsController::class, 'get_page']);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\FileFunctions\EditItemsController;
|
||||
use App\Http\Controllers\Sharing\FileSharingController;
|
||||
|
||||
// Editor functions
|
||||
Route::group(['prefix' => 'editor'], function () {
|
||||
Route::patch('/rename/{id}/public/{token}', [EditItemsController::class, 'guest_rename_item']);
|
||||
Route::post('/create-folder/public/{token}', [EditItemsController::class, 'guest_create_folder']);
|
||||
Route::post('/remove/public/{token}', [EditItemsController::class, 'guest_delete_item']);
|
||||
Route::post('/upload/public/{token}', [EditItemsController::class, 'guest_upload']);
|
||||
Route::post('/move/public/{token}', [EditItemsController::class, 'guest_move']);
|
||||
});
|
||||
|
||||
// Editor/Visitor zip functions
|
||||
Route::group(['prefix' => 'zip'], function () {
|
||||
Route::get('/folder/{id}/public/{token}', [EditItemsController::class, 'guest_zip_folder']);
|
||||
Route::post('/files/public/{token}', [EditItemsController::class, 'guest_zip_multiple_files']);
|
||||
});
|
||||
|
||||
// Sharing page browsing
|
||||
Route::get('/folders/{id}/public/{token}', [FileSharingController::class, 'get_public_folders']);
|
||||
Route::get('/navigation/public/{token}', [FileSharingController::class, 'get_public_navigation_tree']);
|
||||
Route::post('/shared/authenticate/{token}', [FileSharingController::class, 'authenticate']);
|
||||
Route::get('/search/public/{token}', [FileSharingController::class, 'search_public']);
|
||||
Route::get('/files/{token}/public', [FileSharingController::class, 'file_public']);
|
||||
Route::get('/shared/{token}', [ShareController::class, 'show']);
|
||||
@@ -201,7 +201,7 @@ class ShareEditorTest extends TestCase
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'user_scope' => 'master',
|
||||
]);
|
||||
|
||||
@@ -224,7 +224,7 @@ class ShareEditorTest extends TestCase
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('traffic', [
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
@@ -240,7 +240,107 @@ class ShareEditorTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_zip_shared_multiple_files()
|
||||
public function editor_move_file_to_another_folder()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
$children = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $root->id,
|
||||
]);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $root->id
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'item_id' => $root->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'folder',
|
||||
'is_protected' => false,
|
||||
'permission' => 'editor',
|
||||
]);
|
||||
|
||||
$this->postJson("/api/editor/move/public/$share->token", [
|
||||
'to_id' => $children->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'file',
|
||||
'id' => $file->id,
|
||||
]
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'id' => $file->id,
|
||||
'folder_id' => $children->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function editor_move_folder_to_another_folder()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
$brother = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $root->id,
|
||||
]);
|
||||
|
||||
$sister = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $root->id,
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'item_id' => $root->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'folder',
|
||||
'is_protected' => false,
|
||||
'permission' => 'editor',
|
||||
]);
|
||||
|
||||
$this->postJson("/api/editor/move/public/$share->token", [
|
||||
'to_id' => $brother->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'folder',
|
||||
'id' => $sister->id,
|
||||
]
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'id' => $sister->id,
|
||||
'parent_id' => $brother->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function guest_zip_shared_multiple_files()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
@@ -295,7 +395,7 @@ class ShareEditorTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_zip_non_shared_file_with_already_shared_multiple_files()
|
||||
public function guest_try_zip_non_shared_file_with_already_shared_multiple_files()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
@@ -332,7 +432,7 @@ class ShareEditorTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_zip_shared_folder()
|
||||
public function guest_zip_shared_folder()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
@@ -392,7 +492,7 @@ class ShareEditorTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_zip_non_shared_folder()
|
||||
public function guest_try_zip_non_shared_folder()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user