mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add notifications.
This commit is contained in:
parent
665b78ebf5
commit
be1dff49fa
41
app/Events/NewVersionAvailable.php
Normal file
41
app/Events/NewVersionAvailable.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/*
|
||||
* NewVersionAvailable.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NewVersionAvailable extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public string $message;
|
||||
|
||||
/**
|
||||
* Create a new event instance. This event is triggered when a new version is available.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct(string $message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,67 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\Admin;
|
||||
|
||||
class VersionCheckResult
|
||||
{
|
||||
use FireflyIII\Models\Bill;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* Class VersionCheckResult
|
||||
*
|
||||
*/
|
||||
class VersionCheckResult extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private string $message;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
|
||||
return (new MailMessage)
|
||||
->markdown('emails.new-version', ['message' => $this->message])
|
||||
->subject((string)trans('email.new_version_email_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Events\DestroyedTransactionGroup;
|
||||
use FireflyIII\Events\DetectedNewIPAddress;
|
||||
use FireflyIII\Events\NewVersionAvailable;
|
||||
use FireflyIII\Events\RegisteredUser;
|
||||
use FireflyIII\Events\RequestedNewPassword;
|
||||
use FireflyIII\Events\RequestedReportOnJournals;
|
||||
@ -109,6 +110,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
AdminRequestedTestMessage::class => [
|
||||
'FireflyIII\Handlers\Events\AdminEventHandler@sendTestMessage',
|
||||
],
|
||||
NewVersionAvailable::class => [
|
||||
'FireflyIII\Handlers\Events\AdminEventHandler@sendNewVersion',
|
||||
],
|
||||
// is a Transaction Journal related event.
|
||||
StoredTransactionGroup::class => [
|
||||
'FireflyIII\Handlers\Events\StoredGroupEventHandler@processRules',
|
||||
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Services\FireflyIIIOrg\Update;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Events\NewVersionAvailable;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JsonException;
|
||||
@ -168,6 +169,7 @@ class UpdateRequest implements UpdateRequestInterface
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
// a newer version is available!
|
||||
/** @var Carbon $released */
|
||||
$released = $information['date'];
|
||||
@ -189,7 +191,7 @@ class UpdateRequest implements UpdateRequestInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
// its been around for a while:
|
||||
// it's been around for a while:
|
||||
$return['level'] = 'success';
|
||||
$return['message'] = (string) trans(
|
||||
'firefly.update_new_version_alert',
|
||||
@ -215,6 +217,9 @@ class UpdateRequest implements UpdateRequestInterface
|
||||
}
|
||||
Log::debug('New release is here!', $return);
|
||||
|
||||
// send event, this may result in a notification.
|
||||
event(new NewVersionAvailable($return['message']));
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ return [
|
||||
|
||||
// notifications
|
||||
'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'],
|
||||
'admin_notifications' => ['admin_new_reg', 'user_new_reg'],
|
||||
'admin_notifications' => ['admin_new_reg', 'user_new_reg', 'new_version'],
|
||||
|
||||
// enabled languages
|
||||
'languages' => [
|
||||
|
@ -61,6 +61,9 @@ return [
|
||||
'registered_pw_reset_link' => 'Password reset:',
|
||||
'registered_doc_link' => 'Documentation:',
|
||||
|
||||
// new version
|
||||
'new_version_email_subject' => 'A new Firefly III version is available',
|
||||
|
||||
// email change
|
||||
'email_change_subject' => 'Your Firefly III email address has changed',
|
||||
'email_change_body_to_new' => 'You or somebody with access to your Firefly III account has changed your email address. If you did not expect this message, please ignore and delete it.',
|
||||
|
6
resources/views/emails/new-version.blade.php
Normal file
6
resources/views/emails/new-version.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
@component('mail::message')
|
||||
{{ $message }}
|
||||
|
||||
[Firefly III @ GitHub](https://github.com/firefly-iii/firefly-iii/releases)
|
||||
|
||||
@endcomponent
|
Loading…
Reference in New Issue
Block a user