mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 19:10:40 +00:00
- gate implementation
- protected shared view fix
This commit is contained in:
@@ -86,7 +86,7 @@ class UploadFileAction
|
||||
return UserFile::create([
|
||||
'mimetype' => get_file_type_from_mimetype($file_mimetype),
|
||||
'type' => get_file_type($file_mimetype),
|
||||
'folder_id' => $request->input('folder_id'),
|
||||
'parent_id' => $request->input('parent_id'),
|
||||
'metadata' => $metadata,
|
||||
'name' => $request->input('filename'),
|
||||
'basename' => $disk_file_name,
|
||||
|
||||
@@ -23,7 +23,7 @@ class UploadFileController extends Controller
|
||||
public function __invoke(
|
||||
UploadRequest $request,
|
||||
): Response | array {
|
||||
if (is_demo_account('howdy@hi5ve.digital')) {
|
||||
if (is_demo_account()) {
|
||||
return ($this->fakeUploadFile)($request);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace Domain\Files\Controllers;
|
||||
|
||||
use Domain\Files\Models\File;
|
||||
use Gate;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Files\Resources\FileResource;
|
||||
@@ -12,22 +13,16 @@ use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
*/
|
||||
class VisitorShowFileController
|
||||
{
|
||||
public function __construct(
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
Share $shared
|
||||
): Response {
|
||||
// Check ability to access protected share files
|
||||
($this->protectShareRecord)($shared);
|
||||
|
||||
// Get file
|
||||
$file = File::whereUserId($shared->user_id)
|
||||
->whereId($shared->item_id)
|
||||
->firstOrFail();
|
||||
|
||||
Gate::authorize('can-visit', [$file, $shared]);
|
||||
|
||||
// Set access urls
|
||||
$file->setPublicUrl($shared->token);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class VisitorUploadFileController extends Controller
|
||||
UploadRequest $request,
|
||||
Share $shared,
|
||||
): Response | array {
|
||||
if (is_demo_account($shared->user->email)) {
|
||||
if (is_demo_account()) {
|
||||
return ($this->fakeUploadFile)($request);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class VisitorUploadFileController extends Controller
|
||||
}
|
||||
|
||||
// Check access to requested directory
|
||||
($this->verifyAccessToItem)($request->input('folder_id'), $shared);
|
||||
($this->verifyAccessToItem)($request->input('parent_id'), $shared);
|
||||
|
||||
// Return new uploaded file
|
||||
$new_file = ($this->uploadFile)($request, $shared);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Domain\Files\Models;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Domain\Sharing\Models\Share;
|
||||
@@ -23,7 +22,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
* @method static where(string $string, string $user_id)
|
||||
* @property string id
|
||||
* @property string user_id
|
||||
* @property string folder_id
|
||||
* @property string parent_id
|
||||
* @property string thumbnail
|
||||
* @property string filesize
|
||||
* @property string type
|
||||
@@ -148,7 +147,16 @@ class File extends Model
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Folder::class, 'folder_id', 'id');
|
||||
return $this->belongsTo(Folder::class, 'parent_id', 'id');
|
||||
}
|
||||
|
||||
public function getLatestParent()
|
||||
{
|
||||
if ($this->parent) {
|
||||
return $this->parent->getLatestParent();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shared(): HasOne
|
||||
@@ -159,7 +167,8 @@ class File extends Model
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$name = mb_convert_encoding(
|
||||
mb_strtolower($this->name, 'UTF-8'), 'UTF-8'
|
||||
mb_strtolower($this->name, 'UTF-8'),
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
$trigram = (new TNTIndexer)
|
||||
|
||||
@@ -25,7 +25,7 @@ class UploadRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'filename' => 'required|string',
|
||||
'folder_id' => 'nullable|uuid',
|
||||
'parent_id' => 'nullable|uuid',
|
||||
'is_last' => 'sometimes|string',
|
||||
'file' => ['required', 'file', new DisabledMimetypes],
|
||||
];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace Domain\Files\Resources;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Carbon\Carbon;
|
||||
use ByteUnits\Metric;
|
||||
use Domain\Sharing\Resources\ShareResource;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -25,17 +25,17 @@ class FileResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'attributes' => [
|
||||
'filesize' => $fileSize,
|
||||
'name' => $this->name,
|
||||
'basename' => $this->basename,
|
||||
'mimetype' => $this->mimetype,
|
||||
'file_url' => $this->file_url,
|
||||
'thumbnail' => $this->thumbnail,
|
||||
'metadata' => $this->metadata,
|
||||
'folder_id' => $this->folder_id,
|
||||
'updated_at' => $this->updated_at,
|
||||
'filesize' => $fileSize,
|
||||
'name' => $this->name,
|
||||
'basename' => $this->basename,
|
||||
'mimetype' => $this->mimetype,
|
||||
'file_url' => $this->file_url,
|
||||
'thumbnail' => $this->thumbnail,
|
||||
'metadata' => $this->metadata,
|
||||
'parent_id' => $this->parent_id,
|
||||
'updated_at' => $this->updated_at,
|
||||
'created_at' => Carbon::parse($this->created_at)->diffForHumans(),
|
||||
'deleted_at' => $this->deleted_at,
|
||||
'deleted_at' => $this->deleted_at,
|
||||
/*'updated_at' => format_date(
|
||||
set_time_by_user_timezone($this->updated_at), __t('time')
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user