refactor(databases): update backup queries to use team-specific method
- Modified backup retrieval logic in DatabasesController to utilize the new ownedByCurrentTeamAPI method for improved access control based on team ID. - Enhanced code consistency and maintainability by centralizing team-based filtering in the ScheduledDatabaseBackup model.
This commit is contained in:
@@ -85,7 +85,7 @@ class DatabasesController extends Controller
|
|||||||
|
|
||||||
$databaseIds = $databases->pluck('id')->toArray();
|
$databaseIds = $databases->pluck('id')->toArray();
|
||||||
|
|
||||||
$backupConfigs = ScheduledDatabaseBackup::with('latest_log')
|
$backupConfigs = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->with('latest_log')
|
||||||
->whereIn('database_id', $databaseIds)
|
->whereIn('database_id', $databaseIds)
|
||||||
->get()
|
->get()
|
||||||
->groupBy('database_id');
|
->groupBy('database_id');
|
||||||
@@ -159,7 +159,7 @@ class DatabasesController extends Controller
|
|||||||
|
|
||||||
$this->authorize('view', $database);
|
$this->authorize('view', $database);
|
||||||
|
|
||||||
$backupConfig = ScheduledDatabaseBackup::with('executions')->where('database_id', $database->id)->get();
|
$backupConfig = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->with('executions')->where('database_id', $database->id)->get();
|
||||||
|
|
||||||
return response()->json($backupConfig);
|
return response()->json($backupConfig);
|
||||||
}
|
}
|
||||||
@@ -718,7 +718,7 @@ class DatabasesController extends Controller
|
|||||||
return response()->json(['message' => 'Database not found.'], 404);
|
return response()->json(['message' => 'Database not found.'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$backupConfig = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
$backupConfig = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->where('database_id', $database->id)
|
||||||
->where('uuid', $request->scheduled_backup_uuid)
|
->where('uuid', $request->scheduled_backup_uuid)
|
||||||
->first();
|
->first();
|
||||||
if (! $backupConfig) {
|
if (! $backupConfig) {
|
||||||
@@ -1951,7 +1951,7 @@ class DatabasesController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the backup configuration by its UUID
|
// Find the backup configuration by its UUID
|
||||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
$backup = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->where('database_id', $database->id)
|
||||||
->where('uuid', $request->scheduled_backup_uuid)
|
->where('uuid', $request->scheduled_backup_uuid)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -2072,7 +2072,7 @@ class DatabasesController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the backup configuration by its UUID
|
// Find the backup configuration by its UUID
|
||||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
$backup = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->where('database_id', $database->id)
|
||||||
->where('uuid', $request->scheduled_backup_uuid)
|
->where('uuid', $request->scheduled_backup_uuid)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -2180,7 +2180,7 @@ class DatabasesController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the backup configuration by its UUID
|
// Find the backup configuration by its UUID
|
||||||
$backup = ScheduledDatabaseBackup::ownedByCurrentTeam()->where('database_id', $database->id)
|
$backup = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->where('database_id', $database->id)
|
||||||
->where('uuid', $request->scheduled_backup_uuid)
|
->where('uuid', $request->scheduled_backup_uuid)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
@@ -15,6 +15,11 @@ class ScheduledDatabaseBackup extends BaseModel
|
|||||||
return ScheduledDatabaseBackup::whereRelation('team', 'id', currentTeam()->id)->orderBy('name');
|
return ScheduledDatabaseBackup::whereRelation('team', 'id', currentTeam()->id)->orderBy('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ownedByCurrentTeamAPI(int $teamId)
|
||||||
|
{
|
||||||
|
return ScheduledDatabaseBackup::whereRelation('team', 'id', $teamId)->orderBy('name');
|
||||||
|
}
|
||||||
|
|
||||||
public function team()
|
public function team()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Team::class);
|
return $this->belongsTo(Team::class);
|
||||||
|
Reference in New Issue
Block a user