Skip to content
Open
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 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());
}
}
Loading