Skip to content

Commit

Permalink
feat(profile): make thumbnail required if visible (#113)
Browse files Browse the repository at this point in the history
* feat(profile): make thumbnail required if visible

* feat(profile): move thumbnail to top

* fix(test): fake required thumbnail upload

* fix(workflow): call artisan test instead of phpunit

* fix(test): set thumbnail size & mime type

* fix(workflow): add gd extension for test
  • Loading branch information
Fenrikur authored Feb 15, 2025
1 parent d6c465d commit 57fcdd6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: "8.3"
extensions: gd
- uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: "mariadb-10.11"
Expand All @@ -37,4 +38,4 @@ jobs:
DB_DATABASE: dealers
DB_USERNAME: dealers
DB_PASSWORD: dealers
run: vendor/bin/phpunit
run: php artisan test
9 changes: 8 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Profile;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use ZipArchive;
Expand Down Expand Up @@ -91,10 +92,16 @@ public function update(Request $request, Profile $profile) {}

public function destroy(Profile $profile) {}

public static function getValidations()
public static function getValidations(Request $request)
{
return [
"profile_hidden" => [
'prohibited_unless:applicationType,share'
],
"image_thumbnail" => [
Rule::requiredIf(fn() => empty($request->user()?->application?->profile?->image_thumbnail) &&
($request->input('applicationType') === 'dealer' ||
($request->input('applicationType') === 'share' && !$request->has('profile_hidden')))),
'image',
'mimes:jpeg,png',
'max:1024',
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Requests/ApplicationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use App\Models\Application;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\RequiredIf;

class ApplicationRequest extends FormRequest
{
public function rules(): array
public function rules(Request $request): array
{
/**
* This is a multi request, it is accessed in the following circumstances
Expand Down Expand Up @@ -83,7 +84,7 @@ public function rules(): array
],
];

$profileValidations = ProfileController::getValidations();
$profileValidations = ProfileController::getValidations($request);

if (Carbon::parse(config('convention.reg_end_date'))->isFuture()) {
return array_merge($appValidations, $profileValidations);
Expand Down
104 changes: 52 additions & 52 deletions resources/views/forms/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,51 @@
</label>
@endif
<div id="dd-profile" class="mt-2">
<div class="row mb-3">
<div class="row mt-4">
<label for="image_thumbnail" class="col-sm-2 col-form-label fw-bold required">Thumb&shy;nail</label>
<div class="col-sm-10">
<input id="image_thumbnail" type="file"
class="form-control @error('image_thumbnail') is-invalid @enderror" name="image_thumbnail"
accept="image/jpeg, image/png"
onchange="document.getElementById('image_thumbnail_preview').src = window.URL.createObjectURL(this.files[0]); document.getElementById('image_thumbnail_preview_large').src = window.URL.createObjectURL(this.files[0]);">
<div id="image_thumbnailHelp" class="form-text">Upload an image to be shown next to your name in
the dealer list. This image should have a size of 60&times;60 pixels (max file size is 1 MB).
</div>
@error('image_thumbnail')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror

<img id='image_thumbnail_preview' class="mx-auto mb-2" data-bs-toggle="modal"
data-bs-target="#imageThumbnailModal"
src="{{ Storage::disk('public')->url("$profile?->image_thumbnail") }}" alt=""
style="height: 100px;">

<!-- Modal -->
<div class="modal fade" id="imageThumbnailModal" tabindex="-1"
aria-labelledby="imageThumbnailModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<img id='image_thumbnail_preview_large'class="mx-auto d-block w-100"
src="{{ Storage::disk('public')->url("$profile?->image_thumbnail") }}"
alt="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mb-1">
<label class="col-sm-2 col-form-label fw-bold">Attend&shy;ance</label>
</div>
<div class="row mb-1">
Expand Down Expand Up @@ -84,51 +128,7 @@
</div>
</div>
</div>
<div class="row mb-1 mt-5">
<label for="image_thumbnail" class="col-sm-2 col-form-label fw-bold">Thumb&shy;nail</label>
<div class="col-sm-10">
<input id="image_thumbnail" type="file"
class="form-control @error('image_thumbnail') is-invalid @enderror" name="image_thumbnail"
accept="image/jpeg, image/png"
onchange="document.getElementById('image_thumbnail_preview').src = window.URL.createObjectURL(this.files[0]); document.getElementById('image_thumbnail_preview_large').src = window.URL.createObjectURL(this.files[0]);">
<div id="image_thumbnailHelp" class="form-text">Upload an image to be shown next to your name in
the dealer list. This image should have a size of 60&times;60 pixels (max file size is 1 MB).
</div>
@error('image_thumbnail')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror

<img id='image_thumbnail_preview' class="mx-auto mb-5" data-bs-toggle="modal"
data-bs-target="#imageThumbnailModal"
src="{{ Storage::disk('public')->url("$profile?->image_thumbnail") }}" alt=""
style="height: 100px;">

<!-- Modal -->
<div class="modal fade" id="imageThumbnailModal" tabindex="-1"
aria-labelledby="imageThumbnailModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<img id='image_thumbnail_preview_large'class="mx-auto d-block w-100"
src="{{ Storage::disk('public')->url("$profile?->image_thumbnail") }}"
alt="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mb-3">
<div class="row mb-3 mt-5">
<label for="short_desc" class="col-sm-2 col-form-label fw-bold">Short De&shy;scrip&shy;tion</label>
<div class="col-sm-10">
<textarea rows="5" type="text" name="short_desc"
Expand All @@ -141,7 +141,7 @@ class="form-control @error('short_desc') is-invalid @enderror" id="short_desc">{
</div>
</div>
</div>
<div class="row mb-1 mt-5">
<div class="row mb-1 mt-3">
<label for="image_artist" class="col-sm-2 col-form-label fw-bold">Profile Header</label>
<div class="col-sm-10">

Expand All @@ -158,7 +158,7 @@ class="form-control @error('image_artist') is-invalid @enderror" name="image_art
<strong>{{ $message }}</strong>
</span>
@enderror
<img id='image_artist_preview' class="mx-auto mb-5" data-bs-toggle="modal"
<img id='image_artist_preview' class="mx-auto mb-2" data-bs-toggle="modal"
data-bs-target="#imageArtistModal"
src="{{ Storage::disk('public')->url("$profile?->image_artist") }}" alt=""
style="height: 100px;">
Expand Down Expand Up @@ -199,7 +199,7 @@ class="form-control @error('artist_desc') is-invalid @enderror" id="artist_desc"
</div>
</div>
</div>
<div class="row mb-1 mt-5">
<div class="row mb-1 mt-3">
<label for="image_art" class="col-sm-2 col-form-label fw-bold">Show&shy;case Image</label>
<div class="col-sm-10">
<input id="image_art" type="file"
Expand All @@ -217,7 +217,7 @@ class="form-control @error('image_art') is-invalid @enderror" name="image_art"
<strong>{{ $message }}</strong>
</span>
@enderror
<img id='image_art_preview' class="mx-auto mb-5" data-bs-toggle="modal"
<img id='image_art_preview' class="mx-auto mb-2" data-bs-toggle="modal"
data-bs-target="#imageArtModal"
src="{{ Storage::disk('public')->url("$profile?->image_art") }}" alt=""
style="height: 100px;">
Expand Down Expand Up @@ -274,7 +274,7 @@ class="form-control @error('art_preview_caption') is-invalid @enderror" id="art_
</div>
</div>
</div>
<div class="row mb-3">
<div class="row mb-3 mt-5">
<label for="profile_website" class="col-sm-2 col-form-label fw-bold">Web&shy;site</label>
<div class="col-sm-10">
<input type="text" name="profile_website" placeholder="https://yourprofile.example.com/itsme"
Expand Down Expand Up @@ -373,7 +373,7 @@ class="form-control @error('discord') is-invalid @enderror" id="discord"
</div>
</div>
</div>
<div class="row mb-3">
<div class="row mb-3 mt-5">
<label for="tweet" class="col-sm-2 col-form-label fw-bold">Ad&shy;ver&shy;tise&shy;ment
text</label>
<div class="col-sm-10">
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use App\Models\TableType;
use http\Client\Curl\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

/**
Expand All @@ -19,6 +21,11 @@ class ApplicationTest extends TestCase
{
use RefreshDatabase;

/**
* @var string
*/
private $thumbnailPath;

public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -55,6 +62,7 @@ public function test_application_creation_and_edit_normal()
"attends_thu" => "on",
"attends_fri" => "on",
"attends_sat" => "on",
"image_thumbnail" => UploadedFile::fake()->image('thumbnail.jpg', 60, 60)->size(100)->mimeType('image/jpeg'),
]);
$response->assertRedirect(route('dashboard'));
$this->assertDatabaseHas('applications', [
Expand Down Expand Up @@ -166,6 +174,7 @@ public function test_application_creation_edit_normal()
"attends_thu" => "on",
"attends_fri" => "on",
"attends_sat" => "on",
"image_thumbnail" => UploadedFile::fake()->image('thumbnail.jpg', 60, 60)->size(100)->mimeType('image/jpeg'),
]);
$response->assertRedirect(route('applications.edit'));
$this->assertDatabaseHas('applications', [
Expand Down

0 comments on commit 57fcdd6

Please sign in to comment.