refactor backup download

This commit is contained in:
Andras Bacsai 2024-04-29 11:31:50 +02:00
parent 360f5db2cf
commit 6bb05a6780

View File

@ -218,7 +218,7 @@
// Route::get('/security', fn () => view('security.index'))->name('security.index'); // Route::get('/security', fn () => view('security.index'))->name('security.index');
Route::get('/security/private-key', fn () => view('security.private-key.index', [ Route::get('/security/private-key', fn () => view('security.private-key.index', [
'privateKeys' => PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related','description'])->get() 'privateKeys' => PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related', 'description'])->get()
]))->name('security.private-key.index'); ]))->name('security.private-key.index');
// Route::get('/security/private-key/new', SecurityPrivateKeyCreate::class)->name('security.private-key.create'); // Route::get('/security/private-key/new', SecurityPrivateKeyCreate::class)->name('security.private-key.create');
Route::get('/security/private-key/{private_key_uuid}', SecurityPrivateKeyShow::class)->name('security.private-key.show'); Route::get('/security/private-key/{private_key_uuid}', SecurityPrivateKeyShow::class)->name('security.private-key.show');
@ -247,10 +247,16 @@
Route::get('/download/backup/{executionId}', function () { Route::get('/download/backup/{executionId}', function () {
try { try {
$team = auth()->user()->currentTeam(); $team = auth()->user()->currentTeam();
if (is_null($team)) {
return response()->json(['message' => 'Team not found.'], 404);
}
$exeuctionId = request()->route('executionId'); $exeuctionId = request()->route('executionId');
$execution = ScheduledDatabaseBackupExecution::where('id', $exeuctionId)->firstOrFail(); $execution = ScheduledDatabaseBackupExecution::where('id', $exeuctionId)->firstOrFail();
// // get team $execution_team_id = $execution->scheduledDatabaseBackup->database->team()?->id;
if ($team->id !== $execution->scheduledDatabaseBackup->database->team()->id) { if (is_null($execution_team_id)) {
return response()->json(['message' => 'Team not found.'], 404);
}
if ($team->id !== $execution_team_id) {
return response()->json(['message' => 'Permission denied.'], 403); return response()->json(['message' => 'Permission denied.'], 403);
} }
if (is_null($execution)) { if (is_null($execution)) {