mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-13 16:55:01 +00:00
- ability leave team folder
- refactoring
This commit is contained in:
@@ -132,7 +132,7 @@ class SetupDevEnvironment extends Command
|
||||
],
|
||||
[
|
||||
'avatar' => 'avatar-03.png',
|
||||
'email' => $this->faker->email,
|
||||
'email' => 'johan@hi5ve.digital',
|
||||
],
|
||||
[
|
||||
'avatar' => 'avatar-04.png',
|
||||
@@ -805,6 +805,9 @@ class SetupDevEnvironment extends Command
|
||||
$owner = User::whereEmail('alice@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$johan = User::whereEmail('johan@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
@@ -828,25 +831,29 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'permission' => 'owner',
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'permission' => 'owner',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $johan->id,
|
||||
'permission' => 'owner',
|
||||
]
|
||||
]);
|
||||
|
||||
// Get meme gallery
|
||||
collect([
|
||||
'Sofishticated.jpg',
|
||||
'whaaaaat.jpg',
|
||||
'You Are My Sunshine.jpg',
|
||||
])
|
||||
->each(function ($file) use ($owner, $memes) {
|
||||
->each(function ($file) use ($owner, $folder) {
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
@@ -855,7 +862,7 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $memes->id,
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'name' => $file,
|
||||
'basename' => $basename,
|
||||
@@ -867,6 +874,34 @@ class SetupDevEnvironment extends Command
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// Get meme gallery
|
||||
collect([
|
||||
'You Are My Sunshine.jpg',
|
||||
])
|
||||
->each(function ($file) use ($johan, $folder) {
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
Storage::putFileAs("files/$johan->id", storage_path("demo/images/memes/$file"), $basename, 'private');
|
||||
Storage::putFileAs("files/$johan->id", storage_path("demo/images/memes/thumbnail-$file"), "thumbnail-$basename", 'private');
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $johan->id,
|
||||
'name' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'image',
|
||||
'author' => 'user',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'thumbnail' => "thumbnail-$basename",
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
collect([
|
||||
'Eggcited bro.jpg',
|
||||
'Get a Rest.jpg',
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Domain\Teams\Controllers;
|
||||
use Domain\Files\Resources\FilesCollection;
|
||||
use Domain\Folders\Resources\FolderCollection;
|
||||
use Domain\Folders\Resources\FolderResource;
|
||||
use Gate;
|
||||
use Str;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
@@ -18,6 +19,12 @@ class BrowseSharedWithMeController
|
||||
$id = Str::isUuid($id) ? $id : null;
|
||||
|
||||
if ($id) {
|
||||
$teamFolder = Folder::findOrFail($id)->getLatestParent();
|
||||
|
||||
if (! Gate::any(['can-edit', 'can-view'], [$teamFolder, null])) {
|
||||
abort(403, 'Access Denied');
|
||||
}
|
||||
|
||||
$folders = Folder::with(['parent:id,name'])
|
||||
->where('parent_id', $id)
|
||||
->sortable()
|
||||
@@ -44,7 +51,7 @@ class BrowseSharedWithMeController
|
||||
'root' => $id ? new FolderResource(Folder::findOrFail($id)) : null,
|
||||
'folders' => new FolderCollection($folders),
|
||||
'files' => isset($files) ? new FilesCollection($files) : new FilesCollection([]),
|
||||
'teamFolder' => $id ? new FolderResource(Folder::findOrFail($id)->getLatestParent()) : null,
|
||||
'teamFolder' => $id ? new FolderResource($teamFolder) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Auth;
|
||||
|
||||
class LeaveTeamFolderController extends Controller
|
||||
{
|
||||
public function __invoke(Folder $folder): Response|Application|ResponseFactory
|
||||
{
|
||||
// Find and delete attached member from team folder
|
||||
DB::table('team_folder_members')
|
||||
->where('parent_id', $folder->id)
|
||||
->where('user_id', Auth::id())
|
||||
->delete();
|
||||
|
||||
return response('Done.', 204);
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ use Gate;
|
||||
|
||||
class NavigationTreeController
|
||||
{
|
||||
public function __invoke(string $id): array
|
||||
public function __invoke(Folder $folder): array
|
||||
{
|
||||
$teamFolder = Folder::findOrFail($id)->getLatestParent();
|
||||
$teamFolder = $folder->getLatestParent();
|
||||
|
||||
if (! Gate::any(['can-edit', 'can-view'], [$teamFolder, null])) {
|
||||
abort(403, 'Access Denied');
|
||||
|
||||
Reference in New Issue
Block a user