feat(dev patches): add functionality to send test email with patch data in development mode

This commit is contained in:
Andras Bacsai
2025-08-17 17:58:38 +02:00
parent 58d865c751
commit 91cc52f81e
2 changed files with 88 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use App\Actions\Server\CheckUpdates;
use App\Actions\Server\UpdatePackage;
use App\Events\ServerPackageUpdated;
use App\Models\Server;
use App\Notifications\Server\ServerPatchCheck;
use Livewire\Component;
class Patches extends Component
@@ -96,6 +97,89 @@ class Patches extends Component
}
}
public function sendTestEmail()
{
if (! isDev()) {
$this->dispatch('error', message: 'Test email functionality is only available in development mode.');
return;
}
try {
// Get current patch data or create test data if none exists
$testPatchData = $this->createTestPatchData();
// Send test notification
$this->server->team->notify(new ServerPatchCheck($this->server, $testPatchData));
$this->dispatch('success', 'Test email sent successfully! Check your email inbox.');
} catch (\Exception $e) {
$this->dispatch('error', message: 'Failed to send test email: '.$e->getMessage());
}
}
private function createTestPatchData(): array
{
// If we have real patch data, use it
if (isset($this->updates) && is_array($this->updates) && count($this->updates) > 0) {
return [
'total_updates' => $this->totalUpdates,
'updates' => $this->updates,
'osId' => $this->osId,
'package_manager' => $this->packageManager,
];
}
// Otherwise create realistic test data
return [
'total_updates' => 8,
'updates' => [
[
'package' => 'docker-ce',
'current_version' => '24.0.7-1',
'new_version' => '25.0.1-1',
],
[
'package' => 'nginx',
'current_version' => '1.20.2-1',
'new_version' => '1.22.1-1',
],
[
'package' => 'kernel-generic',
'current_version' => '5.15.0-89',
'new_version' => '5.15.0-91',
],
[
'package' => 'openssh-server',
'current_version' => '8.9p1-3',
'new_version' => '9.0p1-1',
],
[
'package' => 'curl',
'current_version' => '7.81.0-1',
'new_version' => '7.85.0-1',
],
[
'package' => 'git',
'current_version' => '2.34.1-1',
'new_version' => '2.39.1-1',
],
[
'package' => 'python3',
'current_version' => '3.10.6-1',
'new_version' => '3.11.0-1',
],
[
'package' => 'htop',
'current_version' => '3.2.1-1',
'new_version' => '3.2.2-1',
],
],
'osId' => $this->osId ?? 'ubuntu',
'package_manager' => $this->packageManager ?? 'apt',
];
}
public function render()
{
return view('livewire.server.security.patches');

View File

@@ -22,6 +22,10 @@
soon.<br/>Status notifications sent every week.<br/>You can disable notifications in the <a class='dark:text-white underline' href='{{ route('notifications.email') }}'>notification settings</a>." />
<x-forms.button type="button" wire:click="$dispatch('checkForUpdatesDispatch')">
Check Now</x-forms.button>
@if (isDev())
<x-forms.button type="button" wire:click="sendTestEmail">
Send Test Email (dev only)</x-forms.button>
@endif
</div>
<div>Update your servers semi-automatically.</div>
<div>