Skip to content

Firefly III: a personal finances manager

Fix notification nullpointer

James Cole923debb29917
diff --git a/app/Notifications/Admin/TestNotification.php b/app/Notifications/Admin/TestNotification.php
index aa4a954d3a..0332f3519c 100644
--- a/app/Notifications/Admin/TestNotification.php
+++ b/app/Notifications/Admin/TestNotification.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Admin;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
@@ -97,7 +98,9 @@ class TestNotification extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/Admin/UserInvitation.php b/app/Notifications/Admin/UserInvitation.php
index a5a9f67c7d..9050b30863 100644
--- a/app/Notifications/Admin/UserInvitation.php
+++ b/app/Notifications/Admin/UserInvitation.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Admin;
use FireflyIII\Models\InvitedUser;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
@@ -100,7 +101,9 @@ class UserInvitation extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/Admin/UserRegistration.php b/app/Notifications/Admin/UserRegistration.php
index b195bd4ff5..8d0ebf5406 100644
--- a/app/Notifications/Admin/UserRegistration.php
+++ b/app/Notifications/Admin/UserRegistration.php
@@ -98,7 +98,9 @@ class UserRegistration extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/Admin/VersionCheckResult.php b/app/Notifications/Admin/VersionCheckResult.php
index 2323bf7289..d6f29ceecd 100644
--- a/app/Notifications/Admin/VersionCheckResult.php
+++ b/app/Notifications/Admin/VersionCheckResult.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Admin;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
@@ -112,7 +113,9 @@ class VersionCheckResult extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/User/BillReminder.php b/app/Notifications/User/BillReminder.php
index 827517b7ab..abe997248b 100644
--- a/app/Notifications/User/BillReminder.php
+++ b/app/Notifications/User/BillReminder.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\User;
use FireflyIII\Models\Bill;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
@@ -118,7 +119,9 @@ class BillReminder extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.php
index c35e5dc96b..69df8107a0 100644
--- a/app/Notifications/User/NewAccessToken.php
+++ b/app/Notifications/User/NewAccessToken.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\User;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
@@ -94,7 +95,9 @@ class NewAccessToken extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}
diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.php
index 22a56cde73..4ede883cea 100644
--- a/app/Notifications/User/UserLogin.php
+++ b/app/Notifications/User/UserLogin.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\User;
use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
@@ -122,7 +123,9 @@ class UserLogin extends Notification
*/
public function via($notifiable)
{
- $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
+ /** @var User|null $user */
+ $user = auth()->user();
+ $slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) {
return ['mail', 'slack'];
}