feat(dev patches): add functionality to send test email with patch data in development mode
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Actions\Server\CheckUpdates;
|
|||||||
use App\Actions\Server\UpdatePackage;
|
use App\Actions\Server\UpdatePackage;
|
||||||
use App\Events\ServerPackageUpdated;
|
use App\Events\ServerPackageUpdated;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Notifications\Server\ServerPatchCheck;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Patches extends 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()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.server.security.patches');
|
return view('livewire.server.security.patches');
|
||||||
|
@@ -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>." />
|
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')">
|
<x-forms.button type="button" wire:click="$dispatch('checkForUpdatesDispatch')">
|
||||||
Check Now</x-forms.button>
|
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>
|
||||||
<div>Update your servers semi-automatically.</div>
|
<div>Update your servers semi-automatically.</div>
|
||||||
<div>
|
<div>
|
||||||
|
Reference in New Issue
Block a user