Don't break the page if no variable rules are provided.

This commit is contained in:
Dane Everitt 2018-01-21 11:58:59 -06:00
parent bd5952bf00
commit 2212f28351
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 18 additions and 15 deletions

View file

@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### v0.7.0-beta.5 (Derelict Dermodactylus)
### Fixed
* `[beta.4]` — Fixes some bad search and replace action that happened previously and was throwing errors when validating user permissions.
* `[beta.4]` — Fixes behavior of variable validation to not break the page when no rules are provided.
## v0.7.0-beta.4 (Derelict Dermodactylus)
### Fixed

View file

@ -1,11 +1,4 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Http\Requests\Admin\Egg;
@ -15,6 +8,8 @@ use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class EggVariableFormRequest extends AdminFormRequest
{
/**
* Define rules for validation of this request.
*
* @return array
*/
public function rules()
@ -23,7 +18,7 @@ class EggVariableFormRequest extends AdminFormRequest
'name' => 'required|string|min:1|max:255',
'description' => 'sometimes|nullable|string',
'env_variable' => 'required|regex:/^[\w]{1,255}$/|notIn:' . EggVariable::RESERVED_ENV_NAMES,
'default_value' => 'string',
'default_value' => 'nullable|string',
'options' => 'sometimes|required|array',
'rules' => 'bail|required|string',
];
@ -41,6 +36,13 @@ class EggVariableFormRequest extends AdminFormRequest
$rules = $this->input('rules', $this->route()->parameter('egg')->rules);
}
// If rules is not a string it is already violating the rule defined above
// so just skip the addition of default value rules since this request
// will fail anyways.
if (! is_string($rules)) {
return;
}
$validator->addRules(['default_value' => $rules]);
}
}

View file

@ -99,25 +99,25 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Create New Option Variable</h4>
<h4 class="modal-title">Create New Egg Variable</h4>
</div>
<form action="{{ route('admin.nests.egg.variables', $egg->id) }}" method="POST">
<div class="modal-body">
<div class="form-group">
<label class="form-label">Name</label>
<label class="control-label">Name <span class="field-required"></span></label>
<input type="text" name="name" class="form-control" />
</div>
<div class="form-group">
<label class="form-label">Description</label>
<label class="control-label">Description</label>
<textarea name="description" class="form-control" rows="3"></textarea>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="form-label">Environment Variable</label>
<label class="control-label">Environment Variable <span class="field-required"></span></label>
<input type="text" name="env_variable" class="form-control" />
</div>
<div class="form-group col-md-6">
<label class="form-label">Default Value</label>
<label class="control-label">Default Value</label>
<input type="text" name="default_value" class="form-control" />
</div>
<div class="col-xs-12">
@ -125,14 +125,14 @@
</div>
</div>
<div class="form-group">
<label class="form-label">Permissions</label>
<label class="control-label">Permissions</label>
<select name="options[]" class="pOptions form-control" multiple>
<option value="user_viewable">Users Can View</option>
<option value="user_editable">Users Can Edit</option>
</select>
</div>
<div class="form-group">
<label class="form-label">Input Rules</label>
<label class="control-label">Input Rules <span class="field-required"></span></label>
<input type="text" name="rules" class="form-control" value="required|string|max:20" placeholder="required|string|max:20" />
<p class="text-muted small">These rules are defined using standard Laravel Framework validation rules.</p>
</div>