-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ability to delete individual backup task logs
- Loading branch information
1 parent
0ba209e
commit 7c5d5a4
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Livewire\BackupTasks; | ||
|
||
use App\Models\BackupTaskLog; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Routing\Redirector; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
use Masmerise\Toaster\Toaster; | ||
|
||
class DeleteBackupTaskLogButton extends Component | ||
{ | ||
public BackupTaskLog $backupTaskLog; | ||
|
||
public function mount(BackupTaskLog $backupTaskLog): void | ||
{ | ||
$this->backupTaskLog = $backupTaskLog; | ||
} | ||
|
||
public function delete(): RedirectResponse|Redirector | ||
{ | ||
$this->authorize('forceDelete', $this->backupTaskLog->backupTask); | ||
|
||
$this->backupTaskLog->forceDelete(); | ||
|
||
Toaster::success('Backup task log has been removed.'); | ||
|
||
$this->dispatch('refreshBackupTaskHistory'); | ||
|
||
return Redirect::route('backup-tasks.index'); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.backup-tasks.delete-backup-task-log-button'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
resources/views/livewire/backup-tasks/delete-backup-task-log-button.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<div> | ||
<x-modal name="backup-task-remove-historic-log-{{ $backupTaskLog->id }}"> | ||
<div class="p-6"> | ||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100"> | ||
{{ __('Clear Backup Task Log - :label', ['label' => $backupTaskLog->backupTask->label]) }} | ||
</h2> | ||
<p class="text-gray-800 dark:text-gray-200 my-3"> | ||
{{ __('Are you sure you want to clear this log?') }} | ||
</p> | ||
<p class="text-gray-800 dark:text-gray-200 my-3"> | ||
{{ __('The backup data will still exist at your backup destination, however there will be no record of this within :app.', ['app' => config('app.name')]) }} | ||
</p> | ||
<div class="flex space-x-5"> | ||
<div class="w-4/6"> | ||
<x-danger-button type="button" wire:click="delete" class="mt-4" centered | ||
wire:loading.attr="disabled" | ||
wire:loading.class="opacity-50 cursor-not-allowed"> | ||
|
||
<div wire:loading wire:target="delete"> | ||
<x-spinner class="mr-2 text-white h-4 w-4 inline"/> | ||
{{ __('Clearing...') }} | ||
</div> | ||
|
||
<div wire:loading.remove wire:target="delete"> | ||
{{ __('Confirm') }} | ||
</div> | ||
</x-danger-button> | ||
</div> | ||
<div class="w-2/6 ml-2"> | ||
<x-secondary-button type="button" class="mt-4" centered x-on:click="$dispatch('close')"> | ||
{{ __('Cancel') }} | ||
</x-secondary-button> | ||
</div> | ||
</div> | ||
</div> | ||
</x-modal> | ||
</div> |
53 changes: 53 additions & 0 deletions
53
tests/Feature/BackupTasks/Livewire/DeleteBackupTaskLogButtonTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use App\Livewire\BackupTasks\DeleteBackupTaskLogButton; | ||
use App\Models\BackupTask; | ||
use App\Models\BackupTaskLog; | ||
use App\Models\User; | ||
|
||
test('the component can be rendered', function () { | ||
|
||
$backupTask = BackupTask::factory()->create(); | ||
$log = BackupTaskLog::factory()->create(['backup_task_id' => $backupTask->id]); | ||
Livewire::test(DeleteBackupTaskLogButton::class, ['backupTaskLog' => $log]) | ||
->assertOk(); | ||
}); | ||
|
||
test('the authorized user can delete a task log', function () { | ||
\Masmerise\Toaster\Toaster::fake(); | ||
|
||
$user = User::factory()->create(); | ||
$task = BackupTask::factory()->create(['user_id' => $user->id]); | ||
$log = BackupTaskLog::factory()->create(['backup_task_id' => $task->id]); | ||
|
||
$component = Livewire::actingAs($user) | ||
->test(DeleteBackupTaskLogButton::class, ['backupTaskLog' => $log]) | ||
->call('delete') | ||
->assertRedirect(route('backup-tasks.index')); | ||
|
||
$this->assertModelMissing($log); | ||
$this->assertAuthenticatedAs($user); | ||
|
||
Toaster::assertDispatched(__('Backup task log has been removed.')); | ||
|
||
$component->assertDispatched('refreshBackupTaskHistory'); | ||
}); | ||
|
||
test('an unauthorized user cannot delete a task log', function () { | ||
|
||
$user = User::factory()->create(); | ||
$anotherUser = User::factory()->create(); | ||
|
||
$task = BackupTask::factory()->create(['user_id' => $anotherUser->id]); | ||
|
||
$log = BackupTaskLog::factory()->create(['backup_task_id' => $task->id]); | ||
|
||
Livewire::actingAs($user) | ||
->test(DeleteBackupTaskLogButton::class, ['backupTaskLog' => $log]) | ||
->call('delete') | ||
->assertForbidden(); | ||
|
||
$this->assertDatabaseHas('backup_task_logs', ['id' => $log->id]); | ||
|
||
$this->assertAuthenticatedAs($user); | ||
}); |