diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7fd552f57d..3b396ee7c7 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use App\Helpers\Helper; use Illuminate\Validation\ValidationException; use Log; +use JsonException; class Handler extends ExceptionHandler @@ -26,6 +27,7 @@ class Handler extends ExceptionHandler \Illuminate\Validation\ValidationException::class, \Intervention\Image\Exception\NotSupportedException::class, \League\OAuth2\Server\Exception\OAuthServerException::class, + JsonException::class ]; /** @@ -60,6 +62,12 @@ class Handler extends ExceptionHandler return redirect()->back()->with('error', trans('general.token_expired')); } + // Invalid JSON exception + // TODO: don't understand why we have to do this when we have the invalidJson() method, below, but, well, whatever + if ($e instanceof JsonException) { + return response()->json(Helper::formatStandardApiResponse('error', null, 'invalid JSON'), 422); + } + // Handle Ajax requests that fail because the model doesn't exist if ($request->ajax() || $request->wantsJson()) { diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 80a9109ba8..1478cce954 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -866,7 +866,7 @@ class AssetsController extends Controller return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.success'))); } - return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.error'))); + return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.error'))); } diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 8d57346079..ef16eaebb8 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -155,7 +155,6 @@ class AssetModelsController extends Controller $model->requestable = $request->input('requestable', '0'); - $this->removeCustomFieldsDefaultValues($model); if ($request->input('custom_fieldset')=='') { @@ -168,7 +167,6 @@ class AssetModelsController extends Controller } } - if ($model->save()) { return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success')); } @@ -463,7 +461,9 @@ class AssetModelsController extends Controller private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues) { foreach ($defaultValues as $customFieldId => $defaultValue) { - if ($defaultValue) { + if(is_array($defaultValue)){ + $model->defaultValues()->attach($customFieldId, ['default_value' => implode(', ', $defaultValue)]); + }elseif ($defaultValue) { $model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]); } } diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 35bfcdee93..54a7b81adf 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -8,6 +8,14 @@ abstract class Request extends FormRequest { protected $rules = []; + public function json($key = null, $default = null) + { + if ($this->ajax() || $this->wantsJson()) { + json_decode($this->getContent(), false, 512, JSON_THROW_ON_ERROR); // ignore output, just throw + } + return parent::json($key, $default); + } + public function rules() { return $this->rules; diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index 501b5057ca..d8b3e7f9a0 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -115,6 +115,7 @@ trait Loggable $log->location_id = null; $log->note = $note; + $log->action_date = $action_date; if (Auth::user()) { $log->user_id = Auth::user()->id; diff --git a/resources/assets/js/components/forms/asset-models/fieldset-default-values.vue b/resources/assets/js/components/forms/asset-models/fieldset-default-values.vue index ea45e1df74..faac811202 100644 --- a/resources/assets/js/components/forms/asset-models/fieldset-default-values.vue +++ b/resources/assets/js/components/forms/asset-models/fieldset-default-values.vue @@ -46,6 +46,14 @@
+
+ +
+ +
+ +
+ {$field->db_column_name()})) ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : '') }}> + {$field->db_column_name()})) ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($key, explode(', ', $field->defaultValue($model->id))) ? ' checked="checked"' : '')) }}> {{ $value }} @@ -32,7 +31,7 @@