Fixes bug with newly created variables not being assigned to existing servers properly, closes #478

This commit is contained in:
Dane Everitt 2017-06-18 21:38:00 -05:00
parent 1f88024cbb
commit cba54637fc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 25 additions and 16 deletions

View file

@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
* API now returns a 404 error when deleting a user that doesn't exist, rather than saying it was successful.
* Service variables that allow empty input now allow you to empty out the assigned value and set it back to blank.
* Fixes a bug where changing the default allocation for a server would not actually apply that allocation as the default on the daemon.
* Newly created service variables are now backfilled and assigned to existing servers properly.
### Added
* Added a `Vagrantfile` to the repository to help speed up development and testing for those who don't want to do a full dedicated install.

View file

@ -242,10 +242,11 @@ class ServerController extends Controller
public function getStartup(Request $request, $uuid)
{
$server = Models\Server::byUuid($uuid);
$server->load(['node', 'allocation', 'variables.variable']);
$this->authorize('view-startup', $server);
$server->load(['node', 'allocation', 'variables']);
$variables = Models\ServiceVariable::where('option_id', $server->option_id)->get();
$replacements = [
'{{SERVER_MEMORY}}' => $server->memory,
'{{SERVER_IP}}' => $server->allocation->ip,
@ -253,9 +254,16 @@ class ServerController extends Controller
];
$processed = str_replace(array_keys($replacements), array_values($replacements), $server->startup);
foreach ($server->variables as $v) {
$replace = ($v->user_can_view) ? $v->variable_value : '[hidden]';
$processed = str_replace('{{' . $v->variable->env_variable . '}}', $replace, $processed);
foreach ($variables as $var) {
if ($var->user_viewable) {
$serverVar = $server->variables->where('variable_id', $var->id)->first();
$var->server_set_value = $serverVar->variable_value ?? $var->default_value;
} else {
$var->server_set_value = '[hidden]';
}
$processed = str_replace('{{' . $var->env_variable . '}}', $var->server_set_value, $processed);
}
$server->js();
@ -263,7 +271,7 @@ class ServerController extends Controller
return view('server.settings.startup', [
'server' => $server,
'node' => $server->node,
'variables' => $server->variables->where('user_can_view', true),
'variables' => $variables->where('user_viewable', 1),
'service' => $server->service,
'processedStartup' => $processed,
]);

View file

@ -59,31 +59,31 @@
<div class="col-xs-12 col-md-4 col-sm-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ $v->variable->name }}</h3>
<h3 class="box-title">{{ $v->name }}</h3>
</div>
<div class="box-body">
<input
@if($v->user_can_edit)
name="env_{{ $v->variable->id }}"
@if($v->user_editable)
name="env_{{ $v->id }}"
@else
readonly
@endif
class="form-control" type="text" value="{{ old('env_' . $v->id, $v->variable_value) }}" />
<p class="small text-muted">{{ $v->variable->description }}</p>
class="form-control" type="text" value="{{ old('env_' . $v->id, $v->server_set_value) }}" />
<p class="small text-muted">{{ $v->description }}</p>
<p class="no-margin">
@if($v->required && $v->user_can_edit)
@if($v->required && $v->user_editable )
<span class="label label-danger">@lang('strings.required')</span>
@elseif(! $v->required && $v->user_can_edit)
@elseif(! $v->required && $v->user_editable)
<span class="label label-default">@lang('strings.optional')</span>
@endif
@if(! $v->user_can_edit)
@if(! $v->user_editable)
<span class="label label-warning">@lang('strings.read_only')</span>
@endif
</p>
</div>
<div class="box-footer">
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_var'):</strong> <code>{{ $v->variable->env_variable }}</code></p>
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_regex'):</strong> <code>{{ $v->variable->rules }}</code></p>
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_var'):</strong> <code>{{ $v->env_variable }}</code></p>
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_regex'):</strong> <code>{{ $v->rules }}</code></p>
</div>
</div>
</div>