Skip to content

Commit 8429cc9

Browse files
committed
Merge branch 'development' into release
2 parents fef61f0 + 47f12cc commit 8429cc9

File tree

19 files changed

+213
-118
lines changed

19 files changed

+213
-118
lines changed

.github/translators.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,4 @@ MrCharlesIII :: Arabic
511511
David Olsen (dawin) :: Danish
512512
ltnzr :: French
513513
Frank Holler (holler.frank) :: German; German Informal
514+
Korab Arifi (korabidev) :: Albanian

.github/workflows/test-migrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-24.04
1717
strategy:
1818
matrix:
19-
php: ['8.2', '8.3', '8.4']
19+
php: ['8.2', '8.3', '8.4', '8.5']
2020
steps:
2121
- uses: actions/checkout@v4
2222

.github/workflows/test-php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-24.04
1717
strategy:
1818
matrix:
19-
php: ['8.2', '8.3', '8.4']
19+
php: ['8.2', '8.3', '8.4', '8.5']
2020
steps:
2121
- uses: actions/checkout@v4
2222

app/Exports/ZipExports/ZipExportReferences.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BookStack\Permissions\Permission;
1616
use BookStack\Uploads\Attachment;
1717
use BookStack\Uploads\Image;
18+
use BookStack\Uploads\ImageService;
1819

1920
class ZipExportReferences
2021
{
@@ -33,6 +34,7 @@ class ZipExportReferences
3334

3435
public function __construct(
3536
protected ZipReferenceParser $parser,
37+
protected ImageService $imageService,
3638
) {
3739
}
3840

@@ -133,17 +135,25 @@ protected function handleModelReference(Model $model, ZipExportModel $exportMode
133135
return "[[bsexport:image:{$model->id}]]";
134136
}
135137

136-
// Find and include images if in visibility
138+
// Get the page which we'll reference this image upon
137139
$page = $model->getPage();
138-
$pageExportModel = $this->pages[$page->id] ?? ($exportModel instanceof ZipExportPage ? $exportModel : null);
139-
if (isset($this->images[$model->id]) || ($page && $pageExportModel && userCan(Permission::PageView, $page))) {
140+
$pageExportModel = null;
141+
if ($page && isset($this->pages[$page->id])) {
142+
$pageExportModel = $this->pages[$page->id];
143+
} elseif ($exportModel instanceof ZipExportPage) {
144+
$pageExportModel = $exportModel;
145+
}
146+
147+
// Add the image to the export if it's accessible or just return the existing reference if already added
148+
if (isset($this->images[$model->id]) || ($pageExportModel && $this->imageService->imageAccessible($model))) {
140149
if (!isset($this->images[$model->id])) {
141150
$exportImage = ZipExportImage::fromModel($model, $files);
142151
$this->images[$model->id] = $exportImage;
143152
$pageExportModel->images[] = $exportImage;
144153
}
145154
return "[[bsexport:image:{$model->id}]]";
146155
}
156+
147157
return null;
148158
}
149159

app/Search/SearchIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function generateTermScoreMapFromText(string $text, float $scoreAdjust
126126
$termMap = $this->textToTermCountMap($text);
127127

128128
foreach ($termMap as $term => $count) {
129-
$termMap[$term] = floor($count * $scoreAdjustment);
129+
$termMap[$term] = intval($count * $scoreAdjustment);
130130
}
131131

132132
return $termMap;

app/Uploads/Image.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
use Illuminate\Database\Eloquent\Relations\HasMany;
1414

1515
/**
16-
* @property int $id
17-
* @property string $name
18-
* @property string $url
19-
* @property string $path
20-
* @property string $type
21-
* @property int $uploaded_to
22-
* @property int $created_by
23-
* @property int $updated_by
16+
* @property int $id
17+
* @property string $name
18+
* @property string $url
19+
* @property string $path
20+
* @property string $type
21+
* @property int|null $uploaded_to
22+
* @property int $created_by
23+
* @property int $updated_by
2424
*/
2525
class Image extends Model implements OwnableInterface
2626
{

app/Uploads/ImageService.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/Uploads/ImageStorage.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public function usingSecureRestrictedImages(): bool
3434
return config('filesystems.images') === 'local_secure_restricted';
3535
}
3636

37+
/**
38+
* Check if "local secure" (Fetched behind auth, either with or without permissions enforced)
39+
* is currently active in the instance.
40+
*/
41+
public function usingSecureImages(): bool
42+
{
43+
return config('filesystems.images') === 'local_secure' || $this->usingSecureRestrictedImages();
44+
}
45+
3746
/**
3847
* Clean up an image file name to be both URL and storage safe.
3948
*/

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"@php artisan view:clear"
9494
],
9595
"refresh-test-database": [
96+
"@putenv APP_TIMEZONE=UTC",
9697
"@php artisan migrate:refresh --database=mysql_testing",
9798
"@php artisan db:seed --class=DummyContentSeeder --database=mysql_testing"
9899
]

0 commit comments

Comments
 (0)