Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2023-06-29 16:23:35 +01:00
commit 4908082240
16 changed files with 46 additions and 39 deletions

View file

@ -125,6 +125,8 @@ class AssetsController extends Controller
$assets->InModelList($non_deprecable_models->toArray()); $assets->InModelList($non_deprecable_models->toArray());
} }
// These are used by the API to query against specific ID numbers. // These are used by the API to query against specific ID numbers.
// They are also used by the individual searches on detail pages like // They are also used by the individual searches on detail pages like
// locations, etc. // locations, etc.
@ -136,12 +138,11 @@ class AssetsController extends Controller
} }
} }
if ((! is_null($filter)) && (count($filter)) > 0) {
// Make sure the offset and limit are actually integers and do not exceed system limits $assets->ByFilter($filter);
$offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset')); } elseif ($request->filled('search')) {
$limit = app('api_limit_value'); $assets->TextSearch($request->input('search'));
}
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
// This is used by the audit reporting routes // This is used by the audit reporting routes
if (Gate::allows('audit', Asset::class)) { if (Gate::allows('audit', Asset::class)) {
@ -156,7 +157,6 @@ class AssetsController extends Controller
} }
// This is used by the sidenav, mostly // This is used by the sidenav, mostly
// We switched from using query scopes here because of a Laravel bug // We switched from using query scopes here because of a Laravel bug
@ -206,7 +206,7 @@ class AssetsController extends Controller
break; break;
case 'Deployed': case 'Deployed':
// more sad, horrible workarounds for laravel bugs when doing full text searches // more sad, horrible workarounds for laravel bugs when doing full text searches
$assets->where('assets.assigned_to', '>', '0'); $assets->whereNotNull('assets.assigned_to');
break; break;
case 'byod': case 'byod':
// This is kind of redundant, since we already check for byod=1 above, but this keeps the // This is kind of redundant, since we already check for byod=1 above, but this keeps the
@ -232,12 +232,6 @@ class AssetsController extends Controller
} }
if ((! is_null($filter)) && (count($filter)) > 0) {
$assets->ByFilter($filter);
} elseif ($request->filled('search')) {
$assets->TextSearch($request->input('search'));
}
// Leave these under the TextSearch scope, else the fuzziness will override the specific ID (status ID, etc) requested // Leave these under the TextSearch scope, else the fuzziness will override the specific ID (status ID, etc) requested
if ($request->filled('status_id')) { if ($request->filled('status_id')) {
$assets->where('assets.status_id', '=', $request->input('status_id')); $assets->where('assets.status_id', '=', $request->input('status_id'));
@ -313,6 +307,7 @@ class AssetsController extends Controller
// in the allowed_columns array) // in the allowed_columns array)
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.created_at'; $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.created_at';
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
switch ($sort_override) { switch ($sort_override) {
case 'model': case 'model':
@ -350,6 +345,10 @@ class AssetsController extends Controller
} }
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset'));
$limit = app('api_limit_value');
$total = $assets->count(); $total = $assets->count();
$assets = $assets->skip($offset)->take($limit)->get(); $assets = $assets->skip($offset)->take($limit)->get();

View file

@ -82,7 +82,7 @@ class ViewAssetsController extends Controller
return view('account/requestable-assets', compact('assets', 'models')); return view('account/requestable-assets', compact('assets', 'models'));
} }
public function getRequestItem(Request $request, $itemType, $itemId = null) public function getRequestItem(Request $request, $itemType, $itemId = null, $cancel_by_admin = false, $requestingUser = null)
{ {
$item = null; $item = null;
$fullItemType = 'App\\Models\\'.studly_case($itemType); $fullItemType = 'App\\Models\\'.studly_case($itemType);
@ -119,16 +119,16 @@ class ViewAssetsController extends Controller
$settings = Setting::getSettings(); $settings = Setting::getSettings();
if ($item_request = $item->isRequestedBy($user)) { if (($item_request = $item->isRequestedBy($user)) || $cancel_by_admin) {
$item->cancelRequest(); $item->cancelRequest($requestingUser);
$data['item_quantity'] = $item_request->qty; $data['item_quantity'] = ($item_request) ? $item_request->qty : 1;
$logaction->logaction('request_canceled'); $logaction->logaction('request_canceled');
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) { if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
$settings->notify(new RequestAssetCancelation($data)); $settings->notify(new RequestAssetCancelation($data));
} }
return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); return redirect()->back()->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
} else { } else {
$item->request(); $item->request();
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) { if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {

View file

@ -32,7 +32,7 @@ class AccessoriesTransformer
'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null, 'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null,
'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null, 'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null,
'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null, 'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null,
'notes' => ($accessory->notes) ? e($accessory->notes) : null, 'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedown($accessory->notes) : null,
'qty' => ($accessory->qty) ? (int) $accessory->qty : null, 'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null, 'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null,
'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost),

View file

@ -110,7 +110,7 @@ class ActionlogsTransformer
'type' => e($actionlog->targetType()), 'type' => e($actionlog->targetType()),
] : null, ] : null,
'note' => ($actionlog->note) ? e($actionlog->note): null, 'note' => ($actionlog->note) ? Helper::parseEscapedMarkedown($actionlog->note): null,
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null, 'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null, 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),

