Files
coolify/app/Models/SharedEnvironmentVariable.php
T
Andras BacsaiandClaude Opus 5.5 da7779d061 fix(env): keep locked variables locked but allow a new value
A locked variable used by Docker Compose could not be changed, unlocked,
or deleted, so a lock by mistake had no fix in the UI. A locked value can
now be replaced without showing it. The lock is permanent in the UI, the
API, and MCP, and Lock asks for confirmation.

Closes #6803

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 22:42:52 +01:00

99 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Support\ValidationPatterns;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class SharedEnvironmentVariable extends Model
{
use Auditable;
/**
* Flags that a "# coolify:" line of the developer view can set, with their defaults.
* Shared variables have no buildtime or runtime flags.
*
* @var array<string, bool>
*/
public const DEV_VIEW_FLAG_DEFAULTS = ['literal' => false];
protected $fillable = [
// Core identification
'key',
'value',
'comment',
// Type and relationships
'type',
'team_id',
'project_id',
'environment_id',
'server_id',
// Boolean flags
'is_multiline',
'is_literal',
'is_shown_once',
// Metadata
'version',
];
protected $hidden = [
'value',
];
protected $casts = [
'key' => 'string',
'value' => 'encrypted',
'is_literal' => 'boolean',
];
protected static function booted(): void
{
// A lock is permanent: no UI, API, or MCP path can unlock a variable and show its value again.
static::saving(function (SharedEnvironmentVariable $sharedVariable) {
if ($sharedVariable->exists && $sharedVariable->getOriginal('is_shown_once')) {
$sharedVariable->is_shown_once = true;
}
});
}
/**
* Scope shared environment variables to a team (API token team_id).
*/
public static function ownedByCurrentTeamAPI(int $teamId)
{
return static::where('team_id', $teamId);
}
protected function key(): Attribute
{
return Attribute::make(
set: fn (string $value) => ValidationPatterns::validatedEnvironmentVariableKey($value),
);
}
public function team()
{
return $this->belongsTo(Team::class);
}
public function project()
{
return $this->belongsTo(Project::class);
}
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function server()
{
return $this->belongsTo(Server::class);
}
}