Move all authenticated organiser-facing event sub-resource routes from
/events/{event}/... to /organisations/{organisation}/events/{event}/...
to enforce multi-tenancy at the routing layer.
Changes:
- Routes: restructured api.php to nest all event sub-resources under
the existing organisation prefix group
- Controllers: added Organisation parameter and VerifiesOrganisationEvent
trait to all 12 affected controllers (sections, time-slots, shifts,
persons, crowd-lists, locations, shift-assignments, registration-fields,
availabilities, field-values, section-preferences, stats)
- Tests: updated all 20 feature test files with new route paths
- Frontend: updated 8 API composables and 20 Vue components/pages
- API.md: updated documentation to reflect new route structure
Portal routes, public routes (volunteer-register), and invitation routes
remain unchanged as they operate without organisation context.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
154 lines
4.7 KiB
PHP
154 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\V1;
|
|
|
|
use App\Mail\RegistrationApprovedMail;
|
|
use App\Mail\RegistrationRejectedMail;
|
|
use App\Models\CrowdType;
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use App\Models\Person;
|
|
use App\Models\User;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class PersonApprovalEmailTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $orgAdmin;
|
|
private Organisation $organisation;
|
|
private Event $event;
|
|
private CrowdType $crowdType;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
|
|
$this->organisation = Organisation::factory()->create();
|
|
$this->orgAdmin = User::factory()->create();
|
|
$this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']);
|
|
|
|
$this->event = Event::factory()->create([
|
|
'organisation_id' => $this->organisation->id,
|
|
]);
|
|
|
|
$this->crowdType = CrowdType::factory()->systemType('VOLUNTEER')->create([
|
|
'organisation_id' => $this->organisation->id,
|
|
]);
|
|
}
|
|
|
|
public function test_approving_person_sends_approved_email(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$person = Person::factory()->create([
|
|
'event_id' => $this->event->id,
|
|
'crowd_type_id' => $this->crowdType->id,
|
|
'status' => 'pending',
|
|
'email' => 'volunteer@test.nl',
|
|
]);
|
|
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve");
|
|
|
|
$response->assertOk();
|
|
|
|
Mail::assertQueued(RegistrationApprovedMail::class, function ($mail) {
|
|
return $mail->hasTo('volunteer@test.nl');
|
|
});
|
|
}
|
|
|
|
public function test_rejecting_person_sends_rejected_email_with_reason(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$person = Person::factory()->create([
|
|
'event_id' => $this->event->id,
|
|
'crowd_type_id' => $this->crowdType->id,
|
|
'status' => 'pending',
|
|
'email' => 'volunteer@test.nl',
|
|
]);
|
|
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/reject", [
|
|
'reason' => 'Geen beschikbaarheid op de juiste momenten.',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
|
|
$this->assertDatabaseHas('persons', [
|
|
'id' => $person->id,
|
|
'status' => 'rejected',
|
|
]);
|
|
|
|
Mail::assertQueued(RegistrationRejectedMail::class, function ($mail) {
|
|
return $mail->hasTo('volunteer@test.nl')
|
|
&& $mail->reason === 'Geen beschikbaarheid op de juiste momenten.';
|
|
});
|
|
}
|
|
|
|
public function test_rejecting_person_sends_rejected_email_without_reason(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$person = Person::factory()->create([
|
|
'event_id' => $this->event->id,
|
|
'crowd_type_id' => $this->crowdType->id,
|
|
'status' => 'pending',
|
|
'email' => 'volunteer@test.nl',
|
|
]);
|
|
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/reject");
|
|
|
|
$response->assertOk();
|
|
|
|
Mail::assertQueued(RegistrationRejectedMail::class, function ($mail) {
|
|
return $mail->hasTo('volunteer@test.nl')
|
|
&& $mail->reason === null;
|
|
});
|
|
}
|
|
|
|
public function test_unauthenticated_cannot_approve(): void
|
|
{
|
|
$person = Person::factory()->create([
|
|
'event_id' => $this->event->id,
|
|
'crowd_type_id' => $this->crowdType->id,
|
|
'status' => 'pending',
|
|
]);
|
|
|
|
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve");
|
|
|
|
$response->assertStatus(401);
|
|
}
|
|
|
|
public function test_outsider_cannot_approve(): void
|
|
{
|
|
$outsider = User::factory()->create();
|
|
$otherOrg = Organisation::factory()->create();
|
|
$otherOrg->users()->attach($outsider, ['role' => 'org_admin']);
|
|
|
|
$person = Person::factory()->create([
|
|
'event_id' => $this->event->id,
|
|
'crowd_type_id' => $this->crowdType->id,
|
|
'status' => 'pending',
|
|
]);
|
|
|
|
Sanctum::actingAs($outsider);
|
|
|
|
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve");
|
|
|
|
$response->assertStatus(403);
|
|
}
|
|
}
|