diff --git a/app/Filament/Admin/Pages/Settings.php b/app/Filament/Admin/Pages/Settings.php index 7449dba86..424b4a795 100644 --- a/app/Filament/Admin/Pages/Settings.php +++ b/app/Filament/Admin/Pages/Settings.php @@ -683,6 +683,36 @@ class Settings extends Page implements HasSchemas ->collapsible() ->collapsed() ->schema([ + Toggle::make('PANEL_SEND_ACCOUNT_CREATED_NOTIFICATION') + ->label(trans('admin/setting.misc.mail_notifications.account_created')) + ->onIcon(TablerIcon::Check) + ->offIcon(TablerIcon::X) + ->onColor('success') + ->offColor('danger') + ->live() + ->formatStateUsing(fn ($state): bool => (bool) $state) + ->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_ACCOUNT_CREATED_NOTIFICATION', (bool) $state)) + ->default(env('PANEL_SEND_ACCOUNT_CREATED_NOTIFICATION', config('panel.email.send_account_created_notification'))), + Toggle::make('PANEL_SEND_ADDED_TO_SERVER_NOTIFICATION') + ->label(trans('admin/setting.misc.mail_notifications.added_to_server')) + ->onIcon(TablerIcon::Check) + ->offIcon(TablerIcon::X) + ->onColor('success') + ->offColor('danger') + ->live() + ->formatStateUsing(fn ($state): bool => (bool) $state) + ->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_ADDED_TO_SERVER_NOTIFICATION', (bool) $state)) + ->default(env('PANEL_SEND_ADDED_TO_SERVER_NOTIFICATION', config('panel.email.send_added_to_server_notification'))), + Toggle::make('PANEL_SEND_REMOVED_FROM_SERVER_NOTIFICATION') + ->label(trans('admin/setting.misc.mail_notifications.removed_from_server')) + ->onIcon(TablerIcon::Check) + ->offIcon(TablerIcon::X) + ->onColor('success') + ->offColor('danger') + ->live() + ->formatStateUsing(fn ($state): bool => (bool) $state) + ->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_SEND_REMOVED_FROM_SERVER_NOTIFICATION', (bool) $state)) + ->default(env('PANEL_SEND_REMOVED_FROM_SERVER_NOTIFICATION', config('panel.email.send_removed_from_server_notification'))), Toggle::make('PANEL_SEND_INSTALL_NOTIFICATION') ->label(trans('admin/setting.misc.mail_notifications.server_installed')) ->onIcon(TablerIcon::Check) diff --git a/app/Listeners/Server/SubUserAddedListener.php b/app/Listeners/Server/SubUserAddedListener.php index 22121e9cb..8f7067782 100644 --- a/app/Listeners/Server/SubUserAddedListener.php +++ b/app/Listeners/Server/SubUserAddedListener.php @@ -29,6 +29,8 @@ class SubUserAddedListener ]) ->sendToDatabase($event->subuser->user); - $event->subuser->user->notify(new AddedToServer($event->subuser->server)); + if (config('panel.email.send_added_to_server_notification', true)) { + $event->subuser->user->notify(new AddedToServer($event->subuser->server)); + } } } diff --git a/app/Listeners/Server/SubUserRemovedListener.php b/app/Listeners/Server/SubUserRemovedListener.php index 1ad964afc..d88a129a0 100644 --- a/app/Listeners/Server/SubUserRemovedListener.php +++ b/app/Listeners/Server/SubUserRemovedListener.php @@ -17,6 +17,8 @@ class SubUserRemovedListener ->body(trans('notifications.user_removed.body', ['server' => $event->server->name], $locale)) ->sendToDatabase($event->user); - $event->user->notify(new RemovedFromServer($event->server)); + if (config('panel.email.send_removed_from_server_notification', true)) { + $event->user->notify(new RemovedFromServer($event->server)); + } } } diff --git a/app/Services/Users/UserCreationService.php b/app/Services/Users/UserCreationService.php index 53efb4933..2af9503ac 100644 --- a/app/Services/Users/UserCreationService.php +++ b/app/Services/Users/UserCreationService.php @@ -66,7 +66,9 @@ class UserCreationService $this->connection->commit(); - $user->notify(new AccountCreated($token ?? null)); + if (config('panel.email.send_account_created_notification', true)) { + $user->notify(new AccountCreated($token ?? null)); + } return $user; } diff --git a/config/panel.php b/config/panel.php index 43ec75e2f..bfb70f13f 100644 --- a/config/panel.php +++ b/config/panel.php @@ -45,6 +45,12 @@ return [ ], 'email' => [ + // Should an email be sent to a new user when their account is created? + 'send_account_created_notification' => env('PANEL_SEND_ACCOUNT_CREATED_NOTIFICATION', true), + // Should an email be sent to a user when they are added as a subuser to a server? + 'send_added_to_server_notification' => env('PANEL_SEND_ADDED_TO_SERVER_NOTIFICATION', true), + // Should an email be sent to a user when they are removed as a subuser from a server? + 'send_removed_from_server_notification' => env('PANEL_SEND_REMOVED_FROM_SERVER_NOTIFICATION', true), // Should an email be sent to a server owner once their server has completed it's first install process? 'send_install_notification' => env('PANEL_SEND_INSTALL_NOTIFICATION', true), // Should an email be sent to a server owner whenever their server is reinstalled? diff --git a/lang/en/admin/setting.php b/lang/en/admin/setting.php index 88719e042..b7a278dfa 100644 --- a/lang/en/admin/setting.php +++ b/lang/en/admin/setting.php @@ -116,6 +116,9 @@ return [ 'mail_notifications' => [ 'title' => 'Mail Notifications', 'helper' => 'Toggle which mail notifications should be sent to Users.', + 'account_created' => 'Account Created', + 'added_to_server' => 'Added to Server', + 'removed_from_server' => 'Removed from Server', 'server_installed' => 'Server Installed', 'server_reinstalled' => 'Server Reinstalled', 'backup_completed' => 'Backup Completed',