Merge pull request #3949 from peaklabs-dev/fix-project-deletion
Fix: Projects can be deleted with resources
This commit is contained in:
@@ -422,7 +422,7 @@ class ProjectController extends Controller
|
||||
if (! $project) {
|
||||
return response()->json(['message' => 'Project not found.'], 404);
|
||||
}
|
||||
if ($project->resource_count() > 0) {
|
||||
if (! $project->isEmpty()) {
|
||||
return response()->json(['message' => 'Project has resources, so it cannot be deleted.'], 400);
|
||||
}
|
||||
|
||||
|
@@ -37,6 +37,6 @@ class DeleteEnvironment extends Component
|
||||
return redirect()->route('project.show', parameters: ['project_uuid' => $this->parameters['project_uuid']]);
|
||||
}
|
||||
|
||||
return $this->dispatch('error', 'Environment has defined resources, please delete them first.');
|
||||
return $this->dispatch('error', "<strong>Environment {$environment->name}</strong> has defined resources, please delete them first.");
|
||||
}
|
||||
}
|
||||
|
@@ -27,11 +27,12 @@ class DeleteProject extends Component
|
||||
'project_id' => 'required|int',
|
||||
]);
|
||||
$project = Project::findOrFail($this->project_id);
|
||||
if ($project->applications->count() > 0) {
|
||||
return $this->dispatch('error', 'Project has resources defined, please delete them first.');
|
||||
}
|
||||
$project->delete();
|
||||
if ($project->isEmpty()) {
|
||||
$project->delete();
|
||||
|
||||
return redirect()->route('project.index');
|
||||
return redirect()->route('project.index');
|
||||
}
|
||||
|
||||
return $this->dispatch('error', "<strong>Project {$project->name}</strong> has resources defined, please delete them first.");
|
||||
}
|
||||
}
|
||||
|
@@ -122,9 +122,18 @@ class Project extends BaseModel
|
||||
return $this->hasManyThrough(StandaloneMariadb::class, Environment::class);
|
||||
}
|
||||
|
||||
public function resource_count()
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->applications()->count() + $this->postgresqls()->count() + $this->redis()->count() + $this->mongodbs()->count() + $this->mysqls()->count() + $this->mariadbs()->count() + $this->keydbs()->count() + $this->dragonflies()->count() + $this->clickhouses()->count() + $this->services()->count();
|
||||
return $this->applications()->count() == 0 &&
|
||||
$this->redis()->count() == 0 &&
|
||||
$this->postgresqls()->count() == 0 &&
|
||||
$this->mysqls()->count() == 0 &&
|
||||
$this->keydbs()->count() == 0 &&
|
||||
$this->dragonflies()->count() == 0 &&
|
||||
$this->clickhouses()->count() == 0 &&
|
||||
$this->mariadbs()->count() == 0 &&
|
||||
$this->mongodbs()->count() == 0 &&
|
||||
$this->services()->count() == 0;
|
||||
}
|
||||
|
||||
public function databases()
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<h1>Project: {{ data_get($project, 'name') }}</h1>
|
||||
<div class="flex items-end gap-2">
|
||||
<x-forms.button type="submit">Save</x-forms.button>
|
||||
<livewire:project.delete-project :disabled="$project->resource_count() > 0" :project_id="$project->id" />
|
||||
<livewire:project.delete-project :disabled="!$project->isEmpty()" :project_id="$project->id" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="pt-2 pb-10">Edit project details here.</div>
|
||||
|
@@ -12,7 +12,7 @@
|
||||
</x-forms.button>
|
||||
</form>
|
||||
</x-modal-input>
|
||||
<livewire:project.delete-project :disabled="$project->resource_count() > 0" :project_id="$project->id" />
|
||||
<livewire:project.delete-project :disabled="!$project->isEmpty()" :project_id="$project->id" />
|
||||
</div>
|
||||
<div class="text-xs truncate subtitle lg:text-sm">{{ $project->name }}.</div>
|
||||
<div class="grid gap-2 lg:grid-cols-2">
|
||||
|
Reference in New Issue
Block a user