public share navigation

This commit is contained in:
Peter Papp
2021-08-23 08:30:34 +02:00
parent 882b5543f0
commit 26e3194f21
11 changed files with 193 additions and 56 deletions
@@ -7,7 +7,7 @@ use Domain\Folders\Models\Folder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
class BrowseFolderContentController
class BrowseFolderController
{
public function __invoke(
Request $request,
@@ -11,7 +11,7 @@ use Domain\Sharing\Actions\VerifyAccessToItemAction;
/**
* Browse shared folder
*/
class VisitorBrowseFolderContentController
class VisitorBrowseFolderController
{
public function __construct(
private ProtectShareRecordAction $protectShareRecord,
@@ -22,13 +22,16 @@ class VisitorBrowseFolderContentController
public function __invoke(
string $id,
Share $shared,
): Collection {
): array {
// Check ability to access protected share record
($this->protectShareRecord)($shared);
// Check if user can get directory
($this->verifyAccessToItem)($id, $shared);
$requestedFolder = Folder::findOrFail($id);
// Get files and folders
$folders = Folder::where('user_id', $shared->user_id)
->where('parent_id', $id)
@@ -44,7 +47,9 @@ class VisitorBrowseFolderContentController
$files->map(fn ($file) => $file->setPublicUrl($shared->token));
// Collect folders and files to single array
return collect([$folders, $files])
->collapse();
return [
'content' => collect([$folders, $files])->collapse(),
'folder' => $requestedFolder,
];
}
}