fix: not able to use other shared envs

This commit is contained in:
Andras Bacsai 2024-01-31 13:40:15 +01:00
parent 5f797ec0ae
commit 52fd7ad571
4 changed files with 34 additions and 2 deletions

View File

@ -32,6 +32,13 @@ class Add extends Component
public function submit() public function submit()
{ {
$this->validate(); $this->validate();
if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
$type = str($this->value)->after("{{")->before(".")->value;
if (!collect(['team', 'project', 'environment'])->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
return;
}
}
$this->dispatch('saveKey', [ $this->dispatch('saveKey', [
'key' => $this->key, 'key' => $this->key,
'value' => $this->value, 'value' => $this->value,

View File

@ -71,12 +71,26 @@ class All extends Component
continue; continue;
} }
$found->value = $variable; $found->value = $variable;
if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
$type = str($found->value)->after("{{")->before(".")->value;
if (!collect(['team', 'project', 'environment'])->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
return;
}
}
$found->save(); $found->save();
continue; continue;
} else { } else {
$environment = new EnvironmentVariable(); $environment = new EnvironmentVariable();
$environment->key = $key; $environment->key = $key;
$environment->value = $variable; $environment->value = $variable;
if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
$type = str($environment->value)->after("{{")->before(".")->value;
if (!collect(['team', 'project', 'environment'])->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
return;
}
}
$environment->is_build_time = false; $environment->is_build_time = false;
$environment->is_preview = $isPreview ? true : false; $environment->is_preview = $isPreview ? true : false;
switch ($this->resource->type()) { switch ($this->resource->type()) {

View File

@ -50,7 +50,8 @@ class Show extends Component
$this->isLocked = true; $this->isLocked = true;
} }
} }
public function serialize() { public function serialize()
{
data_forget($this->env, 'real_value'); data_forget($this->env, 'real_value');
if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') { if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') {
data_forget($this->env, 'is_build_time'); data_forget($this->env, 'is_build_time');
@ -80,6 +81,13 @@ class Show extends Component
} else { } else {
$this->validate(); $this->validate();
} }
if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
$type = str($this->env->value)->after("{{")->before(".")->value;
if (!collect(['team', 'project', 'environment'])->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
return;
}
}
$this->serialize(); $this->serialize();
$this->env->save(); $this->env->save();
$this->dispatch('success', 'Environment variable updated successfully.'); $this->dispatch('success', 'Environment variable updated successfully.');

View File

@ -100,6 +100,9 @@ class EnvironmentVariable extends Model
$variable = Str::after($environment_variable, "{$type}."); $variable = Str::after($environment_variable, "{$type}.");
$variable = Str::before($variable, '}}'); $variable = Str::before($variable, '}}');
$variable = Str::of($variable)->trim()->value; $variable = Str::of($variable)->trim()->value;
if (!collect(['team', 'project', 'environment'])->contains($type)) {
return $variable;
}
if ($type === 'environment') { if ($type === 'environment') {
$id = $resource->environment->id; $id = $resource->environment->id;
} else if ($type === 'project') { } else if ($type === 'project') {