Fix front and backend views with new service variable setups
This commit is contained in:
parent
66e94dd7c0
commit
fcadee7e67
14 changed files with 104 additions and 93 deletions
|
@ -627,23 +627,25 @@ class ServerRepository
|
|||
foreach ($server->option->variables as &$variable) {
|
||||
$set = isset($data['env_' . $variable->id]);
|
||||
|
||||
// Variable is required but was not passed into the function.
|
||||
if ($variable->required && ! $set) {
|
||||
throw new DisplayException('A required variable (' . $variable->env_variable . ') was not passed in the request.');
|
||||
}
|
||||
|
||||
// If user is not an admin and are trying to edit a non-editable field
|
||||
// or an invisible field just silently skip the variable.
|
||||
if (! $admin && (! $variable->user_editable || ! $variable->user_viewable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Confirm value is valid when compared aganist regex.
|
||||
// @TODO: switch to Laravel validation rules.
|
||||
if ($set && ! is_null($variable->regex)) {
|
||||
if (! preg_match($variable->regex, $data['env_' . $variable->id])) {
|
||||
throw new DisplayException('The value passed for a variable (' . $variable->env_variable . ') could not be matched aganist the regex for that field (' . $variable->regex . ').');
|
||||
}
|
||||
// Perform Field Validation
|
||||
$validator = Validator::make([
|
||||
'variable_value' => ($set) ? $data['env_' . $variable->id] : null,
|
||||
], [
|
||||
'variable_value' => $variable->rules,
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode(
|
||||
collect([
|
||||
'notice' => ['There was a validation error with the `' . $variable->name . '` variable.']
|
||||
])->merge($validator->errors()->toArray())
|
||||
));
|
||||
}
|
||||
|
||||
$svar = Models\ServerVariable::firstOrNew([
|
||||
|
|
|
@ -80,7 +80,6 @@ class VariableRepository
|
|||
$data['option_id'] = $option->id;
|
||||
$data['user_viewable'] = (in_array('user_viewable', $data['options']));
|
||||
$data['user_editable'] = (in_array('user_editable', $data['options']));
|
||||
$data['required'] = (in_array('required', $data['options']));
|
||||
|
||||
// Remove field that isn't used.
|
||||
unset($data['options']);
|
||||
|
@ -156,7 +155,6 @@ class VariableRepository
|
|||
|
||||
$data['user_viewable'] = (in_array('user_viewable', $data['options']));
|
||||
$data['user_editable'] = (in_array('user_editable', $data['options']));
|
||||
$data['required'] = (in_array('required', $data['options']));
|
||||
|
||||
// Remove field that isn't used.
|
||||
unset($data['options']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue