mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-28 07:14:42 +00:00
- refactored move method
- refactored FavouriteController.php store method - added some tests methods
This commit is contained in:
@@ -116,7 +116,7 @@ class EditItemsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If request have a change folder icon values set the folder icon
|
// If request have a change folder icon values set the folder icon
|
||||||
if ($request->type === 'folder' && $request->filled('emoji')) {
|
if ($request->type === 'folder' && ($request->filled('emoji') || $request->filled('color'))) {
|
||||||
Editor::set_folder_icon($request, $id);
|
Editor::set_folder_icon($request, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,10 +499,11 @@ class EditItemsController extends Controller
|
|||||||
return Demo::response_204();
|
return Demo::response_204();
|
||||||
}
|
}
|
||||||
|
|
||||||
$to_unique_id = $request->input('to_unique_id');
|
$to_id = $request->input('to_id');
|
||||||
|
|
||||||
// Check permission to upload for authenticated editor
|
// Check permission to upload for authenticated editor
|
||||||
if ($request->user()->tokenCan('editor')) {
|
if ($request->user()->tokenCan('editor')) {
|
||||||
|
|
||||||
// check if shared_token cookie exist
|
// check if shared_token cookie exist
|
||||||
if (!$request->hasCookie('shared_token')) abort('401');
|
if (!$request->hasCookie('shared_token')) abort('401');
|
||||||
|
|
||||||
@@ -510,11 +511,11 @@ class EditItemsController extends Controller
|
|||||||
$shared = get_shared($request->cookie('shared_token'));
|
$shared = get_shared($request->cookie('shared_token'));
|
||||||
|
|
||||||
// Check access to requested directory
|
// Check access to requested directory
|
||||||
Guardian::check_item_access($to_unique_id, $shared);
|
Guardian::check_item_access($to_id, $shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move item
|
// Move item
|
||||||
Editor::move($request, $to_unique_id);
|
Editor::move($request, $to_id);
|
||||||
|
|
||||||
return response('Done!', 204);
|
return response('Done!', 204);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\FileFunctions;
|
namespace App\Http\Controllers\FileFunctions;
|
||||||
|
|
||||||
use App\Folder;
|
|
||||||
use App\Http\Tools\Demo;
|
use App\Http\Tools\Demo;
|
||||||
|
use App\Models\Folder;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -19,33 +19,25 @@ class FavouriteController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
// Validate request
|
// todo: pridat validator ako AddToFavouritesRequest
|
||||||
$validator = Validator::make($request->input('folders'), [
|
|
||||||
'*.unique_id' => 'required|integer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Return error
|
foreach ($request->input('folders') as $id) {
|
||||||
if ($validator->fails()) abort(400, 'Bad input');
|
|
||||||
|
|
||||||
foreach($request->input('folders') as $item) {
|
// Get user & folder
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
// Get user & folder
|
if (is_demo($user->id)) {
|
||||||
$user = Auth::user();
|
return Demo::favourites($user);
|
||||||
$folder = Folder::where('unique_id', $item['unique_id'])->first();
|
}
|
||||||
|
|
||||||
if (is_demo($user->id)) {
|
// Add folder to user favourites
|
||||||
return Demo::favourites($user);
|
$user
|
||||||
|
->favourite_folders()
|
||||||
|
->syncWithoutDetaching($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ownership
|
|
||||||
if ($folder->user_id !== $user->id) abort(403);
|
|
||||||
|
|
||||||
// Add folder to user favourites
|
|
||||||
$user->favourite_folders()->syncWithoutDetaching($item['unique_id']);
|
|
||||||
|
|
||||||
}
|
|
||||||
// Return updated favourites
|
// Return updated favourites
|
||||||
return $user->favourite_folders;
|
return response($user->favourite_folders, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ class MoveItemRequest extends FormRequest
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'to_unique_id' => 'required|integer',
|
'to_id' => 'required|uuid',
|
||||||
'items[*].type' => 'required|string',
|
'items[*].type' => 'required|string',
|
||||||
'items[*].unique_id' => 'required|integer',
|
'items[*].id' => 'required|uuid',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-24
@@ -386,38 +386,28 @@ class Editor
|
|||||||
* Move folder or file to new location
|
* Move folder or file to new location
|
||||||
*
|
*
|
||||||
* @param $request
|
* @param $request
|
||||||
* @param $unique_id
|
* @param $to_id
|
||||||
* @param null $shared
|
|
||||||
*/
|
*/
|
||||||
public static function move($request, $to_unique_id, $shared = null)
|
public static function move($request, $to_id)
|
||||||
{
|
{
|
||||||
// Get user id
|
|
||||||
$user_id = is_null($shared) ? Auth::id() : $shared->user_id;
|
|
||||||
|
|
||||||
foreach ($request->input('items') as $item) {
|
foreach ($request->input('items') as $item) {
|
||||||
$unique_id = $item['unique_id'];
|
|
||||||
|
|
||||||
|
// Move folder
|
||||||
if ($item['type'] === 'folder') {
|
if ($item['type'] === 'folder') {
|
||||||
|
|
||||||
// Move folder
|
Folder::find($item['id'])
|
||||||
$item = Folder::where('user_id', $user_id)
|
->update([
|
||||||
->where('unique_id', $unique_id)
|
'parent_id' => $to_id
|
||||||
->firstOrFail();
|
]);
|
||||||
|
|
||||||
$item->update([
|
}
|
||||||
'parent_id' => $to_unique_id
|
|
||||||
]);
|
|
||||||
|
|
||||||
} else {
|
// Move file
|
||||||
|
if ($item['type'] === 'file') {
|
||||||
// Move file under new folder
|
UserFile::find($item['id'])
|
||||||
$item = UserFile::where('user_id', $user_id)
|
->update([
|
||||||
->where('unique_id', $unique_id)
|
'folder_id' => $to_id
|
||||||
->firstOrFail();
|
]);
|
||||||
|
|
||||||
$item->update([
|
|
||||||
'folder_id' => $to_unique_id
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -243,7 +243,7 @@ class User extends Authenticatable
|
|||||||
*/
|
*/
|
||||||
public function favourite_folders()
|
public function favourite_folders()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'folder_unique_id', 'id', 'unique_id')->with('shared:token,id,item_id,permission,protected,expire_in');
|
return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'folder_id', 'id', 'id')->with('shared:token,id,item_id,permission,protected,expire_in');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-1
@@ -35,7 +35,8 @@
|
|||||||
"fzaninotto/faker": "^1.9.1",
|
"fzaninotto/faker": "^1.9.1",
|
||||||
"mockery/mockery": "^1.3.1",
|
"mockery/mockery": "^1.3.1",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^5.0",
|
||||||
"phpunit/phpunit": "^9.5.2"
|
"phpunit/phpunit": "^9.5.2",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|||||||
use Laravel\Sanctum\Sanctum;
|
use Laravel\Sanctum\Sanctum;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
// TODO: pridat foldre do api skupiny
|
||||||
|
|
||||||
class FolderTest extends TestCase
|
class FolderTest extends TestCase
|
||||||
{
|
{
|
||||||
use DatabaseMigrations;
|
use DatabaseMigrations;
|
||||||
@@ -35,7 +37,6 @@ class FolderTest extends TestCase
|
|||||||
|
|
||||||
Sanctum::actingAs($user);
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
// TODO: pridat do api skupiny
|
|
||||||
$this->postJson('/api/create-folder', [
|
$this->postJson('/api/create-folder', [
|
||||||
'name' => 'New Folder',
|
'name' => 'New Folder',
|
||||||
'parent_id' => null,
|
'parent_id' => null,
|
||||||
@@ -63,7 +64,6 @@ class FolderTest extends TestCase
|
|||||||
|
|
||||||
Sanctum::actingAs($user);
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
// TODO: pridat do api skupiny
|
|
||||||
$this->patchJson("/api/rename/{$folder->id}", [
|
$this->patchJson("/api/rename/{$folder->id}", [
|
||||||
'name' => 'Renamed Folder',
|
'name' => 'Renamed Folder',
|
||||||
'type' => 'folder',
|
'type' => 'folder',
|
||||||
@@ -91,44 +91,115 @@ class FolderTest extends TestCase
|
|||||||
|
|
||||||
Sanctum::actingAs($user);
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
// TODO: pridat do api skupiny
|
$emoji_fragment = [
|
||||||
|
'category' => 'Smileys & Emotion (face-smiling)',
|
||||||
|
'char' => '😁',
|
||||||
|
'name' => 'beaming face with smiling eyes',
|
||||||
|
];
|
||||||
|
|
||||||
$this->patchJson("/api/rename/{$folder->id}", [
|
$this->patchJson("/api/rename/{$folder->id}", [
|
||||||
'name' => 'Renamed Folder',
|
'name' => 'Renamed Folder',
|
||||||
'type' => 'folder',
|
'type' => 'folder',
|
||||||
'emoji' => [
|
'emoji' => $emoji_fragment
|
||||||
'category' => 'Smileys & Emotion (face-smiling)',
|
|
||||||
'char' => '😁',
|
|
||||||
'name' => 'beaming face with smiling eyes',
|
|
||||||
]
|
|
||||||
])
|
])
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonFragment([
|
->assertJsonFragment([
|
||||||
'name' => 'Renamed Folder',
|
'name' => 'Renamed Folder',
|
||||||
'emoji' => [
|
'emoji' => $emoji_fragment
|
||||||
'category' => 'Smileys & Emotion (face-smiling)',
|
|
||||||
'char' => '😁',
|
|
||||||
'name' => 'beaming face with smiling eyes',
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseMissing('folders', [
|
$this->assertDatabaseHas('folders', [
|
||||||
'emoji' => null
|
'color' => null,
|
||||||
|
'emoji' => json_encode($emoji_fragment)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
public function it_set_folder_color()
|
public function it_set_folder_color()
|
||||||
{
|
{
|
||||||
|
$folder = Folder::factory(Folder::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->patchJson("/api/rename/{$folder->id}", [
|
||||||
|
'name' => 'Folder Name',
|
||||||
|
'type' => 'folder',
|
||||||
|
'color' => '#AD6FFE'
|
||||||
|
])
|
||||||
|
->assertStatus(200)
|
||||||
|
->assertJsonFragment([
|
||||||
|
'name' => 'Folder Name',
|
||||||
|
'emoji' => null,
|
||||||
|
'color' => '#AD6FFE',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('folders', [
|
||||||
|
'color' => '#AD6FFE',
|
||||||
|
'emoji' => null,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
public function it_move_folder_to_another_folder()
|
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
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_add_to_favourites_folder()
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_add_folder_to_favourites()
|
||||||
{
|
{
|
||||||
|
$folder = Folder::factory(Folder::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
$this->postJson("/api/folders/favourites", [
|
||||||
|
'folders' => [
|
||||||
|
$folder->id
|
||||||
|
],
|
||||||
|
])->assertStatus(204);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('favourite_folder', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'folder_id' => $folder->id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_zip_and_download_folder_with_content_within()
|
public function it_zip_and_download_folder_with_content_within()
|
||||||
|
|||||||
Reference in New Issue
Block a user