Skip to content

A free open source IT asset/license management system

Don't let a license to be checked out to a non-existent target

Ivan Nieto Vivancoe0050bc8447d
diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php
index 0dd1c1fbd6..b587dae5aa 100644
--- a/app/Http/Controllers/Api/LicenseSeatsController.php
+++ b/app/Http/Controllers/Api/LicenseSeatsController.php
@@ -116,16 +116,20 @@ class LicenseSeatsController extends Controller
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
}
+ // the logging functions expect only one "target". if both asset and user are present in the request,
+ // we simply let assets take precedence over users...
+ if ($licenseSeat->isDirty('assigned_to')) {
+ $target = $is_checkin ? $oldUser : User::find($licenseSeat->assigned_to);
+ }
+ if ($licenseSeat->isDirty('asset_id')) {
+ $target = $is_checkin ? $oldAsset : Asset::find($licenseSeat->asset_id);
+ }
+
+ if(is_null($target)){
+ return response()->json(Helper::formatStandardApiResponse('error', null, 'Target not found'));
+ }
+
if ($licenseSeat->save()) {
- // the logging functions expect only one "target". if both asset and user are present in the request,
- // we simply let assets take precedence over users...
- $changes = $licenseSeat->getChanges();
- if (array_key_exists('assigned_to', $changes)) {
- $target = $is_checkin ? $oldUser : User::find($changes['assigned_to']);
- }
- if (array_key_exists('asset_id', $changes)) {
- $target = $is_checkin ? $oldAsset : Asset::find($changes['asset_id']);
- }
if ($is_checkin) {
$licenseSeat->logCheckin($target, $request->input('note'));
diff --git a/index.html b/index.html
index dbd1babcb8..33cd6c415a 100644
--- a/index.html
+++ b/index.html
@@ -1,50 +1 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>
- Snipe-IT Setup
- </title>
-
- <style>
- td, th {
- font-size: 14px;
- }
-
- .preflight-success {
- color: green;
- }
-
- .preflight-error {
- color: red;
- }
-
- .preflight-warning {
- color: orange;
- }
-
- .page-header {
- font-size: 280%;
- }
-
- h3 {
- font-size: 250%;
- }
-
- .alert {
- font-size: 16px;
- }
-
- </style>
-
- </head>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-lg-11 col-lg-offset-1">
- <h1>D'oh. If you're seeing this, your DocumentRoot is set incorrectly. It should be set to the <code>public</code> directory.
- </div>
- </div>
- </div>
-
- </body>
-</html>
+{"status":"success","messages":"License updated successfully.","payload":{"id":12,"license_id":2,"assigned_to":null,"notes":null,"user_id":1,"created_at":"2022-05-25T23:04:30.000000Z","updated_at":"2022-05-26T22:07:16.000000Z","deleted_at":null,"asset_id":"1161"}}
\ No newline at end of file