Merge branch 'develop' into feature/PTDL-472

This commit is contained in:
Dane Everitt 2017-06-25 15:36:39 -05:00
commit b7b046c044
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
24 changed files with 672 additions and 82 deletions

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

@ -123,12 +123,11 @@ class VariableRepository
$variable = ServiceVariable::findOrFail($id);
$validator = Validator::make($data, [
'name' => 'sometimes|required|string|min:1|max:255',
'description' => 'sometimes|nullable|string',
'env_variable' => 'sometimes|required|regex:/^[\w]{1,255}$/',
'default_value' => 'string',
'name' => 'required|string|min:1|max:255',
'description' => 'nullable|string',
'env_variable' => 'required|regex:/^[\w]{1,255}$/',
'rules' => 'bail|required|string',
'options' => 'sometimes|required|array',
'rules' => 'bail|sometimes|required|string|min:1',
]);
// Ensure the default value is allowed by the rules provided.

View file

@ -535,7 +535,7 @@ class old_ServerRepository
}
$newPorts = true;
$firstNewAllocation = (is_null($firstNewAllocation)) ? $model->id : $firstNewAllocation;
$firstNewAllocation = $firstNewAllocation ?? $model;
$model->update([
'server_id' => $server->id,
]);
@ -555,7 +555,8 @@ class old_ServerRepository
}
// New Allocation, set as the default.
$server->allocation_id = $firstNewAllocation;
$server->allocation_id = $firstNewAllocation->id;
$newBuild['default'] = ['ip' => $firstNewAllocation->ip, 'port' => $firstNewAllocation->port];
}
$newPorts = true;

View file

@ -151,6 +151,8 @@ class old_UserRepository
*/
public function delete($id)
{
$user = Models\User::findOrFail($id);
if (Models\Server::where('owner_id', $id)->count() > 0) {
throw new DisplayException('Cannot delete a user with active servers attached to thier account.');
}
@ -170,7 +172,7 @@ class old_UserRepository
$subuser->delete();
}
Models\User::destroy($id);
$user->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollBack();