diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index e1c79dfbe4..b46c13e13e 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -235,7 +235,13 @@ class LocationsController extends Controller public function destroy($id) { $this->authorize('delete', Location::class); - $location = Location::findOrFail($id); + $location = Location::withCount('assignedAssets as assigned_assets_count') + ->withCount('assets as assets_count') + ->withCount('rtd_assets as rtd_assets_count') + ->withCount('children as children_count') + ->withCount('users as users_count') + ->findOrFail($id); + if (! $location->isDeletable()) { return response() ->json(Helper::formatStandardApiResponse('error', null, trans('admin/companies/message.assoc_users'))); diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 7a3691684f..897d127580 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -320,7 +320,12 @@ class LocationsController extends Controller $locations_raw_array = $request->input('ids'); if ((is_array($locations_raw_array)) && (count($locations_raw_array) > 0)) { - $locations = Location::whereIn('id', $locations_raw_array)->get(); + $locations = Location::whereIn('id', $locations_raw_array) + ->withCount('assignedAssets as assigned_assets_count') + ->withCount('assets as assets_count') + ->withCount('rtd_assets as rtd_assets_count') + ->withCount('children as children_count') + ->withCount('users as users_count')->get(); $success_count = 0; $error_count = 0; @@ -351,7 +356,7 @@ class LocationsController extends Controller if ($error_count > 0) { return redirect() ->route('locations.index') - ->with('warning', trans('general.bulk.partial_success', + ->with('warning', trans('general.bulk.delete.partial', ['success' => $success_count, 'error' => $error_count, 'object_type' => trans('general.locations')] )); } diff --git a/app/Models/Location.php b/app/Models/Location.php index 2965ff2fc0..9f4c551264 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -106,6 +106,7 @@ class Location extends SnipeModel */ public function isDeletable() { + return Gate::allows('delete', $this) && ($this->assets_count === 0) && ($this->assigned_assets_count === 0) diff --git a/package-lock.json b/package-lock.json index 3592a3f2fe..3a81578e6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3377,9 +3377,9 @@ "integrity": "sha1-EQPWvADPv6jPyaJZmrUYxVZD2j8=" }, "bootstrap-table": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.22.2.tgz", - "integrity": "sha512-ZjZGcEXm/N7N/wAykmANWKKV+U+7AxgoNuBwWLrKbvAGT8XXS2f0OCiFmuMwpkqg7pDbF+ff9bEf/lOAlxcF1w==" + "version": "1.22.3", + "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.22.3.tgz", + "integrity": "sha512-YWQTXzmZBX6P4y6YW2mHOxqIAYyLKld2WecHuKSyYamimUE4KZ9YUsmAroSoS2Us1bPYXFaM+JCeTt6X0iKW+g==" }, "brace-expansion": { "version": "1.1.11", diff --git a/package.json b/package.json index 7847bb1793..f02b78db0b 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "bootstrap-colorpicker": "^2.5.3", "bootstrap-datepicker": "^1.10.0", "bootstrap-less": "^3.3.8", - "bootstrap-table": "1.22.2", + "bootstrap-table": "1.22.3", "chart.js": "^2.9.4", "clipboard": "^2.0.11", "css-loader": "^5.0.0", diff --git a/public/js/dist/bootstrap-table.js b/public/js/dist/bootstrap-table.js index 5161d15d12..dd852390a4 100644 Binary files a/public/js/dist/bootstrap-table.js and b/public/js/dist/bootstrap-table.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index b6ad88cc6c..bb0fd7243b 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -18,7 +18,7 @@ "/css/dist/skins/skin-green.css": "/css/dist/skins/skin-green.css?id=b48f4d8af0e1ca5621c161e93951109f", "/css/dist/skins/skin-contrast.css": "/css/dist/skins/skin-contrast.css?id=f0fbbb0ac729ea092578fb05ca615460", "/css/dist/skins/skin-red.css": "/css/dist/skins/skin-red.css?id=b9a74ec0cd68f83e7480d5ae39919beb", - "/css/dist/all.css": "/css/dist/all.css?id=532efb2074799739e7924d4d15cbeb48", + "/css/dist/all.css": "/css/dist/all.css?id=3a58b0695460d60eaed66bc3b7f4e796", "/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/webfonts/fa-brands-400.ttf": "/css/webfonts/fa-brands-400.ttf?id=69e5d8e4e818f05fd882cceb758d1eba", @@ -29,9 +29,9 @@ "/css/webfonts/fa-solid-900.woff2": "/css/webfonts/fa-solid-900.woff2?id=a0feb384c3c6071947a49708f2b0bc85", "/css/webfonts/fa-v4compatibility.ttf": "/css/webfonts/fa-v4compatibility.ttf?id=e24ec0b8661f7fa333b29444df39e399", "/css/webfonts/fa-v4compatibility.woff2": "/css/webfonts/fa-v4compatibility.woff2?id=e11465c0eff0549edd4e8ea6bbcf242f", - "/css/dist/bootstrap-table.css": "/css/dist/bootstrap-table.css?id=afa255bf30b2a7c11a97e3165128d183", + "/css/dist/bootstrap-table.css": "/css/dist/bootstrap-table.css?id=99c395f0bab5966f32f63f4e55899e64", "/js/build/vendor.js": "/js/build/vendor.js?id=a2b971da417306a63385c8098acfe4af", - "/js/dist/bootstrap-table.js": "/js/dist/bootstrap-table.js?id=29340c70d13855fa0165cd4d799c6f5b", + "/js/dist/bootstrap-table.js": "/js/dist/bootstrap-table.js?id=d0eb38da8b772a21b827b7df208dc4fe", "/js/dist/all.js": "/js/dist/all.js?id=fca6ea9956fd827d9790c08e0e982b22", "/js/dist/all-defer.js": "/js/dist/all-defer.js?id=19ccc62a8f1ea103dede4808837384d4", "/css/dist/skins/skin-green.min.css": "/css/dist/skins/skin-green.min.css?id=b48f4d8af0e1ca5621c161e93951109f", diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 6698de246a..695fa86b06 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -32,7 +32,7 @@ Form::macro('countries', function ($name = 'country', $selected = null, $class = $idclause = (!is_null($id)) ? $id : ''; - $select = ''; $select .= ''; // Pull the autoglossonym array from the localizations translation file diff --git a/resources/views/partials/forms/edit/address.blade.php b/resources/views/partials/forms/edit/address.blade.php index c8bf734033..c68ecaa8c2 100644 --- a/resources/views/partials/forms/edit/address.blade.php +++ b/resources/views/partials/forms/edit/address.blade.php @@ -33,7 +33,7 @@
{{ Form::label('country', trans('general.country'), array('class' => 'col-md-3 control-label')) }} -
+
{!! Form::countries('country', old('country', $item->country), 'select2') !!} {!! $errors->first('country', '') !!}
diff --git a/resources/views/partials/forms/edit/user-select.blade.php b/resources/views/partials/forms/edit/user-select.blade.php index 6283f37467..d9cba4b75f 100644 --- a/resources/views/partials/forms/edit/user-select.blade.php +++ b/resources/views/partials/forms/edit/user-select.blade.php @@ -2,7 +2,7 @@ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
+