diff --git a/app/Http/Middleware/RateLimitOutboundMail.php b/app/Http/Middleware/RateLimitOutboundMail.php index aa9f984c14..56a34d567b 100644 --- a/app/Http/Middleware/RateLimitOutboundMail.php +++ b/app/Http/Middleware/RateLimitOutboundMail.php @@ -20,6 +20,7 @@ use App\Jobs\SendDisableUserMail; use App\Jobs\SendMassEmail; use Closure; +use Illuminate\Notifications\SendQueuedNotifications; use Illuminate\Support\Facades\Redis; class RateLimitOutboundMail @@ -29,7 +30,7 @@ class RateLimitOutboundMail * * @param Closure(object): void $next */ - public function handle(SendDeleteUserMail|SendDisableUserMail|SendMassEmail $job, Closure $next): void + public function handle(SendQueuedNotifications|SendDeleteUserMail|SendDisableUserMail|SendMassEmail $job, Closure $next): void { Redis::throttle(config('cache.prefix').':outbound-email-limiter') ->allow(config('other.mail.allow')) diff --git a/app/Jobs/SendDeleteUserMail.php b/app/Jobs/SendDeleteUserMail.php index b57dd4b0b3..d617c6164f 100644 --- a/app/Jobs/SendDeleteUserMail.php +++ b/app/Jobs/SendDeleteUserMail.php @@ -35,9 +35,9 @@ class SendDeleteUserMail implements ShouldQueue use SerializesModels; /** - * The number of times the job may be attempted. + * The maximum number of unhandled exceptions to allow before failing. */ - public int $tries = 3; + public int $maxExceptions = 1; /** * SendDeleteUserMail Constructor. diff --git a/app/Jobs/SendDisableUserMail.php b/app/Jobs/SendDisableUserMail.php index 7a64452a41..d5dfa14b93 100644 --- a/app/Jobs/SendDisableUserMail.php +++ b/app/Jobs/SendDisableUserMail.php @@ -35,9 +35,9 @@ class SendDisableUserMail implements ShouldQueue use SerializesModels; /** - * The number of times the job may be attempted. + * The maximum number of unhandled exceptions to allow before failing. */ - public int $tries = 3; + public int $maxExceptions = 1; /** * SendDisableUserMail Constructor. diff --git a/app/Jobs/SendMassEmail.php b/app/Jobs/SendMassEmail.php index 3a215552d6..c6a5816ca2 100644 --- a/app/Jobs/SendMassEmail.php +++ b/app/Jobs/SendMassEmail.php @@ -34,9 +34,9 @@ class SendMassEmail implements ShouldQueue use SerializesModels; /** - * The number of times the job may be attempted. + * The maximum number of unhandled exceptions to allow before failing. */ - public int $tries = 3; + public int $maxExceptions = 1; /** * Create a new job instance. diff --git a/app/Notifications/FailedLogin.php b/app/Notifications/FailedLogin.php index d2e24cad77..05504abc77 100644 --- a/app/Notifications/FailedLogin.php +++ b/app/Notifications/FailedLogin.php @@ -16,7 +16,9 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -27,6 +29,11 @@ class FailedLogin extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * FailedLogin Constructor. */ @@ -44,6 +51,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Determine if the notification should be sent. */ @@ -69,4 +89,12 @@ public function toMail(object $notifiable): MailMessage { return (new MailMessage())->error()->subject(trans('email.fail-login-subject'))->greeting(trans('email.fail-login-greeting'))->line(trans('email.fail-login-line1'))->line(trans('email.fail-login-line2', ['ip' => $this->ip, 'host' => gethostbyaddr($this->ip), 'time' => Carbon::now()->__toString()])); } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/MassEmail.php b/app/Notifications/MassEmail.php index 1b3c299488..d6372bbfa8 100644 --- a/app/Notifications/MassEmail.php +++ b/app/Notifications/MassEmail.php @@ -16,14 +16,22 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class MassEmail extends Notification +class MassEmail extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -41,6 +49,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -52,4 +73,12 @@ public function toMail(object $notifiable): MailMessage ->action('Login Now', route('login')) ->line('Thank you for using 🚀'.config('other.title')); } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserBan.php b/app/Notifications/UserBan.php index a8e1fd33b6..45cef8bba0 100644 --- a/app/Notifications/UserBan.php +++ b/app/Notifications/UserBan.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\Ban; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserBan extends Notification +class UserBan extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -55,4 +76,12 @@ public function toMail(object $notifiable): MailMessage ->action('Need Support?', $chatUrl) ->line('Thank you for using 🚀'.config('other.title')); } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserBanExpire.php b/app/Notifications/UserBanExpire.php index ad73f5d767..7738be492b 100644 --- a/app/Notifications/UserBanExpire.php +++ b/app/Notifications/UserBanExpire.php @@ -16,14 +16,22 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserBanExpire extends Notification +class UserBanExpire extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -41,6 +49,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -51,4 +72,12 @@ public function toMail(object $notifiable): MailMessage ->line('You have been unbanned from '.config('other.title')) ->line('Thank you for using 🚀'.config('other.title')); } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserEmailChange.php b/app/Notifications/UserEmailChange.php index eae642f3c1..fca2b0e148 100644 --- a/app/Notifications/UserEmailChange.php +++ b/app/Notifications/UserEmailChange.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserEmailChange extends Notification +class UserEmailChange extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -53,4 +74,12 @@ public function toMail(object $notifiable): MailMessage ->action('Helpdesk', route('tickets.index')) ->line('Thank you for using 🚀'.config('other.title')); } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserManualWarningExpire.php b/app/Notifications/UserManualWarningExpire.php index 4146f792d9..f591ebfb54 100644 --- a/app/Notifications/UserManualWarningExpire.php +++ b/app/Notifications/UserManualWarningExpire.php @@ -16,16 +16,24 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; use App\Models\Warning; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserManualWarningExpire extends Notification +class UserManualWarningExpire extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -43,6 +51,19 @@ public function via(object $notifiable): array return ['database', 'mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -70,4 +91,12 @@ public function toArray(object $notifiable): array 'url' => \sprintf('/users/%s', $this->user->username), ]; } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserMaxWarningsReached.php b/app/Notifications/UserMaxWarningsReached.php index a7389b5e81..7cbf021b63 100644 --- a/app/Notifications/UserMaxWarningsReached.php +++ b/app/Notifications/UserMaxWarningsReached.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserMaxWarningsReached extends Notification +class UserMaxWarningsReached extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -69,4 +90,12 @@ public function toArray(object $notifiable): array 'url' => \sprintf('/users/%s', $this->user->username), ]; } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserPreWarning.php b/app/Notifications/UserPreWarning.php index b80ccc1060..0059659b31 100644 --- a/app/Notifications/UserPreWarning.php +++ b/app/Notifications/UserPreWarning.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserPreWarning extends Notification +class UserPreWarning extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['database', 'mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -67,4 +88,12 @@ public function toArray(object $notifiable): array 'url' => route('users.history.index', ['user' => $this->user]), ]; } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserWarning.php b/app/Notifications/UserWarning.php index d0100d03af..000d00e075 100644 --- a/app/Notifications/UserWarning.php +++ b/app/Notifications/UserWarning.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserWarning extends Notification +class UserWarning extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['database', 'mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -67,4 +88,12 @@ public function toArray(object $notifiable): array 'url' => route('users.history.index', ['user' => $this->user]), ]; } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } } diff --git a/app/Notifications/UserWarningExpired.php b/app/Notifications/UserWarningExpired.php index b2b104666f..c3c0cea443 100644 --- a/app/Notifications/UserWarningExpired.php +++ b/app/Notifications/UserWarningExpired.php @@ -16,15 +16,23 @@ namespace App\Notifications; +use App\Http\Middleware\RateLimitOutboundMail; use App\Models\User; +use DateTime; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class UserWarningExpired extends Notification +class UserWarningExpired extends Notification implements ShouldQueue { use Queueable; + /** + * The maximum number of unhandled exceptions to allow before failing. + */ + public int $maxExceptions = 1; + /** * Create a new notification instance. */ @@ -42,6 +50,19 @@ public function via(object $notifiable): array return ['database', 'mail']; } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(object $notifiable, string $channel): array + { + return match ($channel) { + 'mail' => [new RateLimitOutboundMail()], + default => [], + }; + } + /** * Get the mail representation of the notification. */ @@ -69,4 +90,12 @@ public function toArray(object $notifiable): array 'url' => \sprintf('/users/%s', $this->user->username), ]; } + + /** + * Determine the time at which the job should timeout. + */ + public function retryUntil(): DateTime + { + return now()->addHours(2); + } }