Skip to content

A free open source IT asset/license management system

backend form validation. +cleanup

akemidxf45b8360105e
diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php
index f84a468a60..2c49f78bfb 100644
--- a/app/Http/Controllers/Assets/AssetCheckinController.php
+++ b/app/Http/Controllers/Assets/AssetCheckinController.php
@@ -116,6 +116,12 @@ class AssetCheckinController extends Controller
$seat->update(['assigned_to' => null]);
});
+ $settings = \App\Models\Setting::getSettings();
+
+ if($settings->require_checkinout_notes=="1" && (is_null($request->note))) {
+ return redirect()->to("hardware/$assetId/checkin")->with('error', trans('admin/hardware/message.update.no_note'));
+ }
+
// Get all pending Acceptances for this asset and delete them
$acceptances = CheckoutAcceptance::pending()->whereHasMorph('checkoutable',
[Asset::class],
diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php
index 05b766916b..506f47680c 100644
--- a/app/Http/Controllers/Assets/AssetCheckoutController.php
+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php
@@ -102,6 +102,10 @@ class AssetCheckoutController extends Controller
$settings = \App\Models\Setting::getSettings();
+ if($settings->require_checkinout_notes=="1" && (is_null($request->note))) {
+ return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.update.no_note'); //needs translation
+ }
+
// We have to check whether $target->company_id is null here since locations don't have a company yet
if (($settings->full_multiple_companies_support) && ((!is_null($target->company_id)) && (!is_null($asset->company_id)))) {
if ($target->company_id != $asset->company_id){
diff --git a/app/Http/Requests/AssetCheckinRequest.php b/app/Http/Requests/AssetCheckinRequest.php
index 3bee83a810..ea28471899 100644
--- a/app/Http/Requests/AssetCheckinRequest.php
+++ b/app/Http/Requests/AssetCheckinRequest.php
@@ -14,18 +14,6 @@ class AssetCheckinRequest extends Request
return true;
}
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
-// public function rules()
-// {
-// 'note' => 'required|in:asset,',
-//
-// return $rules;
-// }
-
public function response(array $errors)
{
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
diff --git a/app/Http/Requests/AssetCheckoutRequest.php b/app/Http/Requests/AssetCheckoutRequest.php
index 9064e6dcd0..f48a7d5e53 100644
--- a/app/Http/Requests/AssetCheckoutRequest.php
+++ b/app/Http/Requests/AssetCheckoutRequest.php
@@ -27,7 +27,6 @@ class AssetCheckoutRequest extends Request
'assigned_location' => 'required_without_all:assigned_user,assigned_asset',
'status_id' => 'exists:status_labels,id,deployable,1',
'checkout_to_type' => 'required|in:asset,location,user',
-// 'note' => 'required|in:asset,',
'checkout_at' => [
'nullable',
'date',
diff --git a/resources/lang/en-US/admin/hardware/message.php b/resources/lang/en-US/admin/hardware/message.php
index 041d32f56c..32358cb6dd 100644
--- a/resources/lang/en-US/admin/hardware/message.php
+++ b/resources/lang/en-US/admin/hardware/message.php
@@ -23,6 +23,7 @@ return [
'nothing_updated' => 'No fields were selected, so nothing was updated.',
'no_assets_selected' => 'No assets were selected, so nothing was updated.',
'assets_do_not_exist_or_are_invalid' => 'Selected assets cannot be updated.',
+ 'no_note' => 'Note field is empty',
],
'restore' => [
@@ -77,6 +78,7 @@ return [
'user_does_not_exist' => 'That user is invalid. Please try again.',
'not_available' => 'That asset is not available for checkout!',
'no_assets_selected' => 'You must select at least one asset from the list',
+
],
'checkin' => [
diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.php
index 5083325a8e..2b087cb58b 100755
--- a/resources/views/hardware/checkin.blade.php
+++ b/resources/views/hardware/checkin.blade.php
@@ -124,6 +124,7 @@
name="note">{{ old('note', $asset->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
+ @endif
</div>
</div> <!--/.box-body-->
</div> <!--/.box-body-->