feat: complete email infrastructure with queue, templates, logging, and API
Adds the full transactional email system:
- Redis queue (QUEUE_CONNECTION=redis), SES config in .env.example
- 3 migrations: organisation_email_settings, organisation_email_templates, email_logs
- EmailTemplateType and EmailLogStatus enums with Dutch defaults
- EmailService as central entry point for all email sending
- SendTransactionalEmail queued job with retries and idempotency
- TransactionalMail mailable with responsive HTML + plain text templates
- Organisation-level branding (colors, logo, footer, reply-to)
- Per-type template overrides with {variable} substitution
- Email log with filtering by status, type, date range, recipient
- Preview and send-test endpoints for template management
- API endpoints: email-settings, email-templates (CRUD), email-logs (read-only)
- Integrated into existing flows: invitations, password reset, email
verification, registration approval/rejection
- 37 new tests across 4 test files, all existing tests updated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Enums\EmailTemplateType;
|
||||
use App\Enums\PersonStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
||||
@@ -12,18 +13,16 @@ use App\Http\Requests\Api\V1\StorePersonRequest;
|
||||
use App\Http\Requests\Api\V1\UpdatePersonRequest;
|
||||
use App\Http\Resources\Api\V1\PersonCollection;
|
||||
use App\Http\Resources\Api\V1\PersonResource;
|
||||
use App\Mail\RegistrationApprovedMail;
|
||||
use App\Mail\RegistrationRejectedMail;
|
||||
use App\Models\Event;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\User;
|
||||
use App\Services\EmailService;
|
||||
use App\Services\PersonIdentityService;
|
||||
use App\Services\TagSyncService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
final class PersonController extends Controller
|
||||
@@ -33,6 +32,7 @@ final class PersonController extends Controller
|
||||
public function __construct(
|
||||
private readonly PersonIdentityService $identityService,
|
||||
private readonly TagSyncService $tagSyncService,
|
||||
private readonly EmailService $emailService,
|
||||
) {}
|
||||
|
||||
public function index(Request $request, Organisation $organisation, Event $event): PersonCollection
|
||||
@@ -169,7 +169,20 @@ final class PersonController extends Controller
|
||||
$this->tagSyncService->syncFromRegistration($person);
|
||||
|
||||
if ($person->email) {
|
||||
Mail::to($person->email)->queue(new RegistrationApprovedMail($person, $event));
|
||||
$this->emailService->send(
|
||||
type: EmailTemplateType::REGISTRATION_APPROVED,
|
||||
recipientEmail: $person->email,
|
||||
recipientName: trim($person->first_name . ' ' . $person->last_name),
|
||||
variables: [
|
||||
'event_name' => $event->name,
|
||||
'organisation_name' => $organisation->name,
|
||||
],
|
||||
actionUrl: config('app.frontend_portal_url'),
|
||||
organisation: $organisation,
|
||||
eventId: $event->id,
|
||||
personId: $person->id,
|
||||
triggeredByUserId: auth()->id(),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->success(new PersonResource($person->fresh()->load('crowdType')));
|
||||
@@ -182,10 +195,20 @@ final class PersonController extends Controller
|
||||
|
||||
$person->update(['status' => 'rejected']);
|
||||
|
||||
$reason = $request->input('reason');
|
||||
|
||||
if ($person->email) {
|
||||
Mail::to($person->email)->queue(new RegistrationRejectedMail($person, $event, $reason));
|
||||
$this->emailService->send(
|
||||
type: EmailTemplateType::REGISTRATION_REJECTED,
|
||||
recipientEmail: $person->email,
|
||||
recipientName: trim($person->first_name . ' ' . $person->last_name),
|
||||
variables: [
|
||||
'event_name' => $event->name,
|
||||
'organisation_name' => $organisation->name,
|
||||
],
|
||||
organisation: $organisation,
|
||||
eventId: $event->id,
|
||||
personId: $person->id,
|
||||
triggeredByUserId: auth()->id(),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->success(new PersonResource($person->fresh()->load('crowdType')));
|
||||
|
||||
Reference in New Issue
Block a user