mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-13 06:47:46 -08:00
More refactoring
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
f9d5c451bc
commit
4723cfd4ba
|
@ -120,8 +120,8 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
||||||
|
|
||||||
// \Log::debug('ALL Custom fields columns - these may or may not apply: ');
|
\Log::debug('ALL Custom fields columns - these may or may not apply: ');
|
||||||
// \Log::debug(print_r($custom_field_columns, true));
|
\Log::debug(print_r($custom_field_columns, true));
|
||||||
|
|
||||||
if (! $request->filled('ids') || count($request->input('ids')) == 0) {
|
if (! $request->filled('ids') || count($request->input('ids')) == 0) {
|
||||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||||
|
@ -139,14 +139,14 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// We should tighten checks here - burpsuite could punch through this I'd pull the custom fields for new and old here
|
/**
|
||||||
if ($request->anyFilled($custom_field_columns)) {
|
* If ANY of these are filled, prepare to update the values on the assets.
|
||||||
$custom_fields_present = true;
|
*
|
||||||
} else {
|
* Additional checks will be needed for some of them to make sure the values
|
||||||
$custom_fields_present = false;
|
* make sense (for example, changing the status ID to something incompatible with
|
||||||
}
|
* its checkout status.
|
||||||
|
*/
|
||||||
|
|
||||||
// If ANY of these are filled, prepare to update the values on the assets
|
|
||||||
if (($request->filled('purchase_date'))
|
if (($request->filled('purchase_date'))
|
||||||
|| ($request->filled('expected_checkin'))
|
|| ($request->filled('expected_checkin'))
|
||||||
|| ($request->filled('purchase_cost'))
|
|| ($request->filled('purchase_cost'))
|
||||||
|
@ -170,14 +170,17 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
$this->update_array = [];
|
$this->update_array = [];
|
||||||
|
|
||||||
// Leave out model_id and sttaus here because we do math on that later. We have to d some extra
|
/**
|
||||||
// validation and checks on those two
|
* Leave out model_id and status here because we do math on that later. We have to do some extra
|
||||||
|
* validation and checks on those two.
|
||||||
|
*
|
||||||
|
* It's tempting to make these match the request check above, but some of these values require
|
||||||
|
* extra work to make sure the data makes sense.
|
||||||
|
*/
|
||||||
$this->conditionallyAddItem('purchase_date')
|
$this->conditionallyAddItem('purchase_date')
|
||||||
->conditionallyAddItem('expected_checkin')
|
->conditionallyAddItem('expected_checkin')
|
||||||
->conditionallyAddItem('order_number')
|
->conditionallyAddItem('order_number')
|
||||||
->conditionallyAddItem('requestable')
|
->conditionallyAddItem('requestable')
|
||||||
->conditionallyAddItem('model_id')
|
|
||||||
->conditionallyAddItem('status_id')
|
|
||||||
->conditionallyAddItem('supplier_id')
|
->conditionallyAddItem('supplier_id')
|
||||||
->conditionallyAddItem('warranty_months')
|
->conditionallyAddItem('warranty_months')
|
||||||
->conditionallyAddItem('next_audit_date');
|
->conditionallyAddItem('next_audit_date');
|
||||||
|
@ -211,6 +214,53 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We're trying to change the model ID - we need to do some extra checks here to make sure
|
||||||
|
* the custom field values work for the custom fieldset rules around this asset. Uniqueness
|
||||||
|
* and requiredness across the fieldset is particularly important, since those are
|
||||||
|
* fieldset-specific attributes.
|
||||||
|
*/
|
||||||
|
if ($request->filled('model_id')) {
|
||||||
|
\Log::debug('Change the model ID!');
|
||||||
|
$asset->model_id = Model::find($request->input('model_id'))->id;
|
||||||
|
\Log::debug('New model ID is:'.$asset->model_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We're trying to change the status ID - we need to do some extra checks here to
|
||||||
|
* make sure the status label type is one that makes sense for the state of the asset,
|
||||||
|
* for example, we shouldn't be able to make an asset archived if it's currently assigned
|
||||||
|
* to someone/something.
|
||||||
|
*/
|
||||||
|
if ($request->filled('status_id')) {
|
||||||
|
\Log::debug('Change the status ID!');
|
||||||
|
$updated_status = Statuslabel::find($request->input('status_id'));
|
||||||
|
\Log::debug('New status ID is:'.$updated_status->id);
|
||||||
|
\Log::debug('Status label type is: '.$updated_status->getStatuslabelType());
|
||||||
|
|
||||||
|
// We cannot assign a non-deployable status type if the asset is already assigned.
|
||||||
|
// This could probably be added to a form request.
|
||||||
|
// If the asset isn't assigned, we don't care what the status is.
|
||||||
|
// Otherwise we need to make sure the status type is still a deployable one.
|
||||||
|
if (
|
||||||
|
($asset->assigned_to == '')
|
||||||
|
|| ($updated_status->deployable == '1') && ($asset->assetstatus->deployable == '1')
|
||||||
|
) {
|
||||||
|
$asset->status_id = $updated_status->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We're changing the location ID - figure out which location we should apply
|
||||||
|
* this change to:
|
||||||
|
*
|
||||||
|
* 0 - RTD location only
|
||||||
|
* 1 - location ID and RTD location ID
|
||||||
|
* 2 - location ID only
|
||||||
|
*
|
||||||
|
* Note: this is kinda dumb and we should just use human-readable values IMHO. - snipe
|
||||||
|
*/
|
||||||
if ($request->filled('rtd_location_id')) {
|
if ($request->filled('rtd_location_id')) {
|
||||||
|
|
||||||
if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '0')) {
|
if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '0')) {
|
||||||
|
@ -229,30 +279,34 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Anything that happens past this WILL NOT BE logged in the edit log
|
/**
|
||||||
|
* ------------------------------------------------------------------------------
|
||||||
|
* ANYTHING that happens past this foreach
|
||||||
|
* WILL NOT BE logged in the edit log_meta data
|
||||||
|
* ------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
$changed = [];
|
$changed = [];
|
||||||
|
|
||||||
foreach ($this->update_array as $key => $value) {
|
foreach ($this->update_array as $key => $value) {
|
||||||
|
|
||||||
if ($this->update_array[$key] != $asset->{$key}) {
|
if ($this->update_array[$key] != $asset->{$key}) {
|
||||||
$changed[$key]['old'] = $asset->{$key};
|
$changed[$key]['old'] = $asset->{$key};
|
||||||
$changed[$key]['new'] = $this->update_array[$key];
|
$changed[$key]['new'] = $this->update_array[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
\Log::debug('What changed?');
|
\Log::debug('What changed?');
|
||||||
\Log::debug(print_r($changed, true));
|
\Log::debug(print_r($changed, true));
|
||||||
|
|
||||||
|
|
||||||
/** Start all the custom fields shenanigans */
|
/**
|
||||||
if ($custom_fields_present) {
|
* Start all the custom fields shenanigans
|
||||||
|
*/
|
||||||
|
|
||||||
// Make sure this model is valid
|
// Does the model have a fieldset?
|
||||||
// ALISON - FIX THIS BEFORE PUSHING
|
if ($asset->model->fieldset) {
|
||||||
$assetCustomFields = ($request->input('model_id')) ? $request->input('model_id')->fieldset : null;
|
foreach ($asset->model->fieldset->fields as $field) {
|
||||||
|
|
||||||
if ($assetCustomFields && $assetCustomFields->fields) {
|
|
||||||
|
|
||||||
foreach ($assetCustomFields->fields as $field) {
|
|
||||||
|
|
||||||
if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted == '1')) {
|
if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted == '1')) {
|
||||||
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
||||||
|
@ -291,8 +345,8 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
} // endforeach
|
} // endforeach
|
||||||
} // end custom field check
|
}
|
||||||
} // end custom fields handler
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ class Asset extends Depreciable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if an asset is available for checkout.
|
* Determines if an asset is available for checkout.
|
||||||
* This checks to see if the it's checked out to an invalid (deleted) user
|
* This checks to see if it's checked out to an invalid (deleted) user
|
||||||
* OR if the assigned_to and deleted_at fields on the asset are empty AND
|
* OR if the assigned_to and deleted_at fields on the asset are empty AND
|
||||||
* that the status is deployable
|
* that the status is deployable
|
||||||
*
|
*
|
||||||
|
@ -292,6 +292,31 @@ class Asset extends Depreciable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if an asset is available for checkout.
|
||||||
|
* This checks to see if it's checked out to an invalid (deleted) user
|
||||||
|
* OR if the assigned_to and deleted_at fields on the asset are empty AND
|
||||||
|
* that the status is deployable
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v3.0]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDeployableMeta()
|
||||||
|
{
|
||||||
|
|
||||||
|
// The asset status is not archived and is deployable
|
||||||
|
if (($this->assetstatus) && ($this->assetstatus->archived == '0') && (! $this->deleted_at)
|
||||||
|
&& ($this->assetstatus->deployable == '1'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the asset out to the target
|
* Checks the asset out to the target
|
||||||
*
|
*
|
||||||
|
@ -753,7 +778,7 @@ class Asset extends Depreciable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the asset -> status relationship
|
* Establishes the asset -> license seats relationship
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
|
|
|
@ -21,15 +21,16 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="callout callout-warning">
|
|
||||||
<i class="fas fa-exclamation-triangle"></i> {{ trans_choice('admin/hardware/form.bulk_update_warn', count($assets), ['asset_count' => count($assets)]) }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form class="form-horizontal" method="post" action="{{ route('hardware/bulksave') }}" autocomplete="off" role="form">
|
<form class="form-horizontal" method="post" action="{{ route('hardware/bulksave') }}" autocomplete="off" role="form">
|
||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
|
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
|
|
||||||
|
<div class="callout callout-warning">
|
||||||
|
<i class="fas fa-exclamation-triangle"></i> {{ trans_choice('admin/hardware/form.bulk_update_warn', count($assets), ['asset_count' => count($assets)]) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Purchase Date -->
|
<!-- Purchase Date -->
|
||||||
<div class="form-group {{ $errors->has('purchase_date') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('purchase_date') ? ' has-error' : '' }}">
|
||||||
<label for="purchase_date" class="col-md-3 control-label">{{ trans('admin/hardware/form.date') }}</label>
|
<label for="purchase_date" class="col-md-3 control-label">{{ trans('admin/hardware/form.date') }}</label>
|
||||||
|
@ -75,6 +76,7 @@
|
||||||
</label>
|
</label>
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
{{ Form::select('status_id', $statuslabel_list , old('status_id'), array('class'=>'select2', 'style'=>'width:100%', 'aria-label'=>'status_id')) }}
|
{{ Form::select('status_id', $statuslabel_list , old('status_id'), array('class'=>'select2', 'style'=>'width:100%', 'aria-label'=>'status_id')) }}
|
||||||
|
<p class="help-block">If assets are already assigned, they cannot be changed to a non-deployable status type and this value change will be skipped.</p>
|
||||||
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
{!! $errors->first('status_id', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue