Skip to content

A free open source IT asset/license management system

Added location clone

snipedac877f18432
diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php
index 9524abf6ee..25a500b567 100755
--- a/app/Http/Controllers/LocationsController.php
+++ b/app/Http/Controllers/LocationsController.php
@@ -227,6 +227,35 @@ class LocationsController extends Controller
}
+
+ /**
+ * Returns a view that presents a form to clone a location.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @param int $licenseId
+ * @since [v6.0.14]
+ * @return View
+ */
+ public function getClone($licenseId = null)
+ {
+ // Check if the asset exists
+ if (is_null($location_to_clone = Location::find($licenseId))) {
+ // Redirect to the asset management page
+ return redirect()->route('licenses.index')->with('error', trans('admin/locations/message.does_not_exist'));
+ }
+
+ $this->authorize('create', $location_to_clone);
+
+ $location = clone $location_to_clone;
+ $location->id = null;
+ $location->name = null;
+ $location->image = null;
+
+ return view('locations/edit')
+ ->with('item', $location);
+ }
+
+
public function print_all_assigned($id)
{
if ($location = Location::where('id', $id)->first()) {
diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php
index a55c41b350..22eade5d6e 100644
--- a/app/Http/Transformers/LocationsTransformer.php
+++ b/app/Http/Transformers/LocationsTransformer.php
@@ -4,7 +4,7 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Location;
-use Gate;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Storage;
@@ -63,6 +63,7 @@ class LocationsTransformer
$permissions_array['available_actions'] = [
'update' => Gate::allows('update', Location::class) ? true : false,
'delete' => $location->isDeletable(),
+ 'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')),
];
$array += $permissions_array;
diff --git a/routes/web.php b/routes/web.php
index 4c52918f8e..18b7f9a990 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -40,12 +40,9 @@ Route::group(['middleware' => 'auth'], function () {
'parameters' => ['category' => 'category_id'],
]);
- /*
- * Locations
- */
- Route::resource('locations', LocationsController::class, [
- 'parameters' => ['location' => 'location_id'],
- ]);
+ Route::get('locations/{locationId}/clone',
+ [LocationsController::class, 'getClone']
+ )->name('clone/license');
Route::get(
'locations/{locationId}/printassigned',
@@ -57,6 +54,17 @@ Route::group(['middleware' => 'auth'], function () {
[LocationsController::class, 'print_all_assigned']
)->name('locations.print_all_assigned');
+ /*
+ * Locations
+ */
+ Route::resource('locations', LocationsController::class, [
+ 'parameters' => ['location' => 'location_id'],
+ ]);
+
+
+
+
+
/*
* Manufacturers
*/