Clean up and fix notifications.

This commit is contained in:
James Cole
2024-12-14 07:52:02 +01:00
parent 5f1502eea7
commit 5520992861
20 changed files with 195 additions and 25 deletions

View File

@@ -103,7 +103,7 @@ class UserInvitation extends Notification
*/
public function toSlack(OwnerNotifiable $notifiable)
{
return (new SlackMessage())->content(
return new SlackMessage()->content(
(string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])
);
}

View File

@@ -103,7 +103,7 @@ class UserRegistration extends Notification
*/
public function toSlack(OwnerNotifiable $notifiable)
{
return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));
return new SlackMessage()->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));
}
/**

View File

@@ -100,7 +100,7 @@ class VersionCheckResult extends Notification
*/
public function toSlack(OwnerNotifiable $notifiable)
{
return (new SlackMessage())->content($this->message)
return new SlackMessage()->content($this->message)
->attachment(static function ($attachment): void {
$attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases');
});

View File

@@ -65,12 +65,9 @@ class DisabledMFANotification extends Notification
return (new MailMessage())->markdown('emails.security.disabled-mfa', ['user' => $this->user])->subject($subject);
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toNtfy(User $user): Message
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $user);
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.disabled_mfa_subject'));
@@ -84,8 +81,6 @@ class DisabledMFANotification extends Notification
*/
public function toPushover(User $notifiable): PushoverMessage
{
Log::debug('Now in (user) toPushover()');
return PushoverMessage::create((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]))
->title((string) trans('email.disabled_mfa_subject'));
}
@@ -97,7 +92,7 @@ class DisabledMFANotification extends Notification
{
$message = (string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
/**

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class EnabledMFANotification extends Notification
{
@@ -62,6 +65,26 @@ class EnabledMFANotification extends Notification
return (new MailMessage())->markdown('emails.security.enabled-mfa', ['user' => $this->user])->subject($subject);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.enabled_mfa_subject'));
$message->body((string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]))
->title((string) trans('email.enabled_mfa_subject'));
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
@@ -69,7 +92,7 @@ class EnabledMFANotification extends Notification
{
$message = (string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class MFABackupFewLeftNotification extends Notification
{
@@ -70,7 +73,27 @@ class MFABackupFewLeftNotification extends Notification
{
$message = (string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.mfa_few_backups_left_subject'));
$message->body((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]))
->title((string) trans('email.mfa_few_backups_left_subject'));
}

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class MFABackupNoLeftNotification extends Notification
{
@@ -69,7 +72,27 @@ class MFABackupNoLeftNotification extends Notification
{
$message = (string) trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.mfa_no_backups_left_subject'));
$message->body((string) trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email]))
->title((string) trans('email.mfa_no_backups_left_slack'));
}

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class MFAManyFailedAttemptsNotification extends Notification
{
@@ -68,7 +71,27 @@ class MFAManyFailedAttemptsNotification extends Notification
{
$message = (string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.mfa_many_failed_subject'));
$message->body((string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]))
->title((string) trans('email.mfa_many_failed_subject'));
}

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class MFAUsedBackupCodeNotification extends Notification
{
@@ -69,9 +72,28 @@ class MFAUsedBackupCodeNotification extends Notification
{
$message = (string) trans('email.used_backup_code_slack', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.used_backup_code_subject'));
$message->body((string) trans('email.used_backup_code_slack', ['email' => $this->user->email]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.used_backup_code_slack', ['email' => $this->user->email]))
->title((string) trans('email.used_backup_code_subject'));
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)

View File

@@ -25,11 +25,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class NewBackupCodesNotification extends Notification
{
@@ -69,7 +72,27 @@ class NewBackupCodesNotification extends Notification
{
$message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.new_backup_codes_subject'));
$message->body((string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]))
->title((string) trans('email.new_backup_codes_subject'));
}
/**

View File

@@ -24,11 +24,14 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Security;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Pushover\PushoverMessage;
use Ntfy\Message;
class UserFailedLoginAttempt extends Notification
{
@@ -54,9 +57,9 @@ class UserFailedLoginAttempt extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.new_backup_codes_subject');
$subject = (string) trans('email.failed_login_subject');
return (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);
return (new MailMessage())->markdown('emails.security.failed-login', ['user' => $this->user])->subject($subject);
}
/**
@@ -64,9 +67,29 @@ class UserFailedLoginAttempt extends Notification
*/
public function toSlack(User $notifiable)
{
$message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);
$message = (string) trans('email.failed_login_message', ['email' => $this->user->email]);
return (new SlackMessage())->content($message);
return new SlackMessage()->content($message);
}
public function toNtfy(User $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.failed_login_subject'));
$message->body((string) trans('email.failed_login_message', ['email' => $this->user->email]));
return $message;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toPushover(User $notifiable): PushoverMessage
{
return PushoverMessage::create((string) trans('email.failed_login_message', ['email' => $this->user->email]))
->title((string) trans('email.failed_login_subject'));
}
/**

View File

@@ -88,7 +88,7 @@ class BillReminder extends Notification
$bill = $this->bill;
$url = route('bills.show', [$bill->id]);
return (new SlackMessage())
return new SlackMessage()
->warning()
->attachment(static function ($attachment) use ($bill, $url): void {
$attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url);

View File

@@ -63,7 +63,7 @@ class NewAccessToken extends Notification
*/
public function toSlack(User $notifiable)
{
return (new SlackMessage())->content((string) trans('email.access_token_created_body'));
return new SlackMessage()->content((string) trans('email.access_token_created_body'));
}
/**

View File

@@ -73,7 +73,7 @@ class RuleActionFailed extends Notification
$ruleTitle = $this->ruleTitle;
$ruleLink = $this->ruleLink;
return (new SlackMessage())->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {
return new SlackMessage()->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {
$attachment->title((string) trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);
})->attachment(static function ($attachment) use ($ruleTitle, $ruleLink): void {
$attachment->title((string) trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);

View File

@@ -94,7 +94,7 @@ class UserLogin extends Notification
$host = $hostName;
}
return (new SlackMessage())->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
return new SlackMessage()->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
}
/**