- public sharing refactored part 1

This commit is contained in:
Peter Papp
2021-03-19 07:27:15 +01:00
parent 816c8c3e07
commit db9900fcfb
27 changed files with 563 additions and 435 deletions
@@ -27,12 +27,10 @@ class BrowseShareController extends Controller
* @param Share $shared
* @return Collection
*/
public function get_public_folders($id, Share $shared)
public function browse_folder($id, Share $shared)
{
// Abort if folder is protected
if ($shared->is_protected) {
abort(403, "Sorry, you don't have permission");
}
// Check ability to access protected share record
$this->helper->check_protected_share_record($shared);
// Check if user can get directory
$this->helper->check_item_access($id, $shared);
@@ -57,12 +55,10 @@ class BrowseShareController extends Controller
* @param Share $shared
* @return Collection
*/
public function search_public(Request $request, Share $shared)
public function search(Request $request, Share $shared)
{
// Abort if folder is protected
if ($shared->is_protected) {
abort(403, "Sorry, you don't have permission");
}
// Check ability to access protected share record
$this->helper->check_protected_share_record($shared);
// Search files id db
$searched_files = File::search($request->input('query'))
@@ -108,8 +104,11 @@ class BrowseShareController extends Controller
* @param Share $shared
* @return array
*/
public function get_public_navigation_tree(Share $shared)
public function navigation_tree(Share $shared)
{
// Check ability to access protected share record
$this->helper->check_protected_share_record($shared);
// Check if user can get directory
$this->helper->check_item_access($shared->item_id, $shared);
@@ -54,15 +54,14 @@ class FileSharedAccessController extends Controller
* Get file public
*
* @param $filename
* @param $permission
* @param Share $shared
* @return mixed
*/
public function get_file_public($filename, Share $shared)
public function get_file_public($filename, $permission, Share $shared)
{
// Abort if shared is protected
if ($shared->is_protected) {
abort(403, "Sorry, you don't have permission");
}
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared, $permission);
// Get file record
$file = UserFile::where('user_id', $shared->user_id)
@@ -86,15 +85,14 @@ class FileSharedAccessController extends Controller
* Get public image thumbnail
*
* @param $filename
* @param $permission
* @param Share $shared
* @return mixed
*/
public function get_thumbnail_public($filename, Share $shared)
public function get_thumbnail_public($filename, $permission, Share $shared)
{
// Abort if thumbnail is protected
if ($shared->is_protected) {
abort(403, "Sorry, you don't have permission");
}
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared, $permission);
// Get file record
$file = UserFile::where('user_id', $shared->user_id)
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Sharing;
use App\Http\Controllers\Controller;
use App\Http\Requests\Share\AuthenticateShareRequest;
use App\Http\Resources\FileResource;
use App\Http\Resources\ShareResource;
use App\Models\Share;
use App\Models\Setting;
@@ -118,20 +119,17 @@ class ServeSharedController extends Controller
*/
public function file_public(Share $shared)
{
// Abort if file is protected
if ($shared->is_protected) {
abort(403, "Sorry, you don't have permission");
}
// Check ability to access protected share files
$this->helper->check_protected_share_record($shared);
// Get file
$file = File::where('user_id', $shared->user_id)
->where('id', $shared->item_id)
->firstOrFail(['name', 'basename', 'thumbnail', 'type', 'filesize', 'mimetype']);
->firstOrFail();
// Set urls
// Set access urls
$file->setPublicUrl($shared->token);
// Return record
return $file;
return response(new FileResource($file), 200);
}
}