mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
Guardian and FileManagerService.php refactored
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Folder;
|
||||
use DB;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class HelperService
|
||||
@@ -30,4 +32,35 @@ class HelperService
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check access to requested directory
|
||||
*
|
||||
* @param integer|array $requested_id
|
||||
* @param string $shared Shared record detail
|
||||
*/
|
||||
public function check_item_access($requested_id, $shared)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user