2.0 KiB
2.0 KiB
Story 8.10: Admin Notification - System Events
Epic Reference
Epic 8: Email Notification System
User Story
As an admin, I want to be notified of critical system events, So that I can address issues promptly.
Acceptance Criteria
Events to Notify
- Email delivery failures
- Scheduled job failures
- Critical application errors
Content
- Event type and description
- Timestamp
- Relevant details
- Recommended action (if any)
Delivery
- Sent immediately (not queued)
- Clear subject line indicating urgency
Technical Notes
// In App\Exceptions\Handler or bootstrap/app.php
->withExceptions(function (Exceptions $exceptions) {
$exceptions->reportable(function (Throwable $e) {
if ($this->shouldNotifyAdmin($e)) {
$admin = User::where('user_type', 'admin')->first();
$admin?->notify(new SystemErrorNotification($e));
}
});
});
class SystemErrorNotification extends Notification
{
public function __construct(
public Throwable $exception
) {}
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject('[URGENT] System Error - Libra Law Firm')
->line('A critical error occurred on the platform.')
->line('Error: ' . $this->exception->getMessage())
->line('Time: ' . now()->format('Y-m-d H:i:s'))
->line('Please check the logs for more details.');
}
}
// Queue failure notification
Queue::failing(function (JobFailed $event) {
$admin = User::where('user_type', 'admin')->first();
$admin?->notify(new QueueFailureNotification($event));
});
Definition of Done
- Email failures notified
- Job failures notified
- Critical errors notified
- Sent immediately
- Clear urgency indication
- Tests pass
Estimation
Complexity: Medium | Effort: 3 hours