diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index edbdd25fe..18dbde0d3 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use App\Models\Application; use App\Models\ApplicationDeploymentQueue; use App\Models\PrivateKey; use App\Models\Project; @@ -30,6 +31,12 @@ class Dashboard extends Component public function cleanupQueue() { + try { + $this->authorize('cleanupDeploymentQueue', Application::class); + } catch (\Illuminate\Auth\Access\AuthorizationException $e) { + return handleError($e, $this); + } + Artisan::queue('cleanup:deployment-queue', [ '--team-id' => currentTeam()->id, ]); diff --git a/app/Livewire/Project/DeleteEnvironment.php b/app/Livewire/Project/DeleteEnvironment.php index 1ee5de269..e97206081 100644 --- a/app/Livewire/Project/DeleteEnvironment.php +++ b/app/Livewire/Project/DeleteEnvironment.php @@ -3,10 +3,13 @@ namespace App\Livewire\Project; use App\Models\Environment; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Livewire\Component; class DeleteEnvironment extends Component { + use AuthorizesRequests; + public int $environment_id; public bool $disabled = false; @@ -31,6 +34,8 @@ class DeleteEnvironment extends Component 'environment_id' => 'required|int', ]); $environment = Environment::findOrFail($this->environment_id); + $this->authorize('delete', $environment); + if ($environment->isEmpty()) { $environment->delete(); diff --git a/app/Livewire/Project/DeleteProject.php b/app/Livewire/Project/DeleteProject.php index f320a19b0..26b35b2e7 100644 --- a/app/Livewire/Project/DeleteProject.php +++ b/app/Livewire/Project/DeleteProject.php @@ -3,10 +3,13 @@ namespace App\Livewire\Project; use App\Models\Project; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Livewire\Component; class DeleteProject extends Component { + use AuthorizesRequests; + public array $parameters; public int $project_id; @@ -27,6 +30,8 @@ class DeleteProject extends Component 'project_id' => 'required|int', ]); $project = Project::findOrFail($this->project_id); + $this->authorize('delete', $project); + if ($project->isEmpty()) { $project->delete(); diff --git a/app/Livewire/Project/Resource/Create.php b/app/Livewire/Project/Resource/Create.php index 6d72f6191..3dbe4230c 100644 --- a/app/Livewire/Project/Resource/Create.php +++ b/app/Livewire/Project/Resource/Create.php @@ -2,41 +2,19 @@ namespace App\Livewire\Project\Resource; -use App\Models\Application; use App\Models\EnvironmentVariable; use App\Models\Service; -use App\Models\StandaloneClickhouse; use App\Models\StandaloneDocker; -use App\Models\StandaloneDragonfly; -use App\Models\StandaloneKeydb; -use App\Models\StandaloneMariadb; -use App\Models\StandaloneMongodb; -use App\Models\StandaloneMysql; -use App\Models\StandalonePostgresql; -use App\Models\StandaloneRedis; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Livewire\Component; class Create extends Component { - use AuthorizesRequests; - public $type; public $project; public function mount() { - $this->authorize('create', StandalonePostgresql::class); - $this->authorize('create', StandaloneRedis::class); - $this->authorize('create', StandaloneMongodb::class); - $this->authorize('create', StandaloneMysql::class); - $this->authorize('create', StandaloneMariadb::class); - $this->authorize('create', StandaloneKeydb::class); - $this->authorize('create', StandaloneDragonfly::class); - $this->authorize('create', StandaloneClickhouse::class); - $this->authorize('create', Service::class); - $this->authorize('create', Application::class); $type = str(request()->query('type')); $destination_uuid = request()->query('destination'); @@ -57,32 +35,24 @@ class Create extends Component if (in_array($type, DATABASE_TYPES)) { if ($type->value() === 'postgresql') { - $this->authorize('create', StandalonePostgresql::class); $database = create_standalone_postgresql( environmentId: $environment->id, destinationUuid: $destination_uuid, databaseImage: $database_image ); } elseif ($type->value() === 'redis') { - $this->authorize('create', StandaloneRedis::class); $database = create_standalone_redis($environment->id, $destination_uuid); } elseif ($type->value() === 'mongodb') { - $this->authorize('create', StandaloneMongodb::class); $database = create_standalone_mongodb($environment->id, $destination_uuid); } elseif ($type->value() === 'mysql') { - $this->authorize('create', StandaloneMysql::class); $database = create_standalone_mysql($environment->id, $destination_uuid); } elseif ($type->value() === 'mariadb') { - $this->authorize('create', StandaloneMariadb::class); $database = create_standalone_mariadb($environment->id, $destination_uuid); } elseif ($type->value() === 'keydb') { - $this->authorize('create', StandaloneKeydb::class); $database = create_standalone_keydb($environment->id, $destination_uuid); } elseif ($type->value() === 'dragonfly') { - $this->authorize('create', StandaloneDragonfly::class); $database = create_standalone_dragonfly($environment->id, $destination_uuid); } elseif ($type->value() === 'clickhouse') { - $this->authorize('create', StandaloneClickhouse::class); $database = create_standalone_clickhouse($environment->id, $destination_uuid); } diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index 13a9eed94..0ed1347f8 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -37,6 +37,8 @@ class Danger extends Component public string $resourceDomain = ''; + public bool $canDelete = false; + public function mount() { $parameters = get_route_parameters(); @@ -80,6 +82,13 @@ class Danger extends Component 'service-database' => $this->resource->name ?? 'Service Database', default => 'Unknown Resource', }; + + // Check if user can delete this resource + try { + $this->canDelete = auth()->user()->can('delete', $this->resource); + } catch (\Exception $e) { + $this->canDelete = false; + } } public function delete($password) diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 8064c2e23..ac88edbb5 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -30,18 +30,22 @@