mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Scope resource permissions and related records to the owning team across team switches, cloning, deployments, and resource operations. Merge ClickHouse volume mounts, preserve anonymous data volumes on stop, and require adopting current data before starting or restarting. Fix file storage deletion checks and add regression coverage.
138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project;
|
|
|
|
use App\Models\Environment;
|
|
use App\Models\Project;
|
|
use App\Support\ValidationPatterns;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Component;
|
|
|
|
class Show extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public Project $project;
|
|
|
|
public string $name;
|
|
|
|
public ?string $description = null;
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'name' => ValidationPatterns::nameRules(),
|
|
'description' => ValidationPatterns::descriptionRules(),
|
|
];
|
|
}
|
|
|
|
protected function messages(): array
|
|
{
|
|
return ValidationPatterns::combinedMessages();
|
|
}
|
|
|
|
public function mount(string $project_uuid)
|
|
{
|
|
try {
|
|
$this->project = Project::where('team_id', currentTeam()->id)
|
|
->where('uuid', $project_uuid)
|
|
->with([
|
|
'environments' => fn ($query) => $query
|
|
->withCount([
|
|
'applications',
|
|
'services',
|
|
'postgresqls',
|
|
'redis',
|
|
'keydbs',
|
|
'dragonflies',
|
|
'clickhouses',
|
|
'mongodbs',
|
|
'mysqls',
|
|
'mariadbs',
|
|
'sqlites',
|
|
])
|
|
->orderBy('created_at'),
|
|
])
|
|
->firstOrFail();
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function submit()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->project);
|
|
$this->validate();
|
|
$environment = Environment::create([
|
|
'name' => $this->name,
|
|
'project_id' => $this->project->id,
|
|
'uuid' => new_public_id(),
|
|
]);
|
|
|
|
return redirectRoute($this, 'project.resource.index', [
|
|
'project_uuid' => $this->project->uuid,
|
|
'environment_uuid' => $environment->uuid,
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function navigateToEnvironment($projectUuid, $environmentUuid)
|
|
{
|
|
return redirectRoute($this, 'project.resource.index', [
|
|
'project_uuid' => $projectUuid,
|
|
'environment_uuid' => $environmentUuid,
|
|
]);
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
$canUpdateProject = auth()->user()->can('update', $this->project);
|
|
$canCreateResource = auth()->user()->can('createAnyResource');
|
|
|
|
return view('livewire.project.show', [
|
|
'environmentsJs' => $this->project->environments->map(function (Environment $environment) use ($canCreateResource, $canUpdateProject): array {
|
|
$resourceCount = collect([
|
|
$environment->applications_count,
|
|
$environment->services_count,
|
|
$environment->postgresqls_count,
|
|
$environment->redis_count,
|
|
$environment->keydbs_count,
|
|
$environment->dragonflies_count,
|
|
$environment->clickhouses_count,
|
|
$environment->mongodbs_count,
|
|
$environment->mysqls_count,
|
|
$environment->mariadbs_count,
|
|
$environment->sqlites_count,
|
|
])->sum();
|
|
|
|
return [
|
|
'uuid' => $environment->uuid,
|
|
'name' => $environment->name,
|
|
'description' => $environment->description,
|
|
'resourceCount' => $resourceCount,
|
|
'href' => route('project.resource.index', [
|
|
'project_uuid' => $this->project->uuid,
|
|
'environment_uuid' => $environment->uuid,
|
|
]),
|
|
'settingsHref' => $canUpdateProject
|
|
? route('project.environment.edit', [
|
|
'project_uuid' => $this->project->uuid,
|
|
'environment_uuid' => $environment->uuid,
|
|
])
|
|
: null,
|
|
'addResourceHref' => $canCreateResource
|
|
? route('project.resource.create', [
|
|
'project_uuid' => $this->project->uuid,
|
|
'environment_uuid' => $environment->uuid,
|
|
])
|
|
: null,
|
|
];
|
|
})->values()->toArray(),
|
|
]);
|
|
}
|
|
}
|