Merge pull request #12764 from marcusmoore/fixes/importer-fix

Fixes potential unwanted overwrites in asset imports
This commit is contained in:
snipe 2023-03-30 09:40:58 -07:00 committed by GitHub
commit 10c1e923dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -60,7 +60,7 @@ class AssetImporter extends ItemImporter
$asset_tag = Asset::autoincrement_asset();
}
$asset = Asset::where(['asset_tag'=> $asset_tag])->first();
$asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first();
if ($asset) {
if (! $this->updating) {
$this->log('A matching Asset '.$asset_tag.' already exists');

View file

@ -422,6 +422,8 @@ return [
'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)',
'clear_and_save' => 'Clear & Save',
'update_existing_values' => 'Update Existing Values?',
'auto_incrementing_asset_tags_disabled_so_tags_required' => 'Generating auto-incrementing asset tags is disabled so all rows need to have the "Asset Tag" column populated.',
'auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created' => 'Note: Generating auto-incrementing asset tags is enabled so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information.',
'send_welcome_email_to_users' => ' Send Welcome Email for new Users?',
'back_before_importing' => 'Backup before importing?',
'csv_header_field' => 'CSV Header Field',

View file

@ -156,26 +156,36 @@
'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
'data-livewire-component' => $_instance->id
]) }}
@if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 0)
<span class="help-block">
{{ trans('general.auto_incrementing_asset_tags_disabled_so_tags_required') }}
</span>
@endif
</div>
</div>
<div class="form-group col-md-12">
<label for="update" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}">
<label for="update" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}" wire:model="update">
{{ trans('general.update_existing_values') }}
@if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 1 && $update)
<span class="help-block">
{{ trans('general.auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created') }}
</span>
@endif
</label>
</div>
<div class="form-group col-md-12">
<label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}">
<label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}" wire:model="send_welcome">
{{ trans('general.send_welcome_email_to_users') }}
</label>
</div>
<div class="form-group col-md-12">
<label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}">
<label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}" wire:model="run_backup">
{{ trans('general.back_before_importing') }}
</label>
</div>
@ -379,4 +389,4 @@
});})
</script>
@endpush
@endpush