feat: implement media download functionality and enhance case handling in reports
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Enums\ReportStatusEnum;
|
||||
use App\Enums\UserEnum;
|
||||
use App\Enums\WalletTransactionReasonEnum;
|
||||
use App\Models\Document;
|
||||
use App\Models\Medium;
|
||||
use App\Models\Report;
|
||||
use App\Models\User;
|
||||
use App\Services\FileStorageService;
|
||||
@@ -51,6 +52,14 @@ class CaseService
|
||||
|| $document->assignments()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
public function canAccessMedium(Medium $medium, User $user): bool
|
||||
{
|
||||
$documents = $medium->documents()->get()
|
||||
->merge($medium->reports()->with('document')->get()->pluck('document'));
|
||||
|
||||
return $documents->contains(fn ($document) => $this->canAccess($document, $user));
|
||||
}
|
||||
|
||||
public function canReport(Document $document, User $user): bool
|
||||
{
|
||||
return $this->isDoctor($user)
|
||||
@@ -162,7 +171,7 @@ class CaseService
|
||||
->orWhereHas('assignments', fn ($assignmentQuery) => $assignmentQuery->where('user_id', $user->id));
|
||||
}
|
||||
|
||||
protected function isDoctor(User $user): bool
|
||||
public function isDoctor(User $user): bool
|
||||
{
|
||||
return $user->level === UserEnum::Doctor->value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user