diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index 4d5a1b2a4f..ebafd9a98e 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -22,10 +22,21 @@ class CompaniesController extends Controller { $this->authorize('view', Company::class); - $allowed_columns = ['id','name']; + $allowed_columns = [ + 'id', + 'name', + 'created_at', + 'updated_at', + 'users_count', + 'assets_count', + 'licenses_count', + 'accessories_count', + 'consumables_count', + 'components_count', + ]; $companies = Company::withCount('assets','licenses','accessories','consumables','components','users') - ->withCount('users')->withCount('users')->withCount('assets') + ->withCount('users')->withCount('assets') ->withCount('licenses')->withCount('accessories') ->withCount('consumables')->withCount('components'); diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index 4e7a3c4ed7..894d0daa17 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -149,7 +149,7 @@ class ComponentsController extends Controller */ public function getAssets(Request $request, $id) { - $this->authorize('index', Asset::class); + $this->authorize('view', \App\Models\Asset::class); $component = Component::findOrFail($id); $assets = $component->assets(); diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index a2598dca63..4fc6d8d2b4 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -219,7 +219,7 @@ class AssetsController extends Controller // Was the asset created? if ($asset->save()) { - $asset->logCreate(); + if (request('assigned_user')) { $target = User::find(request('assigned_user')); diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index 559f979fad..bfbcbb3b69 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -315,7 +315,7 @@ class LicensesController extends Controller $licenseSeat->asset_id = $request->input('asset_id'); // Override asset's assigned user if available - if ($target->assigned_to!='') { + if ($target->checkedOutToUser()) { $licenseSeat->assigned_to = $target->assigned_to; } diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index ea7b615617..3bb9142083 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -54,6 +54,7 @@ class ActionlogsTransformer 'note' => ($actionlog->note) ? e($actionlog->note): null, 'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null, + 'log_meta' => ($actionlog->log_meta) ? json_decode($actionlog->log_meta): null, ]; diff --git a/app/Http/Transformers/AssetModelsTransformer.php b/app/Http/Transformers/AssetModelsTransformer.php index 8c94f00577..f9ba38160e 100644 --- a/app/Http/Transformers/AssetModelsTransformer.php +++ b/app/Http/Transformers/AssetModelsTransformer.php @@ -53,7 +53,7 @@ class AssetModelsTransformer $permissions_array['available_actions'] = [ 'update' => (Gate::allows('update', AssetModel::class) && ($assetmodel->deleted_at=='')) ? true : false, - 'delete' => (Gate::allows('delete', AssetModel::class) && ($assetmodel->deleted_at=='')) ? true : false, + 'delete' => (Gate::allows('delete', AssetModel::class) && ($assetmodel->assets_count==0) && ($assetmodel->deleted_at=='')) ? true : false, 'clone' => (Gate::allows('create', AssetModel::class) && ($assetmodel->deleted_at=='')) , 'restore' => (Gate::allows('create', AssetModel::class) && ($assetmodel->deleted_at!='')) ? true : false, ]; diff --git a/app/Http/Transformers/CompaniesTransformer.php b/app/Http/Transformers/CompaniesTransformer.php index d8f89ea3b0..e4e8a48711 100644 --- a/app/Http/Transformers/CompaniesTransformer.php +++ b/app/Http/Transformers/CompaniesTransformer.php @@ -38,7 +38,7 @@ class CompaniesTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Company::class) ? true : false, - 'delete' => Gate::allows('delete', Company::class) ? true : false, + 'delete' => (Gate::allows('delete', Category::class) && ($company->assets_count == 0) && ($company->accessories_count == 0) && ($company->consumables_count == 0) && ($company->components_count == 0) && ($company->users_count == 0)) ? true : false, ]; $array += $permissions_array; diff --git a/app/Http/Transformers/DepartmentsTranformer.php b/app/Http/Transformers/DepartmentsTranformer.php index dd51e73aa8..f81954f947 100644 --- a/app/Http/Transformers/DepartmentsTranformer.php +++ b/app/Http/Transformers/DepartmentsTranformer.php @@ -47,7 +47,7 @@ class DepartmentsTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Department::class) ? true : false, - 'delete' => Gate::allows('delete', Department::class) ? true : false, + 'delete' => (Gate::allows('delete', Department::class) && ($department->users_count==0) && ($department->deleted_at=='')) ? true : false, ]; $array += $permissions_array; diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index 96fd25fee6..f8aa322c30 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -57,7 +57,7 @@ class LocationsTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Location::class) ? true : false, - 'delete' => Gate::allows('delete', Location::class) ? true : false, + 'delete' => (Gate::allows('delete', Department::class) && ($location->assigned_assets_count==0) && ($location->assets_count==0) && ($location->users_count==0) && ($location->deleted_at=='')) ? true : false, ]; $array += $permissions_array; diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.php index 7ef0ea54a6..6972d0bbc4 100644 --- a/app/Http/Transformers/ManufacturersTransformer.php +++ b/app/Http/Transformers/ManufacturersTransformer.php @@ -40,7 +40,7 @@ class ManufacturersTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Manufacturer::class) ? true : false, - 'delete' => Gate::allows('delete', Manufacturer::class) ? true : false, + 'delete' => (Gate::allows('delete', Manufacturer::class) && ($manufacturer->assets_count == 0) && ($manufacturer->licenses_count==0) && ($manufacturer->consumables_count==0) && ($manufacturer->accessories_count==0) && ($manufacturer->deleted_at=='')) ? true : false, ]; $array += $permissions_array; diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 36603b4bad..4c126bb387 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -218,7 +218,8 @@ class Actionlog extends SnipeModel $query->where('companies.name', 'LIKE', '%'.$search.'%'); }); })->orWhere('action_type', 'LIKE', '%'.$search.'%') - ->orWhere('note', 'LIKE', '%'.$search.'%'); + ->orWhere('note', 'LIKE', '%'.$search.'%') + ->orWhere('log_meta', 'LIKE', '%'.$search.'%'); } }); diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 3066057d1c..7cac06ed29 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -18,18 +18,36 @@ class AssetObserver public function updating(Asset $asset) { - - if ((isset($asset->getOriginal()['assigned_to'])) && ($asset->getAttributes()['assigned_to'] == $asset->getOriginal()['assigned_to']) + // If the asset isn't being checked out or audited, log the update. + // (Those other actions already create log entries.) + if (($asset->getAttributes()['assigned_to'] == $asset->getOriginal()['assigned_to']) && ($asset->getAttributes()['next_audit_date'] == $asset->getOriginal()['next_audit_date']) - && ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout']) - && ($asset->getAttributes()['status_id'] == $asset->getOriginal()['status_id'])) + && ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout'])) { + $changed = []; + + foreach ($asset->getOriginal() as $key => $value) { + if ($asset->getOriginal()[$key] != $asset->getAttributes()[$key]) { + $changed[$key]['old'] = $asset->getOriginal()[$key]; + $changed[$key]['new'] = $asset->getAttributes()[$key]; + } + } + + $logAction = new Actionlog(); $logAction->item_type = Asset::class; $logAction->item_id = $asset->id; $logAction->created_at = date("Y-m-d H:i:s"); $logAction->user_id = Auth::id(); + $logAction->log_meta = json_encode($changed); $logAction->logaction('update'); + + } else { + + \Log::debug('Something else happened'); + \Log::debug($asset->getOriginal()['assigned_to'].' == '.$asset->getAttributes()['assigned_to']); + \Log::debug($asset->getOriginal()['next_audit_date'].' == '.$asset->getAttributes()['next_audit_date']); + \Log::debug($asset->getOriginal()['last_checkout'].' == '.$asset->getAttributes()['last_checkout']); } } diff --git a/app/Presenters/CompanyPresenter.php b/app/Presenters/CompanyPresenter.php index 233245ff7d..1d0ab86b4a 100644 --- a/app/Presenters/CompanyPresenter.php +++ b/app/Presenters/CompanyPresenter.php @@ -41,51 +41,51 @@ class CompanyPresenter extends Presenter ],[ "field" => "users_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "title" => '', "visible" => true, ],[ "field" => "assets_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "title" => '', "visible" => true, ],[ "field" => "licenses_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => true, "title" => ' ', ],[ "field" => "accessories_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => true, "title" => ' ', ],[ "field" => "consumables_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => true, "title" => ' ', ],[ "field" => "components_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => true, "title" => ' ', ],[ "field" => "updated_at", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => false, "title" => trans('general.updated_at'), ],[ "field" => "created_at", "searchable" => false, - "sortable" => false, + "sortable" => true, "visible" => false, "title" => trans('general.created_at'), ],[ diff --git a/database/migrations/2017_12_12_033618_add_actionlog_meta.php b/database/migrations/2017_12_12_033618_add_actionlog_meta.php new file mode 100644 index 0000000000..a9a662fa1a --- /dev/null +++ b/database/migrations/2017_12_12_033618_add_actionlog_meta.php @@ -0,0 +1,32 @@ +text('log_meta')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('action_logs', function (Blueprint $table) { + $table->dropColumn('log_meta'); + }); + } +} diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 6ee49939d6..638e94d7f3 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -143,29 +143,32 @@ {{ trans('admin/hardware/form.manufacturer') }} - @can('view', \App\Models\Manufacturer::class) - - {{ $asset->model->manufacturer->name }} - - @else - {{ $asset->model->manufacturer->name }} - @endcan + @endif @@ -426,7 +429,7 @@ {!! $asset->assignedTo->present()->glyph() . ' ' .$asset->assignedTo->present()->nameUrl() !!}

-