]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/ImageRepo.php
Guest create page: name field autofocus
[bookstack] / app / Uploads / ImageRepo.php
index 494ff3ac0d02c703d06be0a8c58785b3132e0520..8770402adbdb0abe465a9fb866bedb932bf3cf32 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace BookStack\Uploads;
 
-use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Auth\Permissions\PermissionApplicator;
 use BookStack\Entities\Models\Page;
 use BookStack\Exceptions\ImageUploadException;
 use Exception;
@@ -11,16 +11,16 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
 
 class ImageRepo
 {
-    protected $imageService;
-    protected $restrictionService;
+    protected ImageService $imageService;
+    protected PermissionApplicator $permissions;
 
     /**
      * ImageRepo constructor.
      */
-    public function __construct(ImageService $imageService, PermissionService $permissionService)
+    public function __construct(ImageService $imageService, PermissionApplicator $permissions)
     {
         $this->imageService = $imageService;
-        $this->restrictionService = $permissionService;
+        $this->permissions = $permissions;
     }
 
     /**
@@ -74,7 +74,7 @@ class ImageRepo
         }
 
         // Filter by page access
-        $imageQuery = $this->restrictionService->filterRelatedEntity(Page::class, $imageQuery, 'images', 'uploaded_to');
+        $imageQuery = $this->permissions->restrictPageRelationQuery($imageQuery, 'images', 'uploaded_to');
 
         if ($whereClause !== null) {
             $imageQuery = $imageQuery->where($whereClause);
@@ -103,7 +103,10 @@ class ImageRepo
                 if ($filterType === 'page') {
                     $query->where('uploaded_to', '=', $contextPage->id);
                 } elseif ($filterType === 'book') {
-                    $validPageIds = $contextPage->book->pages()->visible()->pluck('id')->toArray();
+                    $validPageIds = $contextPage->book->pages()
+                        ->scopes('visible')
+                        ->pluck('id')
+                        ->toArray();
                     $query->whereIn('uploaded_to', $validPageIds);
                 }
             };