1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Ran a pass through image and attachment routes

Added some stronger types, formatting changes and simplifications along
the way.
This commit is contained in:
Dan Brown
2021-11-01 11:17:30 +00:00
parent c7fea8fe08
commit 4360da03d4
5 changed files with 28 additions and 53 deletions

View File

@ -68,6 +68,7 @@ class AttachmentController extends Controller
'file' => 'required|file',
]);
/** @var Attachment $attachment */
$attachment = Attachment::query()->findOrFail($attachmentId);
$this->checkOwnablePermission('view', $attachment->page);
$this->checkOwnablePermission('page-update', $attachment->page);
@ -86,11 +87,10 @@ class AttachmentController extends Controller
/**
* Get the update form for an attachment.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getUpdateForm(string $attachmentId)
{
/** @var Attachment $attachment */
$attachment = Attachment::query()->findOrFail($attachmentId);
$this->checkOwnablePermission('page-update', $attachment->page);
@ -173,6 +173,7 @@ class AttachmentController extends Controller
/**
* Get the attachments for a specific page.
* @throws NotFoundException
*/
public function listForPage(int $pageId)
{

View File

@ -67,13 +67,12 @@ class DrawioImageController extends Controller
public function getAsBase64($id)
{
$image = $this->imageRepo->getById($id);
$page = $image->getPage();
if ($image === null || $image->type !== 'drawio' || !userCan('page-view', $page)) {
if (is_null($image) || $image->type !== 'drawio' || !userCan('page-view', $image->getPage())) {
return $this->jsonError('Image data could not be found');
}
$imageData = $this->imageRepo->getImageData($image);
if ($imageData === null) {
if (is_null($imageData)) {
return $this->jsonError('Image data could not be found');
}