From 51236a2ad93cc50ffb654ebab1194e83700627e0 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Sep 2017 19:57:52 -0700 Subject: [PATCH 1/4] Fixes #4056 - check for assets before deleting user --- app/Http/Controllers/UsersController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 62360ff51c..31f3741445 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -376,6 +376,11 @@ class UsersController extends Controller return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.'); } + if (count($user->assets) > 0) { + // Redirect to the user management page + return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->assets) . ' assets associated with them.'); + } + if ($user->licenses()->count() > 0) { // Redirect to the user management page return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.'); From 0e29744ec2c8a81eb199a6be1c550f624781f727 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Sep 2017 20:57:33 -0700 Subject: [PATCH 2/4] =?UTF-8?q?Don=E2=80=99t=20try=20to=20send=20an=20emai?= =?UTF-8?q?l=20if=20the=20user=20doesn=E2=80=99t=20have=20an=20email=20add?= =?UTF-8?q?ress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AccessoriesController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 6658997cf7..b1c00d80f2 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -274,7 +274,7 @@ class AccessoriesController extends Controller $data['note'] = $logaction->note; $data['require_acceptance'] = $accessory->requireAcceptance(); // TODO: Port this to new mail notifications - if (($accessory->requireAcceptance()=='1') || ($accessory->getEula())) { + if ((($accessory->requireAcceptance()=='1') || ($accessory->getEula())) && ($user->email!='')) { Mail::send('emails.accept-accessory', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); @@ -351,7 +351,7 @@ class AccessoriesController extends Controller $data['item_tag'] = ''; $data['note'] = e($logaction->note); - if (($accessory->checkin_email()=='1')) { + if ((($accessory->checkin_email()=='1')) && ($user->email!='')) { Mail::send('emails.checkin-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); From 4d32f2b337d9862d6fb2930169b69bd808e3b855 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Sep 2017 21:18:00 -0700 Subject: [PATCH 3/4] Fixes #4059 - accessories view --- .../Controllers/Api/AccessoriesController.php | 5 ++-- .../Transformers/AccessoriesTransformer.php | 23 ++++++++++++++++--- app/Http/Transformers/AssetsTransformer.php | 3 ++- resources/views/accessories/view.blade.php | 6 ++--- .../views/partials/bootstrap-table.blade.php | 14 ++++++++--- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index b1ca7041c1..07fbc21971 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -129,9 +129,8 @@ class AccessoriesController extends Controller { $this->authorize('view', Accessory::class); $accessory = Accessory::findOrFail($id)->with('users')->first(); - $accessories_users = $accessory->users; - $total = $accessories_users->count(); - return (new AccessoriesTransformer)->transformCheckedoutAccessories($accessories_users, $total); + $total = $accessory->users->count(); + return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $total); } diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php index 575e8be943..ffab0d7cf5 100644 --- a/app/Http/Transformers/AccessoriesTransformer.php +++ b/app/Http/Transformers/AccessoriesTransformer.php @@ -59,13 +59,30 @@ class AccessoriesTransformer } - public function transformCheckedoutAccessories (Collection $accessories_users, $total) + public function transformCheckedoutAccessory (Accessory $accessory, $total) { + + + $array = array(); - foreach ($accessories_users as $user) { - $array[] = (new UsersTransformer)->transformUser($user); + foreach ($accessory->users as $user) { + $array[] = [ + 'assigned_pivot_id' => $user->pivot->id, + 'id' => (int) $user->id, + 'username' => e($user->username), + 'name' => e($user->getFullNameAttribute()), + 'first_name'=> e($user->first_name), + 'last_name'=> e($user->last_name), + 'employee_number' => e($user->employee_num), + 'type' => 'user', + 'available_actions' => ['checkin' => true] + ]; + } + + + return (new DatatablesTransformer)->transformDatatables($array, $total); } diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index c8c054c9be..adcbfafe9a 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -33,7 +33,8 @@ class AssetsTransformer 'model_number' => ($asset->model) ? e($asset->model->model_number) : null, 'status_label' => ($asset->assetstatus) ? [ 'id' => (int) $asset->assetstatus->id, - 'name'=> e($asset->assetstatus->name) + 'name'=> e($asset->assetstatus->name), + 'status_type' => e($asset->assetstatus->getStatuslabelType()), ] : null, 'category' => ($asset->model->category) ? [ 'id' => (int) $asset->model->category->id, diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index 4ce9fb843d..b44e584e01 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -57,15 +57,15 @@ name="accessory_users" class="table table-striped snipe-table" id="table" - data-url="{{ route('api.accessories.show', $accessory->id) }}" + data-url="{{ route('api.accessories.checkedout', $accessory->id) }}" data-cookie="true" data-click-to-select="true" data-cookie-id-table="accessoryUsersTable" > - {{ trans('general.user') }} - {{ trans('table.actions') }} + {{ trans('general.user') }} + {{ trans('table.actions') }} diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 91b8836283..d02d376aa8 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -139,7 +139,9 @@ $('.snipe-table').bootstrapTable({ // Use this when we're introspecting into a column object and need to link function genericColumnObjLinkFormatter(destination) { return function (value,row) { - if ((value) && (value.name)) { + if (value.status_type) { + return ' ' + value.name + ' ' + ''; + } else if ((value) && (value.name)) { return ' ' + value.name + ''; } }; @@ -228,8 +230,14 @@ $('.snipe-table').bootstrapTable({ return '
{{ trans('general.checkout') }}
'; // The user is allowed to check items in - } else if ((row.available_actions.checkin == true) && (row.assigned_to)) { - return '{{ trans('general.checkin') }}'; + } else if (row.available_actions.checkin == true) { + if (row.assigned_to) { + return '{{ trans('general.checkin') }}'; + } else if (row.assigned_pivot_id) { + return '{{ trans('general.checkin') }}'; + } + + } else { } From 42c2a66946cb26519b248b5ddfce06943ad4cea4 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Sep 2017 21:18:16 -0700 Subject: [PATCH 4/4] Small UI tweaks for accessories --- resources/views/accessories/checkin.blade.php | 105 ++++++++++-------- .../views/accessories/checkout.blade.php | 2 +- resources/views/hardware/view.blade.php | 4 +- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/resources/views/accessories/checkin.blade.php b/resources/views/accessories/checkin.blade.php index 5749be8f59..abc5e1f8b1 100755 --- a/resources/views/accessories/checkin.blade.php +++ b/resources/views/accessories/checkin.blade.php @@ -2,59 +2,76 @@ {{-- Page title --}} @section('title') - {{ trans('admin/hardware/general.checkin') }} + {{ trans('admin/accessories/general.checkin') }} @parent @stop +@section('header_right') + + {{ trans('general.back') }} +@stop + + {{-- Page content --}} @section('content') -
-
- {{ trans('general.back') }} -

