Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ public function approve()
{
$data = ['status' => 'APPROVED', 'approved_by' => auth()->user()->id];

// Imported/Nova-created events can reach approval without a code, and the email prints it verbatim.
if (empty($this->codeweek_for_all_participation_code)) {
$data['codeweek_for_all_participation_code'] = 'cw'.now()->format('y').'-'.Str::random(5);
}

$this->update($data);

if (! empty($this->user_email)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function validator(array $data): \Illuminate\Contracts\Validation\Vali
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => ['required', 'string', Password::defaults()],
'password' => ['required', 'string', 'confirmed', Password::defaults()],
'privacy' => 'required',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class="border-2 border-solid border-dark-blue-200 w-full rounded-full h-12 px-4
<password-field id="password_confirmation" name="password_confirmation" required />
</div>
<div class="text-error-200 font-semibold mt-2">
@component('components.validation-errors', ['field'=>'password'])@endcomponent
@component('components.validation-errors', ['field'=>'password_confirmation'])@endcomponent
</div>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/event/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
@endif

<section>
<img class="w-full h-auto lg:h-[520px] object-cover" src="{{$event->picture_detail_path()}}"/>
<img class="w-full h-auto max-h-[500px] object-cover" src="{{$event->picture_detail_path()}}"/>
</section>

@canany(['edit', 'delete'], $event)
Expand Down
27 changes: 27 additions & 0 deletions tests/Feature/ApproveEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,31 @@ public function ambassadors_of_right_country_can_see_the_approve_banner(): void
->assertSee('moderate-event');

}

#[Test]
public function approving_event_without_participation_code_generates_one_for_the_email(): void
{
$this->withExceptionHandling();

Mail::fake();

$superadmin = \App\User::factory()->create();
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$event = \App\Event::factory()->create([
'status' => 'PENDING',
'user_email' => 'foo@bar.com',
'codeweek_for_all_participation_code' => null,
]);

$event->approve();

$event = $event->fresh();
$code = (string) $event->codeweek_for_all_participation_code;

$this->assertMatchesRegularExpression('/^cw\d{2}-[A-Za-z0-9]+$/', $code);
$this->assertStringContainsString($code, (new EventApproved($event, $event->owner))->render());
}
}
25 changes: 25 additions & 0 deletions tests/Feature/Auth/RegisterPasswordConfirmationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Tests\Feature\Auth;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

final class RegisterPasswordConfirmationTest extends TestCase
{
use RefreshDatabase;

public function test_registration_rejects_mismatched_password_confirmation(): void
{
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'mismatch@example.com',
'password' => 'Xq7!vT2#Lm9@',
'password_confirmation' => 'Xq7!vT2#Lm9@Z',
'privacy' => '1',
]);

$response->assertSessionHasErrors('password');
$this->assertDatabaseMissing('users', ['email' => 'mismatch@example.com']);
}
}
Loading