]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/AttachmentController.php
Update .env.example
[bookstack] / app / Http / Controllers / AttachmentController.php
index 715cd2bd8af66565c1c700fe8ffe458b8a0c85c3..ea41278aebc0082ef93054985b28eb4c1cff3db2 100644 (file)
@@ -2,8 +2,8 @@
 
 use BookStack\Exceptions\FileUploadException;
 use BookStack\Attachment;
+use BookStack\Exceptions\NotFoundException;
 use BookStack\Repos\EntityRepo;
-use BookStack\Repos\PageRepo;
 use BookStack\Services\AttachmentService;
 use Illuminate\Http\Request;
 
@@ -11,21 +11,18 @@ class AttachmentController extends Controller
 {
     protected $attachmentService;
     protected $attachment;
-    protected $pageRepo;
     protected $entityRepo;
 
     /**
      * AttachmentController constructor.
      * @param AttachmentService $attachmentService
      * @param Attachment $attachment
-     * @param PageRepo $pageRepo
+     * @param EntityRepo $entityRepo
      */
-    public function __construct(AttachmentService $attachmentService, Attachment $attachment, EntityRepo $entityRepo, PageRepo $pageRepo)
+    public function __construct(AttachmentService $attachmentService, Attachment $attachment, EntityRepo $entityRepo)
     {
         $this->attachmentService = $attachmentService;
         $this->attachment = $attachment;
-        // TODO - Remove this
-        $this->pageRepo = $pageRepo;
         $this->entityRepo = $entityRepo;
         parent::__construct();
     }
@@ -186,11 +183,16 @@ class AttachmentController extends Controller
      * Get an attachment from storage.
      * @param $attachmentId
      * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Symfony\Component\HttpFoundation\Response
+     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
      */
     public function get($attachmentId)
     {
         $attachment = $this->attachment->findOrFail($attachmentId);
         $page = $this->entityRepo->getById('page', $attachment->uploaded_to);
+        if ($page === null) {
+            throw new NotFoundException(trans('errors.attachment_not_found'));
+        }
+
         $this->checkOwnablePermission('page-view', $page);
 
         if ($attachment->external) {
@@ -208,6 +210,7 @@ class AttachmentController extends Controller
      * Delete a specific attachment in the system.
      * @param $attachmentId
      * @return mixed
+     * @throws \Exception
      */
     public function delete($attachmentId)
     {