Expand settings for notifications.

This commit is contained in:
James Cole
2024-12-11 07:23:46 +01:00
parent c35ff3174a
commit c920070ce2
24 changed files with 476 additions and 252 deletions

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Test;
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
@@ -35,26 +36,26 @@ class TestNotificationEmail extends Notification
{
use Queueable;
private string $address;
private OwnerNotifiable $owner;
/**
* Create a new notification instance.
*/
public function __construct(string $address)
public function __construct(OwnerNotifiable $owner)
{
$this->address = $address;
$this->owner = $owner;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @param OwnerNotifiable $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return array
*/
public function toArray($notifiable)
public function toArray(OwnerNotifiable $notifiable)
{
return [
];
@@ -69,23 +70,14 @@ class TestNotificationEmail extends Notification
*
* @return MailMessage
*/
public function toMail($notifiable)
public function toMail(OwnerNotifiable $notifiable)
{
$address = (string) config('firefly.site_owner');
return (new MailMessage())
->markdown('emails.admin-test', ['email' => $this->address])
->markdown('emails.admin-test', ['email' => $address])
->subject((string) trans('email.admin_test_subject'));
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function toSlack($notifiable) {}
/**
* Get the notification's delivery channels.
*
@@ -95,7 +87,7 @@ class TestNotificationEmail extends Notification
*
* @return array
*/
public function via($notifiable)
public function via(OwnerNotifiable $notifiable)
{
return ['mail'];
}

View File

@@ -24,9 +24,10 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Test;
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
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 Ntfy\Message;
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
@@ -40,14 +41,14 @@ class TestNotificationNtfy extends Notification
{
use Queueable;
private string $address;
public OwnerNotifiable $owner;
/**
* Create a new notification instance.
*/
public function __construct(string $address)
public function __construct(OwnerNotifiable $owner)
{
$this->address = $address;
$this->owner = $owner;
}
/**
@@ -66,51 +67,34 @@ class TestNotificationNtfy extends Notification
}
public function toNtfy(mixed $notifiable): Message
public function toNtfy(OwnerNotifiable $notifiable): Message
{
$settings = ReturnsSettings::getSettings('ntfy', 'owner', null);
// overrule config.
config(['ntfy-notification-channel.server' => $settings['ntfy_server']]);
config(['ntfy-notification-channel.topic' => $settings['ntfy_topic']]);
if ($settings['ntfy_auth']) {
// overrule auth as well.
config(['ntfy-notification-channel.authentication.enabled' => true]);
config(['ntfy-notification-channel.authentication.username' => $settings['ntfy_user']]);
config(['ntfy-notification-channel.authentication.password' => $settings['ntfy_pass']]);
}
$message = new Message();
$message->topic(config('ntfy-notification-channel.topic'));
$message->title((string)trans('email.admin_test_subject'));
$message->body((string)trans('email.admin_test_message', ['channel' => 'ntfy']));
$message->tags(['white_check_mark', 'ok_hand']);
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.admin_test_subject'));
$message->body((string) trans('email.admin_test_message', ['channel' => 'ntfy']));
$message->tags(['white_check_mark']);
return $message;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return MailMessage
*/
public function toMail($notifiable)
{
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function toSlack($notifiable) {
}
/**
* Get the notification's delivery channels.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
public function via(OwnerNotifiable $notifiable)
{
return [NtfyChannel::class];
}

View File

@@ -24,6 +24,8 @@ 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;
@@ -42,73 +44,45 @@ class TestNotificationPushover extends Notification
{
use Queueable;
private string $address;
private OwnerNotifiable $owner;
/**
* Create a new notification instance.
*/
public function __construct(string $address)
public function __construct(OwnerNotifiable $owner)
{
$this->address = $address;
$this->owner = $owner;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @param OwnerNotifiable $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return array
*/
public function toArray($notifiable)
public function toArray(OwnerNotifiable $notifiable)
{
return [
];
}
public function toPushover(mixed $notifiable): PushoverMessage
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'));
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return MailMessage
*/
public function toMail($notifiable)
{
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function toSlack($notifiable) {
}
/**
* Get the notification's delivery channels.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
public function via(OwnerNotifiable $notifiable)
{
return [PushoverChannel::class];
}

View File

@@ -24,11 +24,14 @@ 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\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
//use Illuminate\Notifications\Slack\SlackMessage;
use Illuminate\Support\Facades\Log;
use Illuminate\Notifications\Messages\SlackMessage;
/**
* Class TestNotification
@@ -37,64 +40,49 @@ class TestNotificationSlack extends Notification
{
use Queueable;
private string $address;
private OwnerNotifiable $owner;
/**
* Create a new notification instance.
*/
public function __construct(string $address)
public function __construct(OwnerNotifiable $owner)
{
$this->address = $address;
$this->owner =$owner;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @param OwnerNotifiable $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return array
*/
public function toArray($notifiable)
public function toArray(OwnerNotifiable $notifiable)
{
return [
];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return MailMessage
*/
public function toMail($notifiable)
{
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @param OwnerNotifiable $notifiable
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function toSlack($notifiable) {
public function toSlack(OwnerNotifiable $notifiable)
{
// since it's an admin notification, grab the URL from fireflyconfig
$url = app('fireflyconfig')->get('slack_webhook_url', '')->data;
// return (new SlackMessage)
// ->text((string)trans('email.admin_test_subject'))
// ->to($url);
return (new SlackMessage())
->content((string)trans('email.admin_test_subject'))
->to($url);
$url = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
if ('' !== $url) {
return new SlackMessage()->content((string)trans('email.admin_test_subject'))->to($url);
//return new SlackMessage()->text((string) trans('email.admin_test_subject'))->to($url);
}
Log::error('Empty slack URL, cannot send notification.');
}
/**
@@ -102,11 +90,11 @@ class TestNotificationSlack extends Notification
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param mixed $notifiable
* @param OwnerNotifiable $notifiable
*
* @return array
*/
public function via($notifiable)
public function via(OwnerNotifiable $notifiable)
{
return ['slack'];
}