mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Tools;
|
|
|
|
use App;
|
|
use App\Models\Folder;
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
|
class Guardian
|
|
{
|
|
/**
|
|
* Check access to requested directory
|
|
*
|
|
* @param integer|array $requested_id
|
|
* @param string $shared Shared record detail
|
|
*/
|
|
public static 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);
|
|
}
|
|
}
|
|
} |