namespace BookStack\Uploads;
-use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Entities\Models\Page;
use BookStack\Exceptions\ImageUploadException;
use Exception;
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;
}
/**
}
// 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);
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);
}
};