mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-21 01:12:14 +00:00
controller refactoring part 24
This commit is contained in:
@@ -5,7 +5,8 @@ use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Support\Services\HelperService;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Browse shared folder
|
||||
@@ -13,7 +14,8 @@ use Support\Services\HelperService;
|
||||
class VisitorBrowseFolderContentController
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -22,10 +24,10 @@ class VisitorBrowseFolderContentController
|
||||
Share $shared,
|
||||
): Collection {
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check if user can get directory
|
||||
$this->helper->check_item_access($id, $shared);
|
||||
($this->verifyAccessToItem)($id, $shared);
|
||||
|
||||
// Get files and folders
|
||||
$folders = Folder::where('user_id', $shared->user_id)
|
||||
|
||||
@@ -7,8 +7,8 @@ use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
|
||||
/**
|
||||
* Visitor search shared files
|
||||
@@ -16,7 +16,7 @@ use App\Http\Controllers\Controller;
|
||||
class VisitorSearchFilesAndFoldersController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class VisitorSearchFilesAndFoldersController extends Controller
|
||||
Share $shared,
|
||||
): Collection {
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
$query = remove_accents(
|
||||
$request->input('query')
|
||||
|
||||
@@ -14,7 +14,8 @@ class GetFileController extends Controller
|
||||
public function __construct(
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private DownloadFileAction $downloadFile,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
namespace Domain\Files\Controllers\FileAccess;
|
||||
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Files\Models\File as UserFile;
|
||||
use Domain\Files\Actions\DownloadFileAction;
|
||||
use Domain\Traffic\Actions\RecordDownloadAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
|
||||
|
||||
/**
|
||||
* Get file public
|
||||
@@ -16,6 +18,8 @@ class VisitorGetFileController extends Controller
|
||||
public function __construct(
|
||||
private DownloadFileAction $downloadFile,
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -24,15 +28,15 @@ class VisitorGetFileController extends Controller
|
||||
Share $shared,
|
||||
): BinaryFileResponse {
|
||||
// Check ability to access protected share files
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Get file record
|
||||
$file = UserFile::where('user_id', $shared->user_id)
|
||||
$file = File::where('user_id', $shared->user_id)
|
||||
->where('basename', $filename)
|
||||
->firstOrFail();
|
||||
|
||||
// Check file access
|
||||
$this->helper->check_guest_access_to_shared_items($shared, $file);
|
||||
($this->verifyAccessToItemWithin)($shared, $file);
|
||||
|
||||
// Store user download size
|
||||
($this->recordDownload)(
|
||||
@@ -40,6 +44,7 @@ class VisitorGetFileController extends Controller
|
||||
user_id: $shared->user_id,
|
||||
);
|
||||
|
||||
// Finally download file
|
||||
return ($this->downloadFile)($file, $shared->user_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use App\Http\Controllers\Controller;
|
||||
use Domain\Files\Models\File as UserFile;
|
||||
use Domain\Traffic\Actions\RecordDownloadAction;
|
||||
use Domain\Files\Actions\DownloadThumbnailAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
|
||||
|
||||
/**
|
||||
* Get public image thumbnail
|
||||
@@ -16,6 +18,8 @@ class VisitorGetThumbnailController extends Controller
|
||||
public function __construct(
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private DownloadThumbnailAction $downloadThumbnail,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -24,7 +28,7 @@ class VisitorGetThumbnailController extends Controller
|
||||
Share $shared,
|
||||
): StreamedResponse {
|
||||
// Check ability to access protected share files
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Get file record
|
||||
$file = UserFile::where('user_id', $shared->user_id)
|
||||
@@ -32,7 +36,7 @@ class VisitorGetThumbnailController extends Controller
|
||||
->firstOrFail();
|
||||
|
||||
// Check file access
|
||||
$this->helper->check_guest_access_to_shared_items($shared, $file);
|
||||
($this->verifyAccessToItemWithin)($shared, $file);
|
||||
|
||||
// Store user download size
|
||||
($this->recordDownload)(
|
||||
@@ -40,6 +44,7 @@ class VisitorGetThumbnailController extends Controller
|
||||
user_id: $shared->user_id,
|
||||
);
|
||||
|
||||
// Finally download thumbnail
|
||||
return ($this->downloadThumbnail)($file, $shared->user_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Domain\Files\Controllers;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use Domain\Files\Resources\FileResource;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
|
||||
/**
|
||||
* Get shared file record
|
||||
@@ -13,7 +13,7 @@ use Domain\Files\Resources\FileResource;
|
||||
class VisitorShowFileController
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class VisitorShowFileController
|
||||
Share $shared
|
||||
): Response {
|
||||
// Check ability to access protected share files
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Get file
|
||||
$file = File::whereUserId($shared->user_id)
|
||||
|
||||
@@ -3,11 +3,12 @@ namespace Domain\Files\Controllers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Files\Requests\UploadRequest;
|
||||
use Domain\Files\Actions\UploadFileAction;
|
||||
use Support\Demo\Actions\FakeUploadFileAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* guest user upload file into shared folder
|
||||
@@ -15,22 +16,23 @@ use Support\Demo\Actions\FakeUploadFileAction;
|
||||
class VisitorUploadFileController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private UploadFileAction $uploadFile,
|
||||
private FakeUploadFileAction $fakeUploadFile,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
FakeUploadFileAction $fakeUploadFile,
|
||||
UploadFileAction $uploadFile,
|
||||
UploadRequest $request,
|
||||
Share $shared,
|
||||
): Response | array {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return ($fakeUploadFile)($request);
|
||||
return ($this->fakeUploadFile)($request);
|
||||
}
|
||||
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check shared permission
|
||||
if (is_visitor($shared)) {
|
||||
@@ -38,10 +40,10 @@ class VisitorUploadFileController extends Controller
|
||||
}
|
||||
|
||||
// Check access to requested directory
|
||||
$this->helper->check_item_access($request->folder_id, $shared);
|
||||
($this->verifyAccessToItem)($request->folder_id, $shared);
|
||||
|
||||
// Return new uploaded file
|
||||
$new_file = ($uploadFile)($request, $shared);
|
||||
$new_file = ($this->uploadFile)($request, $shared);
|
||||
|
||||
// Set public access url
|
||||
$new_file->setPublicUrl($shared->token);
|
||||
|
||||
@@ -19,6 +19,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
/**
|
||||
* @method static whereUserId($user_id)
|
||||
* @method static whereId($id)
|
||||
* @property string folder_id
|
||||
* @property string id
|
||||
*/
|
||||
class File extends Model
|
||||
{
|
||||
|
||||
@@ -3,11 +3,12 @@ namespace Domain\Folders\Controllers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Folders\Actions\CreateFolderAction;
|
||||
use Domain\Folders\Requests\CreateFolderRequest;
|
||||
use Support\Demo\Actions\FakeCreateFolderAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Create new folder for guest user with edit permission
|
||||
@@ -15,22 +16,23 @@ use Support\Demo\Actions\FakeCreateFolderAction;
|
||||
class VisitorCreateFolderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private CreateFolderAction $createFolder,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
private FakeCreateFolderAction $fakeCreateFolderAction,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
FakeCreateFolderAction $fakeCreateFolderAction,
|
||||
CreateFolderAction $createFolder,
|
||||
CreateFolderRequest $request,
|
||||
Share $shared,
|
||||
): Response | array {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return ($fakeCreateFolderAction)($request);
|
||||
return ($this->fakeCreateFolderAction)($request);
|
||||
}
|
||||
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check shared permission
|
||||
if (is_visitor($shared)) {
|
||||
@@ -38,10 +40,10 @@ class VisitorCreateFolderController extends Controller
|
||||
}
|
||||
|
||||
// Check access to requested directory
|
||||
$this->helper->check_item_access($request->parent_id, $shared);
|
||||
($this->verifyAccessToItem)($request->parent_id, $shared);
|
||||
|
||||
// Create folder
|
||||
$folder = ($createFolder)($request, $shared);
|
||||
$folder = ($this->createFolder)($request, $shared);
|
||||
|
||||
return response($folder, 201);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ namespace Domain\Folders\Controllers;
|
||||
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Get navigation tree of shared folder
|
||||
@@ -12,7 +13,8 @@ use App\Http\Controllers\Controller;
|
||||
class VisitorNavigationFolderTreeController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -20,10 +22,10 @@ class VisitorNavigationFolderTreeController extends Controller
|
||||
Share $shared,
|
||||
): array {
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check if user can get directory
|
||||
$this->helper->check_item_access($shared->item_id, $shared);
|
||||
($this->verifyAccessToItem)($shared->item_id, $shared);
|
||||
|
||||
// Get folders
|
||||
$folders = Folder::with('folders:id,parent_id,name')
|
||||
|
||||
@@ -3,10 +3,11 @@ namespace Domain\Items\Controllers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Items\Requests\DeleteItemRequest;
|
||||
use Domain\Items\Actions\DeleteFileOrFolderAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Delete item for guest user with edit permission
|
||||
@@ -14,8 +15,9 @@ use Domain\Items\Actions\DeleteFileOrFolderAction;
|
||||
class VisitorDeleteFileOrFolderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private HelperService $helper,
|
||||
private DeleteFileOrFolderAction $deleteFileOrFolder,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -30,7 +32,7 @@ class VisitorDeleteFileOrFolderController extends Controller
|
||||
);
|
||||
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check shared permission
|
||||
if (is_visitor($shared)) {
|
||||
@@ -43,9 +45,9 @@ class VisitorDeleteFileOrFolderController extends Controller
|
||||
|
||||
// Check access to requested item
|
||||
if ($file['type'] === 'folder') {
|
||||
$this->helper->check_item_access($item->id, $shared);
|
||||
($this->verifyAccessToItem)($item->id, $shared);
|
||||
} else {
|
||||
$this->helper->check_item_access($item->folder_id, $shared);
|
||||
($this->verifyAccessToItem)($item->folder_id, $shared);
|
||||
}
|
||||
|
||||
// Delete item
|
||||
|
||||
@@ -4,10 +4,11 @@ namespace Domain\Items\Controllers;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Items\Requests\MoveItemRequest;
|
||||
use Domain\Items\Actions\MoveFileOrFolderAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Move item for guest user with edit permission
|
||||
@@ -15,8 +16,9 @@ use Domain\Items\Actions\MoveFileOrFolderAction;
|
||||
class VisitorMoveFileOrFolderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private HelperService $helper,
|
||||
private MoveFileOrFolderAction $moveFileOrFolder,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -31,7 +33,7 @@ class VisitorMoveFileOrFolderController extends Controller
|
||||
);
|
||||
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check shared permission
|
||||
if (is_visitor($shared)) {
|
||||
@@ -40,7 +42,7 @@ class VisitorMoveFileOrFolderController extends Controller
|
||||
|
||||
foreach ($request->input('items') as $item) {
|
||||
if ($item['type'] === 'folder') {
|
||||
$this->helper->check_item_access([
|
||||
($this->verifyAccessToItem)([
|
||||
$request->input('to_id'), $item['id'],
|
||||
], $shared);
|
||||
}
|
||||
@@ -50,7 +52,7 @@ class VisitorMoveFileOrFolderController extends Controller
|
||||
->where('user_id', $shared->user_id)
|
||||
->firstOrFail();
|
||||
|
||||
$this->helper->check_item_access([
|
||||
($this->verifyAccessToItem)([
|
||||
$request->input('to_id'), $file->folder_id,
|
||||
], $shared);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ namespace Domain\Items\Controllers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Items\Requests\RenameItemRequest;
|
||||
use Domain\Items\Actions\RenameFileOrFolderAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
use Domain\Folders\Actions\UpdateFolderPropertyAction;
|
||||
use Support\Demo\Actions\FakeRenameFileOrFolderAction;
|
||||
|
||||
@@ -16,8 +17,9 @@ use Support\Demo\Actions\FakeRenameFileOrFolderAction;
|
||||
class VisitorRenameFileOrFolderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private HelperService $helper,
|
||||
private RenameFileOrFolderAction $renameFileOrFolder,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
private UpdateFolderPropertyAction $updateFolderProperty,
|
||||
private FakeRenameFileOrFolderAction $fakeRenameFileOrFolder,
|
||||
) {
|
||||
@@ -27,14 +29,14 @@ class VisitorRenameFileOrFolderController extends Controller
|
||||
RenameItemRequest $request,
|
||||
string $id,
|
||||
Share $shared,
|
||||
): Response {
|
||||
): Response | array {
|
||||
// Return fake renamed item in demo
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
return ($this->fakeRenameFileOrFolder)($request, $id);
|
||||
}
|
||||
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check shared permission
|
||||
if (is_visitor($shared)) {
|
||||
@@ -46,9 +48,9 @@ class VisitorRenameFileOrFolderController extends Controller
|
||||
|
||||
// Check access to requested item
|
||||
if ($request->input('type') === 'folder') {
|
||||
$this->helper->check_item_access($item->id, $shared);
|
||||
($this->verifyAccessToItem)($item->id, $shared);
|
||||
} else {
|
||||
$this->helper->check_item_access($item->folder_id, $shared);
|
||||
($this->verifyAccessToItem)($item->folder_id, $shared);
|
||||
}
|
||||
|
||||
// If request have a change folder icon values set the folder icon
|
||||
|
||||
33
src/Domain/Sharing/Actions/ProtectShareRecordAction.php
Normal file
33
src/Domain/Sharing/Actions/ProtectShareRecordAction.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Domain\Sharing\Actions;
|
||||
|
||||
use Domain\Sharing\Models\Share;
|
||||
|
||||
class ProtectShareRecordAction
|
||||
{
|
||||
public function __invoke(Share $shared): void
|
||||
{
|
||||
if ($shared->is_protected) {
|
||||
$abort_message = "Sorry, you don't have permission";
|
||||
|
||||
if (! request()->hasCookie('share_session')) {
|
||||
abort(403, $abort_message);
|
||||
}
|
||||
|
||||
// Get shared session
|
||||
$share_session = json_decode(
|
||||
request()->cookie('share_session')
|
||||
);
|
||||
|
||||
// Check if is requested same share record
|
||||
if ($share_session->token !== $shared->token) {
|
||||
abort(403, $abort_message);
|
||||
}
|
||||
|
||||
// Check if share record was authenticated previously via ShareController@authenticate
|
||||
if (! $share_session->authenticated) {
|
||||
abort(403, $abort_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
src/Domain/Sharing/Actions/VerifyAccessToItemAction.php
Normal file
41
src/Domain/Sharing/Actions/VerifyAccessToItemAction.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Domain\Sharing\Actions;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
|
||||
class VerifyAccessToItemAction
|
||||
{
|
||||
/**
|
||||
* Check access to requested directory
|
||||
*/
|
||||
public function __invoke(
|
||||
string | array $requested_id,
|
||||
Share $shared,
|
||||
): void {
|
||||
// Get all children folders
|
||||
$foldersIds = Folder::with('folders:id,parent_id,id,name')
|
||||
->where('user_id', $shared->user_id)
|
||||
->where('parent_id', $shared->item_id)
|
||||
->get();
|
||||
|
||||
// Get all authorized parent folders by shared folder as root of tree
|
||||
$accessible_folder_ids = Arr::flatten([filter_folders_ids($foldersIds), $shared->item_id]);
|
||||
|
||||
// Check user access
|
||||
if (is_array($requested_id)) {
|
||||
foreach ($requested_id as $id) {
|
||||
if (! in_array($id, $accessible_folder_ids)) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! is_array($requested_id)) {
|
||||
if (! in_array($requested_id, $accessible_folder_ids)) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Domain\Sharing\Actions;
|
||||
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Models\Share;
|
||||
|
||||
class VerifyAccessToItemWithinAction
|
||||
{
|
||||
public function __construct(
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user file access
|
||||
*/
|
||||
public function __invoke(
|
||||
Share $shared,
|
||||
File $file
|
||||
): void {
|
||||
// Check by parent folder permission
|
||||
if ($shared->type === 'folder') {
|
||||
($this->verifyAccessToItem)($file->folder_id, $shared);
|
||||
}
|
||||
|
||||
// Check by single file permission
|
||||
if ($shared->type === 'file') {
|
||||
if ($shared->item_id !== $file->id) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,18 @@ use Domain\Sharing\Actions\SendViaEmailAction;
|
||||
|
||||
class ShareViaEmailController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private SendViaEmailAction $sendLinkToEmailAction,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
SendViaEmailAction $sendLinkToEmailAction,
|
||||
Request $request,
|
||||
string $token,
|
||||
): Response {
|
||||
($sendLinkToEmailAction)(
|
||||
$request->input('emails'),
|
||||
$token
|
||||
($this->sendLinkToEmailAction)(
|
||||
emails: $request->input('emails'),
|
||||
token: $token,
|
||||
);
|
||||
|
||||
return response('Done!', 204);
|
||||
|
||||
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
use Domain\Sharing\Resources\ShareResource;
|
||||
use Domain\Sharing\Requests\AuthenticateShareRequest;
|
||||
|
||||
class VisitorAuthenticateProtectedShareController extends Controller
|
||||
class VisitorUnlockLockedShareController extends Controller
|
||||
{
|
||||
/**
|
||||
* Check Password for protected item
|
||||
@@ -5,7 +5,7 @@ use Illuminate\View\View;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class OGSiteController extends Controller
|
||||
class WebCrawlerOpenGraphController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get og site for web crawlers
|
||||
@@ -12,6 +12,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
* @method static whereNotNull(string $string)
|
||||
* @method static where(string $string, string $token)
|
||||
* @property string user_id
|
||||
* @property mixed is_protected
|
||||
* @property string token
|
||||
* @property string item_id
|
||||
* @property string type
|
||||
* @property string password
|
||||
* @property User user
|
||||
*/
|
||||
class Share extends Model
|
||||
{
|
||||
|
||||
@@ -5,9 +5,10 @@ use Illuminate\Http\Request;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Zipping\Actions\ZipFilesAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Guest download multiple files via zip
|
||||
@@ -15,7 +16,8 @@ use Domain\Zipping\Actions\ZipFilesAction;
|
||||
class VisitorZipFilesController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ class VisitorZipFilesController extends Controller
|
||||
Share $shared,
|
||||
): Response {
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
$file_parent_folders = File::whereUserId($shared->user_id)
|
||||
->whereIn('id', $request->items)
|
||||
@@ -34,7 +36,7 @@ class VisitorZipFilesController extends Controller
|
||||
->toArray();
|
||||
|
||||
// Check access to requested directory
|
||||
$this->helper->check_item_access($file_parent_folders, $shared);
|
||||
($this->verifyAccessToItem)($file_parent_folders, $shared);
|
||||
|
||||
// Get requested files
|
||||
$files = File::whereUserId($shared->user_id)
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace Domain\Zipping\Controllers;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Support\Services\HelperService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Zipping\Actions\ZipFolderAction;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemAction;
|
||||
|
||||
/**
|
||||
* Guest download folder via zip
|
||||
@@ -14,7 +15,8 @@ use Domain\Zipping\Actions\ZipFolderAction;
|
||||
class VisitorZipFolderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HelperService $helper,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemAction $verifyAccessToItem,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -24,10 +26,10 @@ class VisitorZipFolderController extends Controller
|
||||
Share $shared,
|
||||
): Response {
|
||||
// Check ability to access protected share record
|
||||
$this->helper->check_protected_share_record($shared);
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Check access to requested folder
|
||||
$this->helper->check_item_access($id, $shared);
|
||||
($this->verifyAccessToItem)($id, $shared);
|
||||
|
||||
// Get folder
|
||||
$folder = Folder::whereUserId($shared->user_id)
|
||||
|
||||
Reference in New Issue
Block a user