Skip to content

Added prevents of deletion of singular parent assets #16380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public function index(Request $request, $action = null, $upcoming_status = null)
'model.category',
'model.manufacturer',
'model.fieldset',
'supplier'
'supplier',
'assignedAssets',
); // it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.


Expand Down
6 changes: 3 additions & 3 deletions app/Http/Transformers/AssetsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\Setting;
use Barryvdh\Debugbar\Controllers\AssetController;
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
use Carbon\Carbon;
Expand All @@ -28,7 +29,6 @@ public function transformAsset(Asset $asset)
{
// This uses the getSettings() method so we're pulling from the cache versus querying the settings on single asset
$setting = Setting::getSettings();

$array = [
'id' => (int) $asset->id,
'name' => e($asset->name),
Expand All @@ -40,7 +40,7 @@ public function transformAsset(Asset $asset)
] : null,
'byod' => ($asset->byod ? true : false),
'requestable' => ($asset->requestable ? true : false),

'child_asset_count' => $asset->assignedAssets->count(),
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date).' months' : null,
'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null,
Expand Down Expand Up @@ -155,7 +155,7 @@ public function transformAsset(Asset $asset)
'clone' => Gate::allows('create', Asset::class) ? true : false,
'restore' => ($asset->deleted_at!='' && Gate::allows('create', Asset::class)) ? true : false,
'update' => ($asset->deleted_at=='' && Gate::allows('update', Asset::class)) ? true : false,
'delete' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) ? true : false,
'delete' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) && ($asset->assignedAssets->count() === 0) ? true : false,
];


Expand Down
1 change: 1 addition & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@
'no_autoassign_licenses_help' => 'Do not include user for bulk-assigning through the license UI or cli tools.',
'modal_confirm_generic' => 'Are you sure?',
'cannot_be_deleted' => 'This item cannot be deleted',
'cannot_delete_parent_asset' => 'Cannot delete asset until attached assets are checked in.',
'cannot_be_edited' => 'This item cannot be edited.',
'undeployable_tooltip' => 'This item cannot be checked out. Check the quantity remaining.',
'serial_number' => 'Serial Number',
Expand Down
8 changes: 5 additions & 3 deletions resources/views/partials/bootstrap-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ function hardwareAuditFormatter(value, row) {
return '<a href="{{ config('app.url') }}/hardware/audit/' + row.id + '/" class="btn btn-sm bg-yellow" data-tooltip="true" title="Audit this item">{{ trans('general.audit') }}</a>';
}


// Make the edit/delete buttons
function genericActionsFormatter(owner_name, element_name) {
if (!element_name) {
Expand Down Expand Up @@ -351,9 +350,12 @@ function genericActionsFormatter(owner_name, element_name) {
} else {
// Do not show the delete button on things that are already deleted
if ((row.available_actions) && (row.available_actions.restore != true)) {
actions += '<span data-tooltip="true" title="{{ trans('general.cannot_be_deleted') }}"><a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><x-icon type="delete" /><span class="sr-only">{{ trans('general.cannot_be_deleted') }}</span></a></span>&nbsp;';
var message = "{{trans('general.cannot_be_deleted')}}";
if(row.child_asset_count > 0){
message = "{{trans('general.cannot_delete_parent_asset')}}";
}
actions += '<span data-tooltip="true" title="'+message+'"><a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><x-icon type="delete" /><span class="sr-only">{{ trans('general.cannot_be_deleted') }}</span></a></span>&nbsp;';
}

}


Expand Down
Loading