@@ -148,7 +148,7 @@ public function getImageStream(Image $image): mixed
148148 }
149149
150150 /**
151- * Destroy an image along with its revisions, thumbnails and remaining folders.
151+ * Destroy an image along with its revisions, thumbnails, and remaining folders.
152152 *
153153 * @throws Exception
154154 */
@@ -252,33 +252,48 @@ public function pathAccessibleInLocalSecure(string $imagePath): bool
252252 {
253253 $ disk = $ this ->storage ->getDisk ('gallery ' );
254254
255+ return $ disk ->usingSecureImages () && $ this ->pathAccessible ($ imagePath );
256+ }
257+
258+ /**
259+ * Check if the given path exists and is accessible depending on the current settings.
260+ */
261+ public function pathAccessible (string $ imagePath ): bool
262+ {
255263 if ($ this ->storage ->usingSecureRestrictedImages () && !$ this ->checkUserHasAccessToRelationOfImageAtPath ($ imagePath )) {
256264 return false ;
257265 }
258266
259- // Check local_secure is active
260- return $ disk ->usingSecureImages ()
261- // Check the image file exists
262- && $ disk ->exists ($ imagePath )
263- // Check the file is likely an image file
264- && str_starts_with ($ disk ->mimeType ($ imagePath ), 'image/ ' );
267+ if ($ this ->storage ->usingSecureImages () && user ()->isGuest ()) {
268+ return false ;
269+ }
270+
271+ return $ this ->imageFileExists ($ imagePath , 'gallery ' );
265272 }
266273
267274 /**
268- * Check if the given path exists and is accessible depending on the current settings .
275+ * Check if the given image should be accessible to the current user .
269276 */
270- public function pathAccessible ( string $ imagePath ): bool
277+ public function imageAccessible ( Image $ image ): bool
271278 {
272- $ disk = $ this ->storage ->getDisk ('gallery ' );
279+ if ($ this ->storage ->usingSecureRestrictedImages () && !$ this ->checkUserHasAccessToRelationOfImage ($ image )) {
280+ return false ;
281+ }
273282
274- if ($ this ->storage ->usingSecureRestrictedImages () && ! $ this -> checkUserHasAccessToRelationOfImageAtPath ( $ imagePath )) {
283+ if ($ this ->storage ->usingSecureImages () && user ()-> isGuest ( )) {
275284 return false ;
276285 }
277286
278- // Check local_secure is active
279- return $ disk ->exists ($ imagePath )
280- // Check the file is likely an image file
281- && str_starts_with ($ disk ->mimeType ($ imagePath ), 'image/ ' );
287+ return $ this ->imageFileExists ($ image ->path , $ image ->type );
288+ }
289+
290+ /**
291+ * Check if the given image path exists for the given image type and that it is likely an image file.
292+ */
293+ protected function imageFileExists (string $ imagePath , string $ imageType ): bool
294+ {
295+ $ disk = $ this ->storage ->getDisk ($ imageType );
296+ return $ disk ->exists ($ imagePath ) && str_starts_with ($ disk ->mimeType ($ imagePath ), 'image/ ' );
282297 }
283298
284299 /**
@@ -307,6 +322,11 @@ protected function checkUserHasAccessToRelationOfImageAtPath(string $path): bool
307322 return false ;
308323 }
309324
325+ return $ this ->checkUserHasAccessToRelationOfImage ($ image );
326+ }
327+
328+ protected function checkUserHasAccessToRelationOfImage (Image $ image ): bool
329+ {
310330 $ imageType = $ image ->type ;
311331
312332 // Allow user or system (logo) images
0 commit comments