refactor(policies): add uploadBackup ability and enforce it on backup upload endpoint

Introduce a dedicated `uploadBackup` ability on Application, Database,
Service, and ServiceDatabase policies (admin/owner only) and call
`$this->authorize('uploadBackup', $resource)` in `UploadController::upload`
so the backup-upload endpoint goes through the same policy layer as the
rest of the authorization refactor. Adds Pest coverage for each policy
variant plus HTTP-level checks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Andras BacsaiandClaude Opus 4.7 committed 2026-04-20 11:51:35 +02:00
1 parent 8a715489cb
commit 6a5fd40a5c
6 files changed
+246

No files matched your search

+18
View File
@@ -78,6 +78,24 @@ class ApplicationPolicy
return false;
}
/**
* Determine whether the user can upload a backup archive for this application.
*/
public function uploadBackup(User $user, Application $application): Response
{
$teamId = $this->getTeamId($application);
if ($teamId === null) {
return Response::deny('Application team not found.');
}
if ($user->isAdminOfTeam($teamId)) {
return Response::allow();
}
return Response::deny('You need at least admin or owner permissions to upload backups for this application.');
}
/**
* Determine whether the user can deploy the application.
*/