Skip to content

Commit 81b9753

Browse files
committed
Merge remote-tracking branch 'origin/develop'
Signed-off-by: snipe <[email protected]> # Conflicts: # public/js/dist/all-defer.js # public/mix-manifest.json
2 parents 50c9104 + b871813 commit 81b9753

27 files changed

+141
-62
lines changed

app/Http/Controllers/Api/AssetMaintenancesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function index(Request $request)
4848
}
4949

5050
if ($request->filled('supplier_id')) {
51-
$maintenances->where('supplier_id', '=', $request->input('supplier_id'));
51+
$maintenances->where('asset_maintenances.supplier_id', '=', $request->input('supplier_id'));
5252
}
5353

5454
if ($request->filled('asset_maintenance_type')) {

app/Importer/AccessoryImporter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ public function createAccessoryIfNotExists($row)
4646
$this->item['min_amt'] = $this->findCsvMatch($row, "min_amt");
4747
$accessory->fill($this->sanitizeItemForStoring($accessory));
4848

49-
//FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.
50-
// $accessory->unsetEventDispatcher();
49+
// This sets an attribute on the Loggable trait for the action log
50+
$accessory->setImported(true);
5151
if ($accessory->save()) {
52-
$accessory->logCreate('Imported using CSV Importer');
5352
$this->log('Accessory '.$this->item['name'].' was created');
5453

5554
return;

app/Importer/AssetImporter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public function createAssetIfNotExists(array $row)
135135
$asset->{$custom_field} = $val;
136136
}
137137
}
138-
138+
// This sets an attribute on the Loggable trait for the action log
139+
$asset->setImported(true);
139140
if ($asset->save()) {
140141

141-
$asset->logCreate(trans('general.importer.import_note'));
142142
$this->log('Asset '.$this->item['name'].' with serial number '.$this->item['serial'].' was created');
143143

144144
// If we have a target to checkout to, lets do so.

app/Importer/ComponentImporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function createComponentIfNotExists()
4848
$this->log('No matching component, creating one');
4949
$component = new Component;
5050
$component->fill($this->sanitizeItemForStoring($component));
51-
//FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.
52-
$component->unsetEventDispatcher();
51+
52+
// This sets an attribute on the Loggable trait for the action log
53+
$component->setImported(true);
5354
if ($component->save()) {
54-
$component->logCreate('Imported using CSV Importer');
5555
$this->log('Component '.$this->item['name'].' was created');
5656

5757
// If we have an asset tag, checkout to that asset.

app/Importer/ConsumableImporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function createConsumableIfNotExists($row)
4545
$this->item['item_no'] = trim($this->findCsvMatch($row, 'item_number'));
4646
$this->item['min_amt'] = trim($this->findCsvMatch($row, "min_amt"));
4747
$consumable->fill($this->sanitizeItemForStoring($consumable));
48-
//FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.
49-
$consumable->unsetEventDispatcher();
48+
49+
// This sets an attribute on the Loggable trait for the action log
50+
$consumable->setImported(true);
5051
if ($consumable->save()) {
51-
$consumable->logCreate('Imported using CSV Importer');
5252
$this->log('Consumable '.$this->item['name'].' was created');
5353

5454
return;

app/Importer/LicenseImporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ public function createLicenseIfNotExists(array $row)
8585
} else {
8686
$license->fill($this->sanitizeItemForStoring($license));
8787
}
88-
//FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything.
89-
// $license->unsetEventDispatcher();
88+
89+
// This sets an attribute on the Loggable trait for the action log
90+
$license->setImported(true);
9091
if ($license->save()) {
91-
$license->logCreate('Imported using csv importer');
9292
$this->log('License '.$this->item['name'].' with serial number '.$this->item['serial'].' was created');
9393

9494
// Lets try to checkout seats if the fields exist and we have seats.

app/Listeners/CheckoutableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function onCheckedIn($event)
115115
);
116116
}
117117
//slack doesn't include the url in its messaging format so this is needed to hit the endpoint
118-
if(Setting::getSettings()->webhook_selected =='slack') {
118+
if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
119119

120120
if ($this->shouldSendWebhookNotification()) {
121121
Notification::route('slack', Setting::getSettings()->webhook_endpoint)

app/Models/Actionlog.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Actionlog extends SnipeModel
1919
{
2020
use HasFactory;
2121

22+
// This is to manually set the source (via setActionSource()) for determineActionSource()
23+
protected ?string $source = null;
24+
2225
protected $presenter = \App\Presenters\ActionlogPresenter::class;
2326
use SoftDeletes;
2427
use Presentable;
@@ -341,7 +344,12 @@ public function getListingOfActionLogsChronologicalOrder()
341344
* @since v6.3.0
342345
* @return string
343346
*/
344-
public function determineActionSource() {
347+
public function determineActionSource(): string
348+
{
349+
// This is a manually set source
350+
if($this->source) {
351+
return $this->source;
352+
}
345353

346354
// This is an API call
347355
if (((request()->header('content-type') && (request()->header('accept'))=='application/json'))
@@ -358,4 +366,10 @@ public function determineActionSource() {
358366
return 'cli/unknown';
359367

360368
}
369+
370+
// Manually sets $this->source for determineActionSource()
371+
public function setActionSource($source = null): void
372+
{
373+
$this->source = $source;
374+
}
361375
}

app/Models/Loggable.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
trait Loggable
1010
{
11+
// an attribute for setting whether or not the item was imported
12+
public ?bool $imported = false;
13+
1114
/**
1215
* @author Daniel Meltzer <[email protected]>
1316
* @since [v3.4]
@@ -18,6 +21,11 @@ public function log()
1821
return $this->morphMany(Actionlog::class, 'item');
1922
}
2023

24+
public function setImported(bool $bool): void
25+
{
26+
$this->imported = $bool;
27+
}
28+
2129
/**
2230
* @author Daniel Meltzer <[email protected]>
2331
* @since [v3.4]

app/Observers/AccessoryObserver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function created(Accessory $accessory)
3838
$logAction->item_id = $accessory->id;
3939
$logAction->created_at = date('Y-m-d H:i:s');
4040
$logAction->user_id = Auth::id();
41+
if($accessory->imported) {
42+
$logAction->setActionSource('importer');
43+
}
4144
$logAction->logaction('create');
4245
}
4346

0 commit comments

Comments
 (0)