Add notifications.

This commit is contained in:
James Cole
2022-09-24 11:41:07 +02:00
parent 665b78ebf5
commit be1dff49fa
9 changed files with 152 additions and 16 deletions

View File

@@ -22,12 +22,12 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use Exception;
use FireflyIII\Events\AdminRequestedTestMessage;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Mail\AdminTestMail;
use FireflyIII\Events\NewVersionAvailable;
use FireflyIII\Notifications\Admin\TestNotification;
use FireflyIII\Notifications\Admin\VersionCheckResult;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Notification;
use Log;
use Mail;
@@ -43,7 +43,7 @@ class AdminEventHandler
*
* @param AdminRequestedTestMessage $event
*
* @return bool
* @return void
*/
public function sendTestMessage(AdminRequestedTestMessage $event): void
{
@@ -56,4 +56,27 @@ class AdminEventHandler
Notification::send($event->user, new TestNotification($event->user->email));
}
/**
* Send new version message to admin.
*
* @param NewVersionAvailable $event
* @return void
*/
public function sendNewVersion(NewVersionAvailable $event): void
{
$sendMail = FireflyConfig::get('notification_new_version', true)->data;
if (false === $sendMail) {
return;
}
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$all = $repository->all();
foreach ($all as $user) {
if ($repository->hasRole($user, 'owner')) {
Notification::send($user, new VersionCheckResult($event->message));
}
}
}
}

View File

@@ -165,7 +165,6 @@ class UserEventHandler
*
* @param Login $event
*
* @return bool
* @throws FireflyException
*/
public function demoUserBackToEnglish(Login $event): void
@@ -272,13 +271,8 @@ class UserEventHandler
* This method will send the user a registration mail, welcoming him or her to Firefly III.
* This message is only sent when the configuration of Firefly III says so.
*
* TODO this is an admin setting not a variable. Fix that first.
*
* @param RegisteredUser $event
*
* @return bool
* @throws FireflyException
* @deprecated
*/
public function sendRegistrationMail(RegisteredUser $event): void
{
@@ -290,7 +284,6 @@ class UserEventHandler
/**
* @param RegisteredUser $event
* @return void
*/
public function sendAdminRegistrationNotification(RegisteredUser $event): void
{
@@ -357,9 +350,10 @@ class UserEventHandler
];
}
$preference = array_values($preference);
$send = app('preferences')->getForUser($user, 'notification_user_login', true)->data;
app('preferences')->setForUser($user, 'login_ip_history', $preference);
if (false === $inArray && true === config('firefly.warn_new_ip')) {
if (false === $inArray && true === $send) {
event(new DetectedNewIPAddress($user, $ip));
}