View file

@ -49,7 +49,7 @@ class AssetMaintenancesTransformer
'id' => (int) $assetmaintenance->asset->defaultLoc->id, 'id' => (int) $assetmaintenance->asset->defaultLoc->id,
'name'=> e($assetmaintenance->asset->defaultLoc->name), 'name'=> e($assetmaintenance->asset->defaultLoc->name),
] : null, ] : null,
'notes' => ($assetmaintenance->notes) ? e($assetmaintenance->notes) : null, 'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedown($assetmaintenance->notes) : null,
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null, 'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null,
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost), 'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type), 'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),

View file

@ -63,7 +63,7 @@ class AssetModelsTransformer
'default_fieldset_values' => $default_field_values, 'default_fieldset_values' => $default_field_values,
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None', 'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None',
'requestable' => ($assetmodel->requestable == '1') ? true : false, 'requestable' => ($assetmodel->requestable == '1') ? true : false,
'notes' => e($assetmodel->notes), 'notes' => Helper::parseEscapedMarkedown($assetmodel->notes),
'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'), 'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'),

View file

@ -58,7 +58,7 @@ class AssetsTransformer
'id' => (int) $asset->supplier->id, 'id' => (int) $asset->supplier->id,
'name'=> e($asset->supplier->name), 'name'=> e($asset->supplier->name),
] : null, ] : null,
'notes' => ($asset->notes) ? e($asset->notes) : null, 'notes' => ($asset->notes) ? Helper::parseEscapedMarkedown($asset->notes) : null,
'order_number' => ($asset->order_number) ? e($asset->order_number) : null, 'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
'company' => ($asset->company) ? [ 'company' => ($asset->company) ? [
'id' => (int) $asset->company->id, 'id' => (int) $asset->company->id,

View file

@ -46,7 +46,7 @@ class ComponentsTransformer
'id' => (int) $component->company->id, 'id' => (int) $component->company->id,
'name' => e($component->company->name), 'name' => e($component->company->name),
] : null, ] : null,
'notes' => ($component->notes) ? e($component->notes) : null, 'notes' => ($component->notes) ? Helper::parseEscapedMarkedown($component->notes) : null,
'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'),
'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0, 'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0,

View file

@ -39,7 +39,7 @@ class ConsumablesTransformer
'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost),
'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'), 'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'),
'qty' => (int) $consumable->qty, 'qty' => (int) $consumable->qty,
'notes' => ($consumable->notes) ? e($consumable->notes) : null, 'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedown($consumable->notes) : null,
'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'),
]; ];

View file

@ -34,7 +34,7 @@ class LicensesTransformer
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null, 'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
'purchase_cost_numeric' => $license->purchase_cost, 'purchase_cost_numeric' => $license->purchase_cost,
'notes' => e($license->notes), 'notes' => Helper::parseEscapedMarkedown($license->notes),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
'seats' => (int) $license->seats, 'seats' => (int) $license->seats,
'free_seats_count' => (int) $license->free_seats_count, 'free_seats_count' => (int) $license->free_seats_count,

View file

@ -43,7 +43,7 @@ class SuppliersTransformer
'licenses_count' => (int) $supplier->licenses_count, 'licenses_count' => (int) $supplier->licenses_count,
'consumables_count' => (int) $supplier->consumables_count, 'consumables_count' => (int) $supplier->consumables_count,
'components_count' => (int) $supplier->components_count, 'components_count' => (int) $supplier->components_count,
'notes' => ($supplier->notes) ? e($supplier->notes) : null, 'notes' => ($supplier->notes) ? Helper::parseEscapedMarkedown($supplier->notes) : null,
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),

