Skip to content

A free open source IT asset/license management system

Add optional hide for history

snipe5806fced78db
diff --git a/app/Policies/AssetModelPolicy.php b/app/Policies/AssetModelPolicy.php
index fb5584b09a..39b0dfb55e 100644
--- a/app/Policies/AssetModelPolicy.php
+++ b/app/Policies/AssetModelPolicy.php
@@ -13,6 +13,10 @@ class AssetModelPolicy extends SnipePermissionsPolicy
public function files(User $user, $item = null)
{
+ // Set this to true so that users who can see the asset can also see the associated model files
+ if ($user->hasAccess('assets.files')) {
+ return true;
+ }
return $user->hasAccess($this->columnName().'.files');
}
}
diff --git a/app/Presenters/HistoryPresenter.php b/app/Presenters/HistoryPresenter.php
index 0a09cfb3fe..a486584b36 100644
--- a/app/Presenters/HistoryPresenter.php
+++ b/app/Presenters/HistoryPresenter.php
@@ -2,9 +2,6 @@
namespace App\Presenters;
-/**
- * Class AccessoryPresenter
- */
class HistoryPresenter extends Presenter
{
/**
@@ -12,168 +9,229 @@ class HistoryPresenter extends Presenter
*
* @return string
*/
- public static function dataTableLayout($serial = false)
+ public static function dataTableLayout($hide_fields = array())
{
- $extra = [];
- $layout_start = [
- [
- 'id' => 'id',
- 'searchable' => false,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.id'),
- 'visible' => false,
- 'class' => 'hidden-xs',
- ],
- [
- 'field' => 'icon',
- 'searchable' => false,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('admin/hardware/table.icon'),
- 'visible' => true,
- 'class' => 'hidden-xs',
- 'formatter' => 'iconFormatter',
- ],
- [
- 'field' => 'created_at',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.created_at'),
- 'visible' => true,
- 'formatter' => 'dateDisplayFormatter',
- ],
- [
- 'field' => 'created_by',
- 'searchable' => true,
- 'sortable' => true,
- 'title' => trans('general.created_by'),
- 'visible' => true,
- 'formatter' => 'usersLinkObjFormatter',
- ],
- [
- 'field' => 'action_date',
- 'searchable' => false,
- 'sortable' => true,
- 'title' => trans('general.action_date'),
- 'visible' => false,
- 'formatter' => 'dateDisplayFormatter',
- ],
- [
- 'field' => 'action_type',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.action'),
- 'visible' => true,
- ],
- [
- 'field' => 'item',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.item'),
- 'visible' => true,
- 'formatter' => 'polymorphicItemFormatter',
- ],
- ];
-
- if ($serial) {
- $extra = [
+ $layout = [];
+
+ if (!in_array('id', $hide_fields)) {
+ array_push($layout,
+ [
+ 'id' => 'id',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.id'),
+ 'visible' => false,
+ 'class' => 'hidden-xs',
+ ]);
+ }
+
+ if (!in_array('icon', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'icon',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('admin/hardware/table.icon'),
+ 'visible' => true,
+ 'class' => 'hidden-xs',
+ 'formatter' => 'iconFormatter',
+ ]);
+ }
+
+ if (!in_array('created_at', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'created_at',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.created_at'),
+ 'visible' => true,
+ 'formatter' => 'dateDisplayFormatter',
+ ]);
+ }
+ if (!in_array('created_by', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'created_by',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'title' => trans('general.created_by'),
+ 'visible' => true,
+ 'formatter' => 'usersLinkObjFormatter',
+ ]);
+ }
+
+
+ if (!in_array('action_type', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'action_type',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.action'),
+ 'visible' => true,
+ ]);
+ }
+
+ if (!in_array('action_date', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'action_date',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'title' => trans('general.action_date'),
+ 'visible' => false,
+ 'formatter' => 'dateDisplayFormatter',
+ ]);
+ }
+
+ if (!in_array('item', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'item',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.item'),
+ 'visible' => true,
+ 'formatter' => 'polymorphicItemFormatter',
+ ]);
+ }
+
+
+ if (!in_array('serial', $hide_fields)) {
+ array_push($layout,
[
'field' => 'item.serial',
'title' => trans('admin/hardware/table.serial'),
'visible' => false,
- ],
- ];
- }
-
- $layout_end = [
- [
- 'field' => 'target',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.target'),
- 'visible' => true,
- 'formatter' => 'polymorphicItemFormatter',
- ],
- [
- 'field' => 'file',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.file_name'),
- 'visible' => true,
- 'formatter' => 'fileNameFormatter',
- ],
- [
- 'field' => 'file_download',
- 'searchable' => false,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.download'),
- 'visible' => true,
- 'formatter' => 'fileDownloadButtonsFormatter',
- ],
- [
- 'field' => 'quantity',
- 'searchable' => false,
- 'sortable' => true,
- 'visible' => true,
- 'title' => trans('general.quantity'),
- ],
- [
- 'field' => 'note',
- 'searchable' => true,
- 'sortable' => true,
- 'visible' => true,
- 'title' => trans('general.notes'),
- 'formatter' => 'notesFormatter',
- ],
- [
- 'field' => 'signature_file',
- 'searchable' => true,
- 'sortable' => true,
- 'switchable' => true,
- 'title' => trans('general.signature'),
- 'visible' => false,
- 'formatter' => 'imageFormatter',
- ],
- [
- 'field' => 'log_meta',
- 'searchable' => false,
- 'sortable' => false,
- 'visible' => true,
- 'title' => trans('admin/hardware/table.changed'),
- 'formatter' => 'changeLogFormatter',
- ],
- [
- 'field' => 'remote_ip',
- 'searchable' => true,
- 'sortable' => true,
- 'visible' => false,
- 'title' => trans('admin/settings/general.login_ip'),
- ],
- [
- 'field' => 'user_agent',
- 'searchable' => true,
- 'sortable' => true,
- 'visible' => false,
- 'title' => trans('admin/settings/general.login_user_agent'),
- ],
- [
- 'field' => 'action_source',
- 'searchable' => true,
- 'sortable' => true,
- 'visible' => false,
- 'title' => trans('general.action_source'),
- ],
- ];
-
- $merged = array_merge($layout_start, $extra, $layout_end);
-
- return json_encode($merged);
+ ]);
+ }
+
+ if (!in_array('target', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'target',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.target'),
+ 'visible' => true,
+ 'formatter' => 'polymorphicItemFormatter',
+ ]);
+ }
+
+ if (!in_array('file', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'file',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.file_name'),
+ 'visible' => true,
+ 'formatter' => 'fileNameFormatter',
+ ]);
+ }
+
+ if (!in_array('file_download', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'file_download',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.download'),
+ 'visible' => true,
+ 'formatter' => 'fileDownloadButtonsFormatter',
+ ]);
+ }
+
+ if (!in_array('quantity', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'quantity',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'visible' => true,
+ 'title' => trans('general.quantity'),
+ ]);
+ }
+
+ if (!in_array('note', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'note',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'visible' => true,
+ 'title' => trans('general.notes'),
+ 'formatter' => 'notesFormatter',
+ ]);
+ }
+
+ if (!in_array('signature_file', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'signature_file',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.signature'),
+ 'visible' => false,
+ 'formatter' => 'imageFormatter',
+ ]);
+ }
+
+ if (!in_array('log_meta', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'log_meta',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'visible' => true,
+ 'title' => trans('admin/hardware/table.changed'),
+ 'formatter' => 'changeLogFormatter',
+ ]);
+ }
+
+ if (!in_array('remote_ip', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'remote_ip',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'visible' => false,
+ 'title' => trans('admin/settings/general.login_ip'),
+ ]);
+ }
+
+ if (!in_array('user_agent', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'user_agent',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'visible' => false,
+ 'title' => trans('admin/settings/general.login_user_agent'),
+ ]);
+ }
+
+ if (!in_array('action_source', $hide_fields)) {
+ array_push($layout,
+ [
+ 'field' => 'action_source',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'visible' => false,
+ 'title' => trans('general.action_source'),
+ ]);
+ }
+
+ return json_encode($layout);
}
}
diff --git a/resources/views/blade/table/history.blade.php b/resources/views/blade/table/history.blade.php
index 6969835c51..1d9c096f28 100644
--- a/resources/views/blade/table/history.blade.php
+++ b/resources/views/blade/table/history.blade.php
@@ -1,12 +1,11 @@
@props([
'route',
'name' => 'default',
- 'presenter' => \App\Presenters\HistoryPresenter::dataTableLayout(),
'table_header' => trans('general.history'),
'model' => null,
+ 'hide_fields' => [],
])
-
<!-- start history tab pane -->
@can('history', $model)
<x-slot:table_header>
@@ -14,9 +13,11 @@
</x-slot:table_header>
<x-table
- :$presenter
+ :presenter="\App\Presenters\HistoryPresenter::dataTableLayout($hide_fields)"
show_advanced_search="false"
api_url="{{ $route }}"
+ fixed_number="false"
+ fixed_right_number="false"
export_filename="export-history-{{ date('Y-m-d') }}"
/>
@endcan
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php
index 0c88e7a0ae..b6073e6274 100755
--- a/resources/views/hardware/view.blade.php
+++ b/resources/views/hardware/view.blade.php
@@ -361,13 +361,21 @@
<!-- start audits tab pane -->
<x-tabs.pane name="audits">
- <x-table.history :table_header="trans('general.audits')" :model="$asset" :route="route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset', 'action_type' => 'audit'])"/>
+ <x-table.history
+ :table_header="trans('general.audits')"
+ :model="$asset"
+ :route="route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset', 'action_type' => 'audit'])"
+ :hide_fields="['id','action_type', 'item', 'changed', 'target','quantity','changed','serial','signature_file','log_meta']"/>
</x-tabs.pane>
<!-- end audits tab pane -->
<!-- start notes tab pane -->
<x-tabs.pane name="notes">
- <x-table.history :table_header="trans('general.notes')" :model="$asset" :route="route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset', 'action_type' => 'note added'])"/>
+ <x-table.history
+ :table_header="trans('general.notes')"
+ :model="$asset" :route="route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset', 'action_type' => 'note added'])"
+ :hide_fields="['id','action_type', 'item', 'changed', 'target','file','file_download','quantity','changed','serial','signature_file','log_meta']"
+ />
</x-tabs.pane>
<!-- end audits tab pane -->
@@ -382,7 +390,10 @@
<!-- start history tab pane -->
<x-tabs.pane name="history">
- <x-table.history :model="$asset" :route="route('api.assets.history', $asset)"/>
+ <x-table.history
+ :model="$asset"
+ :route="route('api.assets.history', $asset)"
+ />
</x-tabs.pane>
<!-- end history tab pane -->
diff --git a/resources/views/reports/activity.blade.php b/resources/views/reports/activity.blade.php
index ddbb2717d0..64af6734e7 100644
--- a/resources/views/reports/activity.blade.php
+++ b/resources/views/reports/activity.blade.php
@@ -22,7 +22,7 @@
<x-box>
<table
- data-columns="{{ \App\Presenters\HistoryPresenter::dataTableLayout($serial = true) }}"
+ data-columns="{{ \App\Presenters\HistoryPresenter::dataTableLayout() }}"
data-cookie-id-table="activityReport"
data-id-table="activityReport"
data-side-pagination="server"