mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Log checkouts (#2772)
* Ensure the log has a target before trying to fetch the associated company * Log creation of items, both in importer and manually
This commit is contained in:
parent
219ef23126
commit
e85241af6a
|
@ -856,6 +856,7 @@ class ObjectImportCommand extends Command
|
|||
if (!$this->option('testrun')) {
|
||||
|
||||
if ($asset->save()) {
|
||||
$asset->logCreate('Imported using csv importer');
|
||||
$this->log('Asset ' . $item["item_name"] . ' with serial number ' . $asset_serial . ' was created');
|
||||
} else {
|
||||
$this->jsonError('Asset', $asset->getErrors());
|
||||
|
@ -941,6 +942,7 @@ class ObjectImportCommand extends Command
|
|||
|
||||
if (!$this->option('testrun')) {
|
||||
if ($accessory->save()) {
|
||||
$accessory->logCreate('Imported using CSV Importer');
|
||||
$this->log('Accessory ' . $item["item_name"] . ' was created');
|
||||
// $this->comment('Accessory ' . $item["item_name"] . ' was created');
|
||||
|
||||
|
@ -1025,6 +1027,7 @@ class ObjectImportCommand extends Command
|
|||
if (!$this->option("testrun")) {
|
||||
// dd($consumable);
|
||||
if ($consumable->save()) {
|
||||
$consumable->logCreate('Imported using CSV Importer');
|
||||
$this->log("Consumable " . $item["item_name"] . ' was created');
|
||||
// $this->comment("Consumable " . $item["item_name"] . ' was created');
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ class AccessoriesController extends Controller
|
|||
|
||||
// Was the accessory created?
|
||||
if ($accessory->save()) {
|
||||
$accessory->logCreate();
|
||||
// Redirect to the new accessory page
|
||||
return redirect()->to("admin/accessories")->with('success', trans('admin/accessories/message.create.success'));
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ class AssetsController extends Controller
|
|||
|
||||
// Was the asset created?
|
||||
if ($asset->save()) {
|
||||
|
||||
$asset->logCreate();
|
||||
if (Input::get('assigned_to')!='') {
|
||||
$user = User::find(e(Input::get('assigned_to')));
|
||||
$asset->checkOutToUser($user, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name')));
|
||||
|
|
|
@ -107,6 +107,7 @@ class ComponentsController extends Controller
|
|||
|
||||
// Was the component created?
|
||||
if ($component->save()) {
|
||||
$component->logCreate();
|
||||
// Redirect to the new component page
|
||||
return redirect()->to("admin/components")->with('success', trans('admin/components/message.create.success'));
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ class ConsumablesController extends Controller
|
|||
|
||||
// Was the consumable created?
|
||||
if ($consumable->save()) {
|
||||
$consumable->logCreate();
|
||||
// Redirect to the new consumable page
|
||||
return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.create.success'));
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ class LicensesController extends Controller
|
|||
|
||||
// Was the license created?
|
||||
if ($license->save()) {
|
||||
|
||||
$license->logCreate();
|
||||
$insertedId = $license->id;
|
||||
// Save the license seat data
|
||||
DB::transaction(function () use (&$insertedId, &$license) {
|
||||
|
|
|
@ -30,7 +30,11 @@ class Actionlog extends Model
|
|||
static::creating( function (Actionlog $actionlog) {
|
||||
// If the admin is a superadmin, let's see if the target instead has a company.
|
||||
if (Auth::user() && Auth::user()->isSuperUser()) {
|
||||
$actionlog->company_id = $actionlog->target->company_id;
|
||||
if ($actionlog->target) {
|
||||
$actionlog->company_id = $actionlog->target->company_id;
|
||||
} else if ($actionlog->item) {
|
||||
$actionlog->company_id = $actionlog->item->company_id;
|
||||
}
|
||||
} else if (Auth::user() && Auth::user()->company) {
|
||||
$actionlog->company_id = Auth::user()->company_id;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,29 @@ trait Loggable
|
|||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <parallelgrapefruit@gmail.com
|
||||
* @since [v3.4]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logCreate($note = null)
|
||||
{
|
||||
$log = new Actionlog;
|
||||
if (static::class == LicenseSeat::class) {
|
||||
$log->item_type = License::class;
|
||||
$log->item_id = $this->license_id;
|
||||
} else {
|
||||
$log->item_type = static::class;
|
||||
$log->item_id = $this->id;
|
||||
}
|
||||
$log->location_id = null;
|
||||
$log->note = $note;
|
||||
$log->user_id = Auth::user()->id;
|
||||
$log->logaction('created');
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <parallelgrapefruit@gmail.com
|
||||
* @since [v3.4]
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
'consumables' => 'Consumables',
|
||||
'country' => 'Country',
|
||||
'create' => 'Create New',
|
||||
'created' => 'Item Created',
|
||||
'created_asset' => 'created asset',
|
||||
'created_at' => 'Created at',
|
||||
'currency' => '$', // this is deprecated
|
||||
|
|
Loading…
Reference in a new issue