Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: add database transactions and component-level authorization to shared variables

Aditya Tripathi28cb561c0428
diff --git a/app/Livewire/SharedVariables/Environment/Show.php b/app/Livewire/SharedVariables/Environment/Show.php
index 6c8342c41b..6b1d35d14b 100644
--- a/app/Livewire/SharedVariables/Environment/Show.php
+++ b/app/Livewire/SharedVariables/Environment/Show.php
@@ -5,6 +5,7 @@ namespace App\Livewire\SharedVariables\Environment;
use App\Models\Application;
use App\Models\Project;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Support\Facades\DB;
use Livewire\Component;
class Show extends Component
@@ -98,23 +99,26 @@ class Show extends Component
private function handleBulkSubmit()
{
$variables = parseEnvFormatToArray($this->variables);
- $changesMade = false;
- // Delete removed variables
- $deletedCount = $this->deleteRemovedVariables($variables);
- if ($deletedCount > 0) {
- $changesMade = true;
- }
+ DB::transaction(function () use ($variables) {
+ $changesMade = false;
- // Update or create variables
- $updatedCount = $this->updateOrCreateVariables($variables);
- if ($updatedCount > 0) {
- $changesMade = true;
- }
+ // Delete removed variables
+ $deletedCount = $this->deleteRemovedVariables($variables);
+ if ($deletedCount > 0) {
+ $changesMade = true;
+ }
- if ($changesMade) {
- $this->dispatch('success', 'Environment variables updated.');
- }
+ // Update or create variables
+ $updatedCount = $this->updateOrCreateVariables($variables);
+ if ($updatedCount > 0) {
+ $changesMade = true;
+ }
+
+ if ($changesMade) {
+ $this->dispatch('success', 'Environment variables updated.');
+ }
+ });
}
private function deleteRemovedVariables($variables)
diff --git a/app/Livewire/SharedVariables/Project/Show.php b/app/Livewire/SharedVariables/Project/Show.php
index a3abe5df23..93ead33a33 100644
--- a/app/Livewire/SharedVariables/Project/Show.php
+++ b/app/Livewire/SharedVariables/Project/Show.php
@@ -4,6 +4,7 @@ namespace App\Livewire\SharedVariables\Project;
use App\Models\Project;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Support\Facades\DB;
use Livewire\Component;
class Show extends Component
@@ -95,23 +96,26 @@ class Show extends Component
private function handleBulkSubmit()
{
$variables = parseEnvFormatToArray($this->variables);
- $changesMade = false;
- // Delete removed variables
- $deletedCount = $this->deleteRemovedVariables($variables);
- if ($deletedCount > 0) {
- $changesMade = true;
- }
+ DB::transaction(function () use ($variables) {
+ $changesMade = false;
- // Update or create variables
- $updatedCount = $this->updateOrCreateVariables($variables);
- if ($updatedCount > 0) {
- $changesMade = true;
- }
+ // Delete removed variables
+ $deletedCount = $this->deleteRemovedVariables($variables);
+ if ($deletedCount > 0) {
+ $changesMade = true;
+ }
- if ($changesMade) {
- $this->dispatch('success', 'Environment variables updated.');
- }
+ // Update or create variables
+ $updatedCount = $this->updateOrCreateVariables($variables);
+ if ($updatedCount > 0) {
+ $changesMade = true;
+ }
+
+ if ($changesMade) {
+ $this->dispatch('success', 'Environment variables updated.');
+ }
+ });
}
private function deleteRemovedVariables($variables)
diff --git a/app/Livewire/SharedVariables/Team/Index.php b/app/Livewire/SharedVariables/Team/Index.php
index 6311d9a87f..bd23bca82e 100644
--- a/app/Livewire/SharedVariables/Team/Index.php
+++ b/app/Livewire/SharedVariables/Team/Index.php
@@ -4,6 +4,7 @@ namespace App\Livewire\SharedVariables\Team;
use App\Models\Team;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Support\Facades\DB;
use Livewire\Component;
class Index extends Component
@@ -89,23 +90,26 @@ class Index extends Component
private function handleBulkSubmit()
{
$variables = parseEnvFormatToArray($this->variables);
- $changesMade = false;
- // Delete removed variables
- $deletedCount = $this->deleteRemovedVariables($variables);
- if ($deletedCount > 0) {
- $changesMade = true;
- }
+ DB::transaction(function () use ($variables) {
+ $changesMade = false;
- // Update or create variables
- $updatedCount = $this->updateOrCreateVariables($variables);
- if ($updatedCount > 0) {
- $changesMade = true;
- }
+ // Delete removed variables
+ $deletedCount = $this->deleteRemovedVariables($variables);
+ if ($deletedCount > 0) {
+ $changesMade = true;
+ }
- if ($changesMade) {
- $this->dispatch('success', 'Environment variables updated.');
- }
+ // Update or create variables
+ $updatedCount = $this->updateOrCreateVariables($variables);
+ if ($updatedCount > 0) {
+ $changesMade = true;
+ }
+
+ if ($changesMade) {
+ $this->dispatch('success', 'Environment variables updated.');
+ }
+ });
}
private function deleteRemovedVariables($variables)
diff --git a/resources/views/livewire/shared-variables/environment/show.blade.php b/resources/views/livewire/shared-variables/environment/show.blade.php
index 02cc07b280..fde2d0ae89 100644
--- a/resources/views/livewire/shared-variables/environment/show.blade.php
+++ b/resources/views/livewire/shared-variables/environment/show.blade.php
@@ -9,9 +9,7 @@
<livewire:project.shared.environment-variable.add :shared="true" />
</x-modal-input>
@endcan
- @can('update', $environment)
- <x-forms.button wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
- @endcan
+ <x-forms.button canGate="update" :canResource="$environment" wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
</div>
<div class="flex items-center gap-1 subtitle">You can use these variables anywhere with <span
class="dark:text-warning text-coollabs">@{{ environment.VARIABLENAME }}</span><x-helper
@@ -28,14 +26,9 @@
</div>
@else
<form wire:submit='submit' class="flex flex-col gap-2">
- @can('update', $environment)
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Environment Shared Variables"></x-forms.textarea>
- <x-forms.button type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
- @else
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Environment Shared Variables" disabled></x-forms.textarea>
- @endcan
+ <x-forms.textarea canGate="update" :canResource="$environment" rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
+ label="Environment Shared Variables"></x-forms.textarea>
+ <x-forms.button canGate="update" :canResource="$environment" type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
</form>
@endif
</div>
diff --git a/resources/views/livewire/shared-variables/project/show.blade.php b/resources/views/livewire/shared-variables/project/show.blade.php
index 99d95059a6..f89ad9ce71 100644
--- a/resources/views/livewire/shared-variables/project/show.blade.php
+++ b/resources/views/livewire/shared-variables/project/show.blade.php
@@ -9,9 +9,7 @@
<livewire:project.shared.environment-variable.add :shared="true" />
</x-modal-input>
@endcan
- @can('update', $project)
- <x-forms.button wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
- @endcan
+ <x-forms.button canGate="update" :canResource="$project" wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
</div>
<div class="flex flex-wrap gap-1 subtitle">
<div>You can use these variables anywhere with</div>
@@ -30,14 +28,9 @@
</div>
@else
<form wire:submit='submit' class="flex flex-col gap-2">
- @can('update', $project)
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Project Shared Variables"></x-forms.textarea>
- <x-forms.button type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
- @else
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Project Shared Variables" disabled></x-forms.textarea>
- @endcan
+ <x-forms.textarea canGate="update" :canResource="$project" rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
+ label="Project Shared Variables"></x-forms.textarea>
+ <x-forms.button canGate="update" :canResource="$project" type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
</form>
@endif
</div>
diff --git a/resources/views/livewire/shared-variables/team/index.blade.php b/resources/views/livewire/shared-variables/team/index.blade.php
index 44399dcda9..fcfca35fb3 100644
--- a/resources/views/livewire/shared-variables/team/index.blade.php
+++ b/resources/views/livewire/shared-variables/team/index.blade.php
@@ -9,9 +9,7 @@
<livewire:project.shared.environment-variable.add :shared="true" />
</x-modal-input>
@endcan
- @can('update', $team)
- <x-forms.button wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
- @endcan
+ <x-forms.button canGate="update" :canResource="$team" wire:click='switch'>{{ $view === 'normal' ? 'Developer view' : 'Normal view' }}</x-forms.button>
</div>
<div class="flex items-center gap-1 subtitle">You can use these variables anywhere with <span
class="dark:text-warning text-coollabs">@{{ team.VARIABLENAME }}</span> <x-helper
@@ -29,14 +27,9 @@
</div>
@else
<form wire:submit='submit' class="flex flex-col gap-2">
- @can('update', $team)
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Team Shared Variables"></x-forms.textarea>
- <x-forms.button type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
- @else
- <x-forms.textarea rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
- label="Team Shared Variables" disabled></x-forms.textarea>
- @endcan
+ <x-forms.textarea canGate="update" :canResource="$team" rows="20" class="whitespace-pre-wrap" id="variables" wire:model="variables"
+ label="Team Shared Variables"></x-forms.textarea>
+ <x-forms.button canGate="update" :canResource="$team" type="submit" class="btn btn-primary">Save All Environment Variables</x-forms.button>
</form>
@endif
</div>