mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Clean up some code.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* UnknownUserLoginAttempt.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -64,15 +65,14 @@ class UnknownUserLoginAttempt extends Notification
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @return MailMessage
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(OwnerNotifiable $notifiable): MailMessage
|
||||
{
|
||||
return new MailMessage()
|
||||
->markdown('emails.owner.unknown-user', ['address' => $this->address])
|
||||
->subject((string) trans('email.unknown_user_subject'));
|
||||
->subject((string) trans('email.unknown_user_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,8 @@ class UnknownUserLoginAttempt extends Notification
|
||||
public function toPushover(OwnerNotifiable $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.unknown_user_message', ['address' => $this->address]))
|
||||
->title((string) trans('email.unknown_user_subject'));
|
||||
->title((string) trans('email.unknown_user_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
@@ -108,7 +109,7 @@ class UnknownUserLoginAttempt extends Notification
|
||||
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.unknown_user_subject'));
|
||||
$message->body((string) trans('email.unknown_user_message', ['address' => $this->address]));
|
||||
|
||||
@@ -83,7 +83,8 @@ class UserInvitation extends Notification
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.invitation-created', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])
|
||||
->subject((string) trans('email.invitation_created_subject'));
|
||||
->subject((string) trans('email.invitation_created_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +108,8 @@ class UserInvitation extends Notification
|
||||
Log::debug('Now in toPushover() for UserInvitation');
|
||||
|
||||
return PushoverMessage::create((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]))
|
||||
->title((string) trans('email.invitation_created_subject'));
|
||||
->title((string) trans('email.invitation_created_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
@@ -126,7 +128,7 @@ class UserInvitation extends Notification
|
||||
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.invitation_created_subject'));
|
||||
$message->body((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]));
|
||||
|
||||
@@ -51,7 +51,7 @@ class UserRegistration extends Notification
|
||||
*/
|
||||
public function __construct(OwnerNotifiable $owner, User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->user = $user;
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ class UserRegistration extends Notification
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id])
|
||||
->subject((string) trans('email.registered_subject_admin'));
|
||||
->subject((string) trans('email.registered_subject_admin'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,8 @@ class UserRegistration extends Notification
|
||||
Log::debug('Now in toPushover() for UserRegistration');
|
||||
|
||||
return PushoverMessage::create((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]))
|
||||
->title((string) trans('email.registered_subject_admin'));
|
||||
->title((string) trans('email.registered_subject_admin'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
@@ -120,10 +122,10 @@ class UserRegistration extends Notification
|
||||
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.registered_subject_admin'));
|
||||
$message->body((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]) );
|
||||
$message->body((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace FireflyIII\Notifications\Admin;
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
@@ -108,7 +107,8 @@ class VersionCheckResult extends Notification
|
||||
Log::debug('Now in toPushover() for VersionCheckResult');
|
||||
|
||||
return PushoverMessage::create($this->message)
|
||||
->title((string) trans('email.new_version_email_subject'));
|
||||
->title((string) trans('email.new_version_email_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
@@ -127,7 +127,7 @@ class VersionCheckResult extends Notification
|
||||
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.new_version_email_subject'));
|
||||
$message->body($this->message);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AdminNotifiable.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -30,13 +31,13 @@ use NotificationChannels\Pushover\PushoverReceiver;
|
||||
|
||||
class OwnerNotifiable
|
||||
{
|
||||
|
||||
public function routeNotificationForSlack(): string
|
||||
{
|
||||
$res = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
|
||||
if (is_array($res)) {
|
||||
$res = '';
|
||||
}
|
||||
|
||||
return (string) $res;
|
||||
}
|
||||
|
||||
@@ -45,8 +46,10 @@ class OwnerNotifiable
|
||||
Log::debug('Return settings for routeNotificationForPushover');
|
||||
$pushoverAppToken = (string) app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;
|
||||
$pushoverUserToken = (string) app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;
|
||||
|
||||
return PushoverReceiver::withUserKey($pushoverUserToken)
|
||||
->withApplicationToken($pushoverAppToken);
|
||||
->withApplicationToken($pushoverAppToken)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,9 +62,10 @@ class OwnerNotifiable
|
||||
*/
|
||||
public function routeNotificationFor($driver, $notification = null)
|
||||
{
|
||||
$method = 'routeNotificationFor' . Str::studly($driver);
|
||||
$method = 'routeNotificationFor'.Str::studly($driver);
|
||||
if (method_exists($this, $method)) {
|
||||
Log::debug(sprintf('Redirect for settings to "%s".', $method));
|
||||
|
||||
return $this->{$method}($notification); // @phpstan-ignore-line
|
||||
}
|
||||
Log::debug(sprintf('No method "%s" found, return generic settings.', $method));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ReturnsAvailableChannels.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -46,8 +47,8 @@ class ReturnsAvailableChannels
|
||||
private static function returnOwnerChannels(): array
|
||||
{
|
||||
|
||||
$channels = ['mail'];
|
||||
$slackUrl = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
|
||||
$channels = ['mail'];
|
||||
$slackUrl = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
$channels[] = 'slack';
|
||||
}
|
||||
@@ -73,8 +74,8 @@ class ReturnsAvailableChannels
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Final channel set in ReturnsAvailableChannels: %s ', implode(', ', $channels)));
|
||||
|
||||
// only the owner can get notifications over
|
||||
return $channels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ReturnsSettings.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -34,6 +35,7 @@ class ReturnsSettings
|
||||
if ('ntfy' === $channel) {
|
||||
return self::getNtfySettings($type, $user);
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('Cannot handle channel "%s"', $channel));
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ class ReturnsSettings
|
||||
$settings['ntfy_user'] = FireflyConfig::getEncrypted('ntfy_user', '')->data;
|
||||
$settings['ntfy_pass'] = FireflyConfig::getEncrypted('ntfy_pass', '')->data;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ class TestNotificationEmail extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@@ -73,9 +71,11 @@ class TestNotificationEmail extends Notification
|
||||
public function toMail(OwnerNotifiable $notifiable)
|
||||
{
|
||||
$address = (string) config('firefly.site_owner');
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('emails.admin-test', ['email' => $address])
|
||||
->subject((string) trans('email.admin_test_subject'));
|
||||
->subject((string) trans('email.admin_test_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,13 +26,12 @@ namespace FireflyIII\Notifications\Test;
|
||||
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Ntfy\Message;
|
||||
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
|
||||
|
||||
//use Illuminate\Notifications\Slack\SlackMessage;
|
||||
// use Illuminate\Notifications\Slack\SlackMessage;
|
||||
|
||||
/**
|
||||
* Class TestNotification
|
||||
@@ -66,7 +65,6 @@ class TestNotificationNtfy extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'owner', null);
|
||||
@@ -82,7 +80,7 @@ class TestNotificationNtfy extends Notification
|
||||
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title((string) trans('email.admin_test_subject'));
|
||||
$message->body((string) trans('email.admin_test_message', ['channel' => 'ntfy']));
|
||||
|
||||
@@ -25,17 +25,13 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Test;
|
||||
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use NotificationChannels\Pushover\PushoverChannel;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
|
||||
|
||||
//use Illuminate\Notifications\Slack\SlackMessage;
|
||||
// use Illuminate\Notifications\Slack\SlackMessage;
|
||||
|
||||
/**
|
||||
* Class TestNotification
|
||||
@@ -57,8 +53,6 @@ class TestNotificationPushover extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@@ -69,16 +63,15 @@ class TestNotificationPushover extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toPushover(OwnerNotifiable $notifiable): PushoverMessage
|
||||
{
|
||||
Log::debug('Now in toPushover()');
|
||||
|
||||
return PushoverMessage::create((string)trans('email.admin_test_message', ['channel' => 'Pushover']))
|
||||
->title((string)trans('email.admin_test_subject'));
|
||||
->title((string)trans('email.admin_test_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
//use Illuminate\Notifications\Slack\SlackMessage;
|
||||
// use Illuminate\Notifications\Slack\SlackMessage;
|
||||
|
||||
/**
|
||||
* Class TestNotification
|
||||
@@ -51,8 +51,6 @@ class TestNotificationSlack extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@@ -66,15 +64,12 @@ class TestNotificationSlack extends Notification
|
||||
/**
|
||||
* Get the Slack representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
*/
|
||||
public function toSlack(OwnerNotifiable $notifiable)
|
||||
{
|
||||
return new SlackMessage()->content((string) trans('email.admin_test_subject'));
|
||||
//return new SlackMessage()->text((string) trans('email.admin_test_subject'))->to($url);
|
||||
// return new SlackMessage()->text((string) trans('email.admin_test_subject'))->to($url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +77,6 @@ class TestNotificationSlack extends Notification
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via(OwnerNotifiable $notifiable)
|
||||
|
||||
Reference in New Issue
Block a user