Expand notifications.

This commit is contained in:
James Cole
2022-09-24 08:23:07 +02:00
parent 416fe0c147
commit 665b78ebf5
11 changed files with 273 additions and 74 deletions

View File

@@ -33,15 +33,16 @@ use FireflyIII\Events\RequestedNewPassword;
use FireflyIII\Events\UserChangedEmail; use FireflyIII\Events\UserChangedEmail;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Mail\ConfirmEmailChangeMail; use FireflyIII\Mail\ConfirmEmailChangeMail;
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
use FireflyIII\Mail\UndoEmailChangeMail; use FireflyIII\Mail\UndoEmailChangeMail;
use FireflyIII\Models\GroupMembership; use FireflyIII\Models\GroupMembership;
use FireflyIII\Models\UserGroup; use FireflyIII\Models\UserGroup;
use FireflyIII\Models\UserRole; use FireflyIII\Models\UserRole;
use FireflyIII\Notifications\Admin\UserRegistration as AdminRegistrationNotification;
use FireflyIII\Notifications\User\UserLogin; use FireflyIII\Notifications\User\UserLogin;
use FireflyIII\Notifications\User\UserNewPassword; use FireflyIII\Notifications\User\UserNewPassword;
use FireflyIII\Notifications\User\UserRegistration as UserRegistrationNotification;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Facades\FireflyConfig;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Auth\Events\Login; use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
@@ -281,26 +282,28 @@ class UserEventHandler
*/ */
public function sendRegistrationMail(RegisteredUser $event): void public function sendRegistrationMail(RegisteredUser $event): void
{ {
$sendMail = config('firefly.send_registration_mail'); $sendMail = FireflyConfig::get('notification_user_new_reg', true)->data;
if ($sendMail) { if ($sendMail) {
// get the email address Notification::send($event->user, new UserRegistrationNotification);
$email = $event->user->email; }
$url = route('index'); }
// see if user has alternative email address: /**
$pref = app('preferences')->getForUser($event->user, 'remote_guard_alt_email'); * @param RegisteredUser $event
if (null !== $pref) { * @return void
$email = $pref->data; */
public function sendAdminRegistrationNotification(RegisteredUser $event): void
{
$sendMail = FireflyConfig::get('notification_admin_new_reg', true)->data;
if ($sendMail) {
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$all = $repository->all();
foreach ($all as $user) {
if ($repository->hasRole($user, 'owner')) {
Notification::send($user, new AdminRegistrationNotification($event->user));
}
} }
// send email.
try {
Mail::to($email)->send(new RegisteredUserMail($url));
} catch (Exception $e) { // @phpstan-ignore-line
Log::error($e->getMessage());
}
} }
} }

View File