{{ trans('general.checkin') }}

-
-
-
- -
-
- - +
+
+ + + - @if ($accessory->name) - -
- -
-

{{ $accessory->name }}

-
-
- @endif +
+ @if ($accessory->id) +
+

{{ $accessory->name }}

+
+ @endif - -
- -
- - {!! $errors->first('note', ' :message') !!} -
-
- -
- -
- {{ trans('button.cancel') }} - +
+ + + + + + @if ($accessory->name) + +
+ +
+

{{ $accessory->name }}

+
+
+ @endif + + +
+ +
+ + {!! $errors->first('note', ' :message') !!} +
+
+ +
+ +
+ {{ trans('button.cancel') }} + +
+
+ +
-
- - -
-
- + +
+ +
+
@stop diff --git a/resources/views/accessories/checkout.blade.php b/resources/views/accessories/checkout.blade.php index bf02673ede..d89ea825dc 100755 --- a/resources/views/accessories/checkout.blade.php +++ b/resources/views/accessories/checkout.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') - {{ trans('admin/hardware/general.checkout') }} + {{ trans('admin/accessories/general.checkout') }} @parent @stop @section('header_right') diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 2e86178189..cbe81166ef 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -87,8 +87,8 @@     @endif - {{ $asset->present()->statusText() }} - ({{ $asset->assetstatus->getStatuslabelType() }}) + {{ $asset->present()->statusText() }} + @endif