Skip to content

Commit cf47f8f

Browse files
authored
Merge pull request #18216 from Godmartinz/fix-license-patch-to-allow-update-of-other-fields
Fixed #18024 License Seat update/patch method
2 parents 5daba60 + 4b45ffd commit cf47f8f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

app/Http/Controllers/Api/LicenseSeatsController.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,22 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
122122

123123
// check if this update is a checkin operation
124124
// 1. are relevant fields touched at all?
125-
$touched = $licenseSeat->isDirty('assigned_to') || $licenseSeat->isDirty('asset_id');
126-
// 2. are they cleared? if yes then this is a checkin operation
127-
$is_checkin = ($touched && $licenseSeat->assigned_to === null && $licenseSeat->asset_id === null);
125+
$assignmentTouched = $licenseSeat->isDirty('assigned_to') || $licenseSeat->isDirty('asset_id');
126+
$anythingTouched = $licenseSeat->isDirty();
128127

129-
if (! $touched) {
130-
// nothing to update
131-
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
128+
if (! $anythingTouched) {
129+
return response()->json(
130+
Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success'))
131+
);
132132
}
133-
if( $touched && $licenseSeat->unreassignable_seat) {
133+
if( $assignmentTouched && $licenseSeat->unreassignable_seat) {
134134
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.checkout.unavailable')));
135135
}
136+
137+
// 2. are they cleared? if yes then this is a checkin operation
138+
$is_checkin = ($assignmentTouched && $licenseSeat->assigned_to === null && $licenseSeat->asset_id === null);
139+
$target = null;
140+
136141
// the logging functions expect only one "target". if both asset and user are present in the request,
137142
// we simply let assets take precedence over users...
138143
if ($licenseSeat->isDirty('assigned_to')) {
@@ -142,25 +147,23 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
142147
$target = $is_checkin ? $oldAsset : Asset::find($licenseSeat->asset_id);
143148
}
144149

145-
if (is_null($target)){
150+
if ($assignmentTouched && is_null($target)){
146151
return response()->json(Helper::formatStandardApiResponse('error', null, 'Target not found'));
147152
}
148153

149154
if ($licenseSeat->save()) {
150-
151-
if ($is_checkin) {
152-
if(!$licenseSeat->license->reassignable){
153-
$licenseSeat->unreassignable_seat = true;
154-
$licenseSeat->save();
155+
if($assignmentTouched) {
156+
if ($is_checkin) {
157+
if (!$licenseSeat->license->reassignable) {
158+
$licenseSeat->unreassignable_seat = true;
159+
$licenseSeat->save();
160+
}
161+
$licenseSeat->logCheckin($target, $licenseSeat->notes);
162+
} else {
163+
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
164+
$licenseSeat->logCheckout($request->input('notes'), $target);
155165
}
156-
$licenseSeat->logCheckin($target, $licenseSeat->notes);
157-
158-
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
159166
}
160-
161-
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
162-
$licenseSeat->logCheckout($request->input('notes'), $target);
163-
164167
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
165168
}
166169

0 commit comments

Comments
 (0)