From 5cd56f63ff7b31abe0901ebea8931a70a5e4994c Mon Sep 17 00:00:00 2001 From: TBK Date: Wed, 4 Mar 2020 00:08:01 +0100 Subject: [PATCH 1/3] Change check to verify that request is present and contains a file --- app/Http/Controllers/SettingController.php | 2 +- app/Http/Controllers/UserController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 00dd60ac7..9c51ef4af 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -57,7 +57,7 @@ class SettingController extends Controller } // Update logo image if set - if ($request->has('app_logo')) { + if ($request->hasFile('app_logo')) { $logoFile = $request->file('app_logo'); $this->imageRepo->destroyByType('system'); $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 207466f38..c91b7678c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -191,7 +191,7 @@ class UserController extends Controller } // Save profile image if in request - if ($request->has('profile_image')) { + if ($request->hasFile('profile_image')) { $imageUpload = $request->file('profile_image'); $this->imageRepo->destroyImage($user->avatar); $image = $this->imageRepo->saveNew($imageUpload, 'user', $user->id); From d3737d5a879ca7284ff7e6170264cfe99ed2a4b5 Mon Sep 17 00:00:00 2001 From: TBK Date: Wed, 4 Mar 2020 00:06:30 +0100 Subject: [PATCH 2/3] Remove redundant getImageValidationRules method --- app/Http/Controllers/BookshelfController.php | 2 +- app/Http/Controllers/Images/GalleryImageController.php | 2 +- app/Http/Controllers/SettingController.php | 2 +- app/Http/Controllers/UserController.php | 2 +- app/Uploads/ImageRepo.php | 8 -------- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index c882ca7c3..ad5967c7c 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -146,7 +146,7 @@ class BookshelfController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->imageRepo->getImageValidationRules(), + 'image' => $this->getImageValidationRules(), ]); diff --git a/app/Http/Controllers/Images/GalleryImageController.php b/app/Http/Controllers/Images/GalleryImageController.php index fd52ffd3f..e506215ca 100644 --- a/app/Http/Controllers/Images/GalleryImageController.php +++ b/app/Http/Controllers/Images/GalleryImageController.php @@ -48,7 +48,7 @@ class GalleryImageController extends Controller { $this->checkPermission('image-create-all'); $this->validate($request, [ - 'file' => $this->imageRepo->getImageValidationRules() + 'file' => $this->getImageValidationRules() ]); try { diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 9c51ef4af..3ecdb9cdc 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -44,7 +44,7 @@ class SettingController extends Controller $this->preventAccessInDemoMode(); $this->checkPermission('settings-manage'); $this->validate($request, [ - 'app_logo' => $this->imageRepo->getImageValidationRules(), + 'app_logo' => $this->getImageValidationRules(), ]); // Cycles through posted settings and update them diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c91b7678c..f6465ca1e 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -155,7 +155,7 @@ class UserController extends Controller 'password' => 'min:6|required_with:password_confirm', 'password-confirm' => 'same:password|required_with:password', 'setting' => 'array', - 'profile_image' => $this->imageRepo->getImageValidationRules(), + 'profile_image' => $this->getImageValidationRules(), ]); $user = $this->userRepo->getById($id); diff --git a/app/Uploads/ImageRepo.php b/app/Uploads/ImageRepo.php index 01b65f882..981c04673 100644 --- a/app/Uploads/ImageRepo.php +++ b/app/Uploads/ImageRepo.php @@ -219,12 +219,4 @@ class ImageRepo return null; } } - - /** - * Get the validation rules for image files. - */ - public function getImageValidationRules(): string - { - return 'image_extension|no_double_extension|mimes:jpeg,png,gif,bmp,webp,tiff'; - } } From 57f587a78b47b23fc646b621628a834833826d69 Mon Sep 17 00:00:00 2001 From: TBK Date: Wed, 4 Mar 2020 00:05:47 +0100 Subject: [PATCH 3/3] Allow book, shelf, settings & profile form input validation to skip image --- app/Http/Controllers/BookController.php | 4 ++-- app/Http/Controllers/BookshelfController.php | 4 ++-- app/Http/Controllers/SettingController.php | 2 +- app/Http/Controllers/UserController.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index e7d788d91..bddfe3f6d 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -86,7 +86,7 @@ class BookController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); $bookshelf = null; @@ -153,7 +153,7 @@ class BookController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); $book = $this->bookRepo->update($book, $request->all()); diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index ad5967c7c..a0e9b7199 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -85,7 +85,7 @@ class BookshelfController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); $bookIds = explode(',', $request->get('books', '')); @@ -146,7 +146,7 @@ class BookshelfController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 3ecdb9cdc..feb6521f3 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -44,7 +44,7 @@ class SettingController extends Controller $this->preventAccessInDemoMode(); $this->checkPermission('settings-manage'); $this->validate($request, [ - 'app_logo' => $this->getImageValidationRules(), + 'app_logo' => 'nullable|' . $this->getImageValidationRules(), ]); // Cycles through posted settings and update them diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f6465ca1e..55a4610bc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -155,7 +155,7 @@ class UserController extends Controller 'password' => 'min:6|required_with:password_confirm', 'password-confirm' => 'same:password|required_with:password', 'setting' => 'array', - 'profile_image' => $this->getImageValidationRules(), + 'profile_image' => 'nullable|' . $this->getImageValidationRules(), ]); $user = $this->userRepo->getById($id);