From bb5498bb5187c24ccce92a1fe0899ea309bbd69d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 23 Jul 2024 13:35:22 +0100 Subject: [PATCH] Allows uploads by all --- app/Livewire/Questions/Create.php | 6 +-- .../views/livewire/questions/create.blade.php | 54 +++++++++---------- .../upload-profile-photo-form.blade.php | 3 +- tests/Unit/Livewire/Questions/CreateTest.php | 18 +++---- 4 files changed, 39 insertions(+), 42 deletions(-) diff --git a/app/Livewire/Questions/Create.php b/app/Livewire/Questions/Create.php index dcb07f6cb..7d1a23843 100644 --- a/app/Livewire/Questions/Create.php +++ b/app/Livewire/Questions/Create.php @@ -7,7 +7,6 @@ use App\Models\User; use App\Rules\MaxUploads; use App\Rules\NoBlankCharacters; -use App\Rules\VerifiedOnly; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; @@ -35,11 +34,11 @@ final class Create extends Component #[Locked] public int $uploadLimit = 1; - #[Locked] /** * Max file size allowed. */ - public int $maxFileSize = 2048; + #[Locked] + public int $maxFileSize = 1024 * 8; /** * The component's user ID. @@ -90,7 +89,6 @@ public function runImageValidation(): void rules: [ 'images' => [ 'bail', - new VerifiedOnly(), new MaxUploads($this->uploadLimit), ], 'images.*' => [ diff --git a/resources/views/livewire/questions/create.blade.php b/resources/views/livewire/questions/create.blade.php index 6e7a2c939..8240210f4 100644 --- a/resources/views/livewire/questions/create.blade.php +++ b/resources/views/livewire/questions/create.blade.php @@ -24,35 +24,33 @@ class="relative group/menu"> x-ref="content" /> - @if (auth()->user()?->is_verified || auth()->user()?->is_company_verified) - - - + + + -
- -
- @endif +
+ +

/ {{ $this->maxContentLength}}

diff --git a/resources/views/profile/partials/upload-profile-photo-form.blade.php b/resources/views/profile/partials/upload-profile-photo-form.blade.php index 05f97aeb8..b93e29b95 100644 --- a/resources/views/profile/partials/upload-profile-photo-form.blade.php +++ b/resources/views/profile/partials/upload-profile-photo-form.blade.php @@ -2,7 +2,8 @@ avatar: null, errors: @json($errors->get('avatar')), checkFileSize(target) { - const maxFileSize = 2 * 1024 * 1024; + const maxFileSize = 8 * 1024 * 1024; + if ((target.files[0]?.size ?? 0) > maxFileSize) { this.errors = ["The avatar may not be greater than 2MB."]; target.value = null; diff --git a/tests/Unit/Livewire/Questions/CreateTest.php b/tests/Unit/Livewire/Questions/CreateTest.php index 8d1aa92e9..057cb5de3 100644 --- a/tests/Unit/Livewire/Questions/CreateTest.php +++ b/tests/Unit/Livewire/Questions/CreateTest.php @@ -491,11 +491,11 @@ 'toId' => $user->id, ]); - expect($component->maxFileSize)->toBe(1024 * 2) + expect($component->maxFileSize)->toBe(1024 * 8) ->and($component->uploadLimit)->toBe(1); }); -test('only verified users can upload images', function () { +test('non verified users can upload images', function () { $user = User::factory()->unverified()->create(); $component = Livewire::actingAs($user)->test(Create::class, [ @@ -505,9 +505,7 @@ $component->set('images', [UploadedFile::fake()->image('test.jpg')]); $component->call('uploadImages'); - $component->assertHasErrors([ - 'images' => 'This action is only available to verified users. Get verified in your profile settings.', - ]); + $component->assertHasNoErrors(); }); test('company verified users can upload images', function () { @@ -583,19 +581,21 @@ 'is_verified' => true, ]); - $maxFileSize = 1024 * 2; + $maxFileSize = 1024 * 8; $component = Livewire::actingAs($user)->test(Create::class, [ 'toId' => $user->id, ]); - $largeFile = UploadedFile::fake()->image('test.jpg')->size(1024 * 5); + $largeFile = UploadedFile::fake()->image('test.jpg')->size(1024 * 16); $component->set('images', [$largeFile]); $component->call('runImageValidation'); - expect($component->get('images'))->toBeArray() - ->and($component->get('images'))->not()->toContain($largeFile); + expect($component->get('images')) + ->toBeArray() + ->and($component->get('images')) + ->not()->toContain($largeFile); $component->assertHasErrors([ 'images.0' => "The image may not be greater than {$maxFileSize} kilobytes.",