View file

@ -53,7 +53,7 @@ class UsersTransformer
'id' => (int) $user->userloc->id, 'id' => (int) $user->userloc->id,
'name'=> e($user->userloc->name), 'name'=> e($user->userloc->name),
] : null, ] : null,
'notes'=> e($user->notes), 'notes'=> Helper::parseEscapedMarkedown($user->notes),
'permissions' => $user->decodePermissions(), 'permissions' => $user->decodePermissions(),
'activated' => ($user->activated == '1') ? true : false, 'activated' => ($user->activated == '1') ? true : false,
'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false, 'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false,

View file

@ -38,8 +38,12 @@ trait Requestable
$this->requests()->where('user_id', Auth::id())->delete(); $this->requests()->where('user_id', Auth::id())->delete();
} }
public function cancelRequest() public function cancelRequest($user_id = null)
{ {
$this->requests()->where('user_id', Auth::id())->update(['canceled_at' => \Carbon\Carbon::now()]); if (!$user_id){
$user_id = Auth::id();
}
$this->requests()->where('user_id', $user_id)->update(['canceled_at' => \Carbon\Carbon::now()]);
} }
} }

View file

@ -436,6 +436,7 @@ return [
'errors_importing' => 'Some Errors occurred while importing: ', 'errors_importing' => 'Some Errors occurred while importing: ',
'warning' => 'WARNING: :warning', 'warning' => 'WARNING: :warning',
'success_redirecting' => '"Success... Redirecting.', 'success_redirecting' => '"Success... Redirecting.',
'cancel_request' => 'Cancel this item request',
'setup_successful_migrations' => 'Your database tables have been created', 'setup_successful_migrations' => 'Your database tables have been created',
'setup_migration_output' => 'Migration output:', 'setup_migration_output' => 'Migration output:',
'setup_migration_create_user' => 'Next: Create User', 'setup_migration_create_user' => 'Next: Create User',

View file

@ -17,11 +17,6 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="box"> <div class="box">
<div class="box-body"> <div class="box-body">
{{ Form::open([
'method' => 'POST',
'route' => ['hardware/bulkedit'],
'class' => 'form-inline',
'id' => 'bulkForm']) }}
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@ -51,7 +46,7 @@
<th class="col-md-2" data-sortable="true">{{ trans('admin/hardware/form.expected_checkin') }}</th> <th class="col-md-2" data-sortable="true">{{ trans('admin/hardware/form.expected_checkin') }}</th>
<th class="col-md-3" data-sortable="true">{{ trans('admin/hardware/table.requesting_user') }}</th> <th class="col-md-3" data-sortable="true">{{ trans('admin/hardware/table.requesting_user') }}</th>
<th class="col-md-2">{{ trans('admin/hardware/table.requested_date') }}</th> <th class="col-md-2">{{ trans('admin/hardware/table.requested_date') }}</th>
<th class="col-md-1">{{ trans('general.checkin').'/'.trans('general.checkout') }}</th> <th class="col-md-1">{{ trans('button.actions') }}</th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -103,6 +98,14 @@
@endif @endif
</td> </td>
<td>{{ App\Helpers\Helper::getFormattedDateObject($request->created_at, 'datetime', false) }}</td> <td>{{ App\Helpers\Helper::getFormattedDateObject($request->created_at, 'datetime', false) }}</td>
<td>
{{ Form::open([
'method' => 'POST',
'route' => ['account/request-item', $request->itemType(), $request->requestable->id, true, $request->requestingUser()->id],
]) }}
<button class="btn btn-warning btn-sm" data-tooltip="true" title="{{ trans('general.cancel_request') }}">{{ trans('button.cancel') }}</button>
{{ Form::close() }}
</td>
<td> <td>
@if ($request->itemType() == "asset") @if ($request->itemType() == "asset")
@if ($request->requestable->assigned_to=='') @if ($request->requestable->assigned_to=='')

View file

@ -281,7 +281,7 @@ Route::group(['prefix' => 'account', 'middleware' => ['auth']], function () {
)->name('account/request-asset'); )->name('account/request-asset');
Route::post( Route::post(
'request/{itemType}/{itemId}', 'request/{itemType}/{itemId}/{cancel_by_admin?}/{requestingUser?}',
[ViewAssetsController::class, 'getRequestItem'] [ViewAssetsController::class, 'getRequestItem']
)->name('account/request-item'); )->name('account/request-item');