@@ -26,6 +26,7 @@ use FireflyIII\Events\AdminRequestedTestMessage;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Support\Facades\FireflyConfig;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
@@ -68,9 +69,28 @@ class HomeController extends Controller
if (null !== $pref && is_string($pref->data)) { if (null !== $pref && is_string($pref->data)) {
$email = $pref->data; $email = $pref->data;
} }
Log::debug('Email is ', [$email]);
return view('admin.index', compact('title', 'mainTitleIcon', 'email')); // admin notification settings:
$notifications = [];
foreach (config('firefly.admin_notifications') as $item) {
$notifications[$item] = FireflyConfig::get(sprintf('notification_%s', $item), true)->data;
}
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications'));
}
public function notifications(Request $request): RedirectResponse
{
foreach (config('firefly.admin_notifications') as $item) {
$value = false;
if ($request->has(sprintf('notification_%s', $item))) {
$value = true;
}
FireflyConfig::set(sprintf('notification_%s',$item), $value);
}
session()->flash('success', (string) trans('firefly.notification_settings_saved'));
return redirect(route('admin.index'));
} }
/** /**

View File

@@ -22,7 +22,61 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Admin; namespace FireflyIII\Notifications\Admin;
class UserRegistration use FireflyIII\User;
{ use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class UserRegistration extends Notification
{
use Queueable;
private User $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* 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.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id])
->subject((string) trans('email.registered_subject_admin'));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
} }

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
/*
* UserRegistration.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\Notifications\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class UserRegistration extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
}
/**
* 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.registered', ['address' => route('index')])
->subject((string) trans('email.registered_subject'));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}

View File

@@ -73,6 +73,7 @@ class EventServiceProvider extends ServiceProvider
// is a User related event. // is a User related event.
RegisteredUser::class => [ RegisteredUser::class => [
'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail', 'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail',
'FireflyIII\Handlers\Events\UserEventHandler@sendAdminRegistrationNotification',
'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole', 'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole',
'FireflyIII\Handlers\Events\UserEventHandler@createGroupMembership', 'FireflyIII\Handlers\Events\UserEventHandler@createGroupMembership',
'FireflyIII\Handlers\Events\UserEventHandler@createExchangeRates', 'FireflyIII\Handlers\Events\UserEventHandler@createExchangeRates',

View File

@@ -145,7 +145,8 @@ return [
'update_minimum_age' => 7, 'update_minimum_age' => 7,
// notifications // notifications
'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'], 'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'],
'admin_notifications' => ['admin_new_reg', 'user_new_reg'],
// enabled languages // enabled languages
'languages' => [ 'languages' => [

View File

@@ -49,6 +49,8 @@ return [
// registered // registered
'registered_subject' => 'Welcome to Firefly III!', 'registered_subject' => 'Welcome to Firefly III!',
'registered_subject_admin' => 'A new user has registered',
'admin_new_user_registered' => 'A new user has registered. User **:email** was given user ID #:id.',
'registered_welcome' => 'Welcome to [Firefly III](:address). Your registration has made it, and this email is here to confirm it. Yay!', 'registered_welcome' => 'Welcome to [Firefly III](:address). Your registration has made it, and this email is here to confirm it. Yay!',
'registered_pw' => 'If you have forgotten your password already, please reset it using [the password reset tool](:address/password/reset).', 'registered_pw' => 'If you have forgotten your password already, please reset it using [the password reset tool](:address/password/reset).',
'registered_help' => 'There is a help-icon in the top right corner of each page. If you need help, click it!', 'registered_help' => 'There is a help-icon in the top right corner of each page. If you need help, click it!',

View File

@@ -1936,55 +1936,62 @@ return [
'updated_tag' => 'Updated tag ":tag"', 'updated_tag' => 'Updated tag ":tag"',
'created_tag' => 'Tag ":tag" has been created!', 'created_tag' => 'Tag ":tag" has been created!',
'transaction_journal_information' => 'Transaction information', 'transaction_journal_information' => 'Transaction information',
'transaction_journal_meta' => 'Meta information', 'transaction_journal_meta' => 'Meta information',
'transaction_journal_more' => 'More information', 'transaction_journal_more' => 'More information',
'basic_journal_information' => 'Basic transaction information', 'basic_journal_information' => 'Basic transaction information',
'transaction_journal_extra' => 'Extra information', 'transaction_journal_extra' => 'Extra information',
'att_part_of_journal' => 'Stored under ":journal"', 'att_part_of_journal' => 'Stored under ":journal"',
'total_amount' => 'Total amount', 'total_amount' => 'Total amount',
'number_of_decimals' => 'Number of decimals', 'number_of_decimals' => 'Number of decimals',
// administration // administration
'administration' => 'Administration', 'administration' => 'Administration',
'user_administration' => 'User administration', 'user_administration' => 'User administration',
'list_all_users' => 'All users', 'list_all_users' => 'All users',
'all_users' => 'All users', 'all_users' => 'All users',
'instance_configuration' => 'Configuration', 'instance_configuration' => 'Configuration',
'firefly_instance_configuration' => 'Configuration options for Firefly III', 'firefly_instance_configuration' => 'Configuration options for Firefly III',
'setting_single_user_mode' => 'Single user mode', 'setting_single_user_mode' => 'Single user mode',
'setting_single_user_mode_explain' => 'By default, Firefly III only accepts one (1) registration: you. This is a security measure, preventing others from using your instance unless you allow them to. Future registrations are blocked. When you uncheck this box, others can use your instance as well, assuming they can reach it (when it is connected to the internet).', 'setting_single_user_mode_explain' => 'By default, Firefly III only accepts one (1) registration: you. This is a security measure, preventing others from using your instance unless you allow them to. Future registrations are blocked. When you uncheck this box, others can use your instance as well, assuming they can reach it (when it is connected to the internet).',
'store_configuration' => 'Store configuration', 'store_configuration' => 'Store configuration',
'single_user_administration' => 'User administration for :email', 'single_user_administration' => 'User administration for :email',
'edit_user' => 'Edit user :email', 'edit_user' => 'Edit user :email',
'hidden_fields_preferences' => 'You can enable more transaction options in your <a href="preferences">preferences</a>.', 'hidden_fields_preferences' => 'You can enable more transaction options in your <a href="preferences">preferences</a>.',
'user_data_information' => 'User data', 'user_data_information' => 'User data',
'user_information' => 'User information', 'user_information' => 'User information',
'total_size' => 'total size', 'total_size' => 'total size',
'budget_or_budgets' => ':count budget|:count budgets', 'budget_or_budgets' => ':count budget|:count budgets',
'budgets_with_limits' => ':count budget with configured amount|:count budgets with configured amount', 'budgets_with_limits' => ':count budget with configured amount|:count budgets with configured amount',
'nr_of_rules_in_total_groups' => ':count_rules rule(s) in :count_groups rule group(s)', 'nr_of_rules_in_total_groups' => ':count_rules rule(s) in :count_groups rule group(s)',
'tag_or_tags' => ':count tag|:count tags', 'tag_or_tags' => ':count tag|:count tags',
'configuration_updated' => 'The configuration has been updated', 'configuration_updated' => 'The configuration has been updated',
'setting_is_demo_site' => 'Demo site', 'setting_is_demo_site' => 'Demo site',
'setting_is_demo_site_explain' => 'If you check this box, this installation will behave as if it is the demo site, which can have weird side effects.', 'setting_is_demo_site_explain' => 'If you check this box, this installation will behave as if it is the demo site, which can have weird side effects.',
'block_code_bounced' => 'Email message(s) bounced', 'block_code_bounced' => 'Email message(s) bounced',
'block_code_expired' => 'Demo account expired', 'block_code_expired' => 'Demo account expired',
'no_block_code' => 'No reason for block or user not blocked', 'no_block_code' => 'No reason for block or user not blocked',
'block_code_email_changed' => 'User has not yet confirmed new email address', 'block_code_email_changed' => 'User has not yet confirmed new email address',
'admin_update_email' => 'Contrary to the profile page, the user will NOT be notified their email address has changed!', 'admin_update_email' => 'Contrary to the profile page, the user will NOT be notified their email address has changed!',
'update_user' => 'Update user', 'update_user' => 'Update user',
'updated_user' => 'User data has been changed.', 'updated_user' => 'User data has been changed.',
'delete_user' => 'Delete user :email', 'delete_user' => 'Delete user :email',
'user_deleted' => 'The user has been deleted', 'user_deleted' => 'The user has been deleted',
'send_test_email' => 'Send test email message', 'send_test_email' => 'Send test email message',
'send_test_email_text' => 'To see if your installation is capable of sending email, please press this button. You will not see an error here (if any), <strong>the log files will reflect any errors</strong>. You can press this button as many times as you like. There is no spam control. The message will be sent to <code>:email</code> and should arrive shortly.', 'send_test_email_text' => 'To see if your installation is capable of sending email, please press this button. You will not see an error here (if any), <strong>the log files will reflect any errors</strong>. You can press this button as many times as you like. There is no spam control. The message will be sent to <code>:email</code> and should arrive shortly.',
'send_message' => 'Send message', 'send_message' => 'Send message',
'send_test_triggered' => 'Test was triggered. Check your inbox and the log files.', 'send_test_triggered' => 'Test was triggered. Check your inbox and the log files.',
'give_admin_careful' => 'Users who are given admin rights can take away yours. Be careful.', 'give_admin_careful' => 'Users who are given admin rights can take away yours. Be careful.',
'admin_maintanance_title' => 'Maintenance', 'admin_maintanance_title' => 'Maintenance',
'admin_maintanance_expl' => 'Some nifty buttons for Firefly III maintenance', 'admin_maintanance_expl' => 'Some nifty buttons for Firefly III maintenance',
'admin_maintenance_clear_cache' => 'Clear cache', 'admin_maintenance_clear_cache' => 'Clear cache',
'admin_notifications' => 'Admin notifications',
'admin_notifications_expl' => 'The following notifications can be enabled or disabled by the administrator.',
'admin_notification_check_user_new_reg' => 'User gets post-registration welcome message',
'admin_notification_check_admin_new_reg' => 'Administrator(s) get new user registration notification',
'save_notification_settings' => 'Save settings',
'notification_settings_saved' => 'The notification settings have been saved',
'split_transaction_title' => 'Description of the split transaction', 'split_transaction_title' => 'Description of the split transaction',
'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.', 'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.',

View File

@@ -12,7 +12,9 @@
</div> </div>
<div class="box-body"> <div class="box-body">
<ul> <ul>
<li><a href="{{ route('admin.configuration.index') }}">{{ 'firefly_instance_configuration'|_ }}</a></li> <li>
<a href="{{ route('admin.configuration.index') }}">{{ 'firefly_instance_configuration'|_ }}</a>
</li>
<li><a href="{{ route('admin.links.index') }}">{{ 'journal_link_configuration'|_ }}</a></li> <li><a href="{{ route('admin.links.index') }}">{{ 'journal_link_configuration'|_ }}</a></li>
<li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li> <li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li>
</ul> </ul>
@@ -28,6 +30,31 @@
</ul> </ul>
</div> </div>
</div> </div>
<form action="{{ route('admin.notifications') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">{{ 'admin_notifications'|_ }}</h3>
</div>
<div class="box-body">
<p>
{{ 'admin_notifications_expl'|_ }}
</p>
{% for notification, value in notifications %}
<div class="checkbox">
<label>
<input value="1" {% if true == value %}checked{% endif %} type="checkbox" name="notification_{{ notification }}"> {{ trans('firefly.admin_notification_check_'~notification) }}
</label>
</div>
{% endfor %}
</div>
<div class="box-footer">
<button type="submit" class="btn btn-success">
<span class="fa fa-check-circle"></span> {{ ('save_notification_settings')|_ }}
</button>
</div>
</div>
</form>
</div> </div>
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12"> <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
<div class="box box-default"> <div class="box box-default">
@@ -35,11 +62,11 @@
<h3 class="box-title">{{ 'send_test_email'|_ }}</h3> <h3 class="box-title">{{ 'send_test_email'|_ }}</h3>
</div> </div>
<form action="{{ route('admin.test-message') }}" method="post"> <form action="{{ route('admin.test-message') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="box-body"> <div class="box-body">
<p> <p>
{{ trans('firefly.send_test_email_text', {email:email})|raw }} {{ trans('firefly.send_test_email_text', {email:email})|raw }}
</p> </p>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div> </div>
<div class="box-footer"> <div class="box-footer">
<button type="submit" class="btn btn-success"> <button type="submit" class="btn btn-success">
@@ -57,7 +84,8 @@
{{ 'admin_maintanance_expl'|_ }} {{ 'admin_maintanance_expl'|_ }}
</p> </p>
<p> <p>
<a href="{{ route('flush') }}" class="btn btn-warning">{{ 'admin_maintenance_clear_cache'|_ }}</a> <a href="{{ route('flush') }}"
class="btn btn-warning">{{ 'admin_maintenance_clear_cache'|_ }}</a>
</p> </p>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,3 @@
@component('mail::message')
{{ trans('email.admin_new_user_registered', ['id' => $id,'email' => $email]) }}
@endcomponent

View File

@@ -1085,6 +1085,7 @@ Route::group(
// admin home // admin home
Route::get('', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('', ['uses' => 'HomeController@index', 'as' => 'index']);
Route::post('test-message', ['uses' => 'HomeController@testMessage', 'as' => 'test-message']); Route::post('test-message', ['uses' => 'HomeController@testMessage', 'as' => 'test-message']);
Route::post('notifications', ['uses' => 'HomeController@notifications', 'as' => 'notifications']);
// check for updates? // check for updates?
Route::get('update-check', ['uses' => 'UpdateController@index', 'as' => 'update-check']); Route::get('update-check', ['uses' => 'UpdateController@index', 'as' => 'update-check']);