mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-24 12:09:02 -05:00
fix: outbound mail rate limit not applying to all emails
Only the mailables were rate limited previously.
This commit is contained in:
@@ -20,6 +20,7 @@ use App\Jobs\SendDeleteUserMail;
|
||||
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'))
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -16,7 +16,9 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class FailedLogin extends Notification implements ShouldQueue
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class FailedLogin extends Notification implements ShouldQueue
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,22 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class MassEmail extends Notification
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class MassEmail extends Notification
|
||||
->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserBan extends Notification
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserBan extends Notification
|
||||
->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,22 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserBanExpire extends Notification
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserBanExpire extends Notification
|
||||
->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserEmailChange extends Notification
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserEmailChange extends Notification
|
||||
->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,24 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserManualWarningExpire extends Notification
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserManualWarningExpire extends Notification
|
||||
'url' => \sprintf('/users/%s', $this->user->username),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the time at which the job should timeout.
|
||||
*/
|
||||
public function retryUntil(): DateTime
|
||||
{
|
||||
return now()->addHours(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserMaxWarningsReached extends Notification
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserMaxWarningsReached extends Notification
|
||||
'url' => \sprintf('/users/%s', $this->user->username),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the time at which the job should timeout.
|
||||
*/
|
||||
public function retryUntil(): DateTime
|
||||
{
|
||||
return now()->addHours(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserPreWarning extends Notification
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserPreWarning extends Notification
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserWarning extends Notification
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserWarning extends Notification
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@ declare(strict_types=1);
|
||||
|
||||
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 @@ class UserWarningExpired extends Notification
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
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 @@ class UserWarningExpired extends Notification
|
||||
'url' => \sprintf('/users/%s', $this->user->username),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the time at which the job should timeout.
|
||||
*/
|
||||
public function retryUntil(): DateTime
|
||||
{
|
||||
return now()->addHours(2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user