Guardian and FileManagerService.php refactored

This commit is contained in:
Peter Papp
2021-03-14 12:54:34 +01:00
parent bb469f2520
commit 0364e73c60
6 changed files with 135 additions and 123 deletions

View File

@@ -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);
}
}
}