refactor(databases): streamline backup queries to use team context
- Updated backup retrieval logic in DatabasesController to utilize the new ownedByCurrentTeam method for improved access control. - Enhanced code readability and maintainability by centralizing team-based filtering in the ScheduledDatabaseBackup model.
This commit is contained in:
parent
5c6ab50332
commit
bb06a74fee
2 changed files with 9 additions and 4 deletions
|
|
@ -718,7 +718,7 @@ public function update_backup(Request $request)
|
|||
return response()->json(['message' => 'Database not found.'], 404);
|
||||
}
|
||||
|
||||
$backupConfig = ScheduledDatabaseBackup::where('team_id', $teamId)->where('database_id', $database->id)
|
||||
$backupConfig = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
||||
->where('uuid', $request->scheduled_backup_uuid)
|
||||
->first();
|
||||
if (! $backupConfig) {
|
||||
|
|
@ -1951,7 +1951,7 @@ public function delete_backup_by_uuid(Request $request)
|
|||
}
|
||||
|
||||
// Find the backup configuration by its UUID
|
||||
$backup = ScheduledDatabaseBackup::where('team_id', $teamId)->where('database_id', $database->id)
|
||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
||||
->where('uuid', $request->scheduled_backup_uuid)
|
||||
->first();
|
||||
|
||||
|
|
@ -2072,7 +2072,7 @@ public function delete_execution_by_uuid(Request $request)
|
|||
}
|
||||
|
||||
// Find the backup configuration by its UUID
|
||||
$backup = ScheduledDatabaseBackup::where('team_id', $teamId)->where('database_id', $database->id)
|
||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
||||
->where('uuid', $request->scheduled_backup_uuid)
|
||||
->first();
|
||||
|
||||
|
|
@ -2180,7 +2180,7 @@ public function list_backup_executions(Request $request)
|
|||
}
|
||||
|
||||
// Find the backup configuration by its UUID
|
||||
$backup = ScheduledDatabaseBackup::where('team_id', $teamId)->where('database_id', $database->id)
|
||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
||||
->where('uuid', $request->scheduled_backup_uuid)
|
||||
->first();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ class ScheduledDatabaseBackup extends BaseModel
|
|||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public static function ownedByCurrentTeam()
|
||||
{
|
||||
return ScheduledDatabaseBackup::whereRelation('team', 'id', currentTeam()->id)->orderBy('name');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo(Team::class);
|
||||
|
|
|
|||
Loading…
Reference in a new issue