2023-05-04 20:29:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Shared\EnvironmentVariable;
|
2023-05-04 20:29:14 +00:00
|
|
|
|
2025-11-19 09:54:19 +00:00
|
|
|
use App\Models\Environment;
|
|
|
|
|
use App\Models\Project;
|
2025-09-23 06:53:14 +00:00
|
|
|
use App\Traits\EnvironmentVariableAnalyzer;
|
2025-08-26 08:27:31 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2025-11-19 09:54:19 +00:00
|
|
|
use Livewire\Attributes\Computed;
|
2023-05-04 20:29:14 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Add extends Component
|
|
|
|
|
{
|
2025-09-23 06:53:14 +00:00
|
|
|
use AuthorizesRequests, EnvironmentVariableAnalyzer;
|
2025-08-26 08:27:31 +00:00
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public $parameters;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-15 10:46:22 +00:00
|
|
|
public bool $shared = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-05 10:07:55 +00:00
|
|
|
public bool $is_preview = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public string $key;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-26 12:45:52 +00:00
|
|
|
public ?string $value = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-15 21:02:37 +00:00
|
|
|
public bool $is_multiline = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-15 10:46:22 +00:00
|
|
|
public bool $is_literal = false;
|
2023-05-04 20:29:14 +00:00
|
|
|
|
2025-09-18 16:14:54 +00:00
|
|
|
public bool $is_runtime = true;
|
|
|
|
|
|
|
|
|
|
public bool $is_buildtime = true;
|
2025-09-11 15:38:16 +00:00
|
|
|
|
2025-11-18 13:48:08 +00:00
|
|
|
public ?string $comment = null;
|
|
|
|
|
|
2025-09-23 06:53:14 +00:00
|
|
|
public array $problematicVariables = [];
|
|
|
|
|
|
2023-05-05 12:20:10 +00:00
|
|
|
protected $listeners = ['clearAddEnv' => 'clear'];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-05-05 07:28:00 +00:00
|
|
|
protected $rules = [
|
|
|
|
|
'key' => 'required|string',
|
2023-09-26 12:45:52 +00:00
|
|
|
'value' => 'nullable',
|
2024-03-15 21:02:37 +00:00
|
|
|
'is_multiline' => 'required|boolean',
|
2024-04-15 10:46:22 +00:00
|
|
|
'is_literal' => 'required|boolean',
|
2025-09-18 16:14:54 +00:00
|
|
|
'is_runtime' => 'required|boolean',
|
|
|
|
|
'is_buildtime' => 'required|boolean',
|
2025-11-18 13:48:08 +00:00
|
|
|
'comment' => 'nullable|string|max:256',
|
2023-05-05 07:28:00 +00:00
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
|
'key' => 'key',
|
|
|
|
|
'value' => 'value',
|
2024-03-15 21:02:37 +00:00
|
|
|
'is_multiline' => 'multiline',
|
2024-04-15 10:46:22 +00:00
|
|
|
'is_literal' => 'literal',
|
2025-09-18 16:14:54 +00:00
|
|
|
'is_runtime' => 'runtime',
|
|
|
|
|
'is_buildtime' => 'buildtime',
|
2025-11-18 13:48:08 +00:00
|
|
|
'comment' => 'comment',
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2025-09-23 06:53:14 +00:00
|
|
|
$this->problematicVariables = self::getProblematicVariablesForFrontend();
|
2023-05-04 20:29:14 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-11-19 09:54:19 +00:00
|
|
|
#[Computed]
|
|
|
|
|
public function availableSharedVariables(): array
|
|
|
|
|
{
|
|
|
|
|
$team = currentTeam();
|
|
|
|
|
$result = [
|
|
|
|
|
'team' => [],
|
|
|
|
|
'project' => [],
|
|
|
|
|
'environment' => [],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Early return if no team
|
|
|
|
|
if (! $team) {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if user can view team variables
|
|
|
|
|
try {
|
|
|
|
|
$this->authorize('view', $team);
|
|
|
|
|
$result['team'] = $team->environment_variables()
|
|
|
|
|
->pluck('key')
|
|
|
|
|
->toArray();
|
|
|
|
|
} catch (\Illuminate\Auth\Access\AuthorizationException $e) {
|
|
|
|
|
// User not authorized to view team variables
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get project variables if we have a project_uuid in route
|
|
|
|
|
$projectUuid = data_get($this->parameters, 'project_uuid');
|
|
|
|
|
if ($projectUuid) {
|
|
|
|
|
$project = Project::where('team_id', $team->id)
|
|
|
|
|
->where('uuid', $projectUuid)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if ($project) {
|
|
|
|
|
try {
|
|
|
|
|
$this->authorize('view', $project);
|
|
|
|
|
$result['project'] = $project->environment_variables()
|
|
|
|
|
->pluck('key')
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
// Get environment variables if we have an environment_uuid in route
|
|
|
|
|
$environmentUuid = data_get($this->parameters, 'environment_uuid');
|
|
|
|
|
if ($environmentUuid) {
|
|
|
|
|
$environment = $project->environments()
|
|
|
|
|
->where('uuid', $environmentUuid)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if ($environment) {
|
|
|
|
|
try {
|
|
|
|
|
$this->authorize('view', $environment);
|
|
|
|
|
$result['environment'] = $environment->environment_variables()
|
|
|
|
|
->pluck('key')
|
|
|
|
|
->toArray();
|
|
|
|
|
} catch (\Illuminate\Auth\Access\AuthorizationException $e) {
|
|
|
|
|
// User not authorized to view environment variables
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (\Illuminate\Auth\Access\AuthorizationException $e) {
|
|
|
|
|
// User not authorized to view project variables
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public function submit()
|
|
|
|
|
{
|
2023-05-05 07:28:00 +00:00
|
|
|
$this->validate();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('saveKey', [
|
2023-05-05 12:20:10 +00:00
|
|
|
'key' => $this->key,
|
|
|
|
|
'value' => $this->value,
|
2024-03-15 21:02:37 +00:00
|
|
|
'is_multiline' => $this->is_multiline,
|
2024-04-15 10:46:22 +00:00
|
|
|
'is_literal' => $this->is_literal,
|
2025-09-18 16:14:54 +00:00
|
|
|
'is_runtime' => $this->is_runtime,
|
|
|
|
|
'is_buildtime' => $this->is_buildtime,
|
2023-06-05 10:07:55 +00:00
|
|
|
'is_preview' => $this->is_preview,
|
2025-11-18 13:48:08 +00:00
|
|
|
'comment' => $this->comment,
|
2023-05-05 12:20:10 +00:00
|
|
|
]);
|
2023-07-13 11:16:24 +00:00
|
|
|
$this->clear();
|
2023-05-05 12:20:10 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-05 12:20:10 +00:00
|
|
|
public function clear()
|
|
|
|
|
{
|
|
|
|
|
$this->key = '';
|
|
|
|
|
$this->value = '';
|
2024-03-15 21:02:37 +00:00
|
|
|
$this->is_multiline = false;
|
2024-04-15 10:46:22 +00:00
|
|
|
$this->is_literal = false;
|
2025-09-18 16:14:54 +00:00
|
|
|
$this->is_runtime = true;
|
|
|
|
|
$this->is_buildtime = true;
|
2025-11-18 13:48:08 +00:00
|
|
|
$this->comment = null;
|
2023-05-04 20:29:14 +00:00
|
|
|
}
|
|
|
|
|
}
|