fix: do not allow to delete env if a resource is defined
This commit is contained in:
@@ -21,10 +21,10 @@ class DeleteEnvironment extends Component
|
||||
'environment_id' => 'required|int',
|
||||
]);
|
||||
$environment = Environment::findOrFail($this->environment_id);
|
||||
if ($environment->applications->count() > 0) {
|
||||
return $this->emit('error', 'Environment has resources defined, please delete them first.');
|
||||
if ($environment->isEmpty()) {
|
||||
$environment->delete();
|
||||
return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
|
||||
}
|
||||
$environment->delete();
|
||||
return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
|
||||
return $this->emit('error', 'Environment has defined resources, please delete them first.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class Environment extends Model
|
||||
'project_id',
|
||||
];
|
||||
|
||||
public function can_delete_environment()
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->applications()->count() == 0 &&
|
||||
$this->redis()->count() == 0 &&
|
||||
|
||||
@@ -18,7 +18,7 @@ class Project extends BaseModel
|
||||
'project_id' => $project->id,
|
||||
]);
|
||||
Environment::create([
|
||||
'name' => 'Production',
|
||||
'name' => 'production',
|
||||
'project_id' => $project->id,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user