Skip to content

Commit f2303ae

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 69a57b7 + 4d44fd4 commit f2303ae

File tree

47 files changed

+231
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+231
-117
lines changed

app/Http/Controllers/Account/AcceptanceController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use App\Models\Contracts\Acceptable;
1414
use App\Models\Setting;
1515
use App\Models\User;
16-
use App\Notifications\AcceptanceAssetAcceptedNotification;
17-
use App\Notifications\AcceptanceAssetAcceptedToUserNotification;
18-
use App\Notifications\AcceptanceAssetDeclinedNotification;
16+
use App\Notifications\AcceptanceItemAcceptedNotification;
17+
use App\Notifications\AcceptanceItemAcceptedToUserNotification;
18+
use App\Notifications\AcceptanceItemDeclinedNotification;
1919
use Exception;
2020
use Illuminate\Http\Request;
2121
use Illuminate\Support\Facades\Mail;
@@ -145,7 +145,7 @@ public function store(Request $request, $id) : RedirectResponse
145145
// Get the data array ready for the notifications and PDF generation
146146
$data = [
147147
'item_tag' => $item->asset_tag,
148-
'item_name' => $item->name, // this handles licenses seats, which don't have a 'name' field
148+
'item_name' => $item->display_name, // this handles licenses seats, which don't have a 'name' field
149149
'item_model' => $item->model?->name,
150150
'item_serial' => $item->serial,
151151
'item_status' => $item->assetstatus?->name,
@@ -183,13 +183,13 @@ public function store(Request $request, $id) : RedirectResponse
183183
// Add the attachment for the signing user into the $data array
184184
$data['file'] = $pdf_filename;
185185
try {
186-
$assigned_user->notify((new AcceptanceAssetAcceptedToUserNotification($data))->locale($assigned_user->locale));
186+
$assigned_user->notify((new AcceptanceItemAcceptedToUserNotification($data))->locale($assigned_user->locale));
187187
} catch (\Exception $e) {
188188
Log::warning($e);
189189
}
190190
}
191191
try {
192-
$acceptance->notify((new AcceptanceAssetAcceptedNotification($data))->locale(Setting::getSettings()->locale));
192+
$acceptance->notify((new AcceptanceItemAcceptedNotification($data))->locale(Setting::getSettings()->locale));
193193
} catch (\Exception $e) {
194194
Log::warning($e);
195195
}
@@ -204,7 +204,7 @@ public function store(Request $request, $id) : RedirectResponse
204204
$acceptance->decline($sig_filename, $request->input('note'));
205205
}
206206

207-
$acceptance->notify(new AcceptanceAssetDeclinedNotification($data));
207+
$acceptance->notify(new AcceptanceItemDeclinedNotification($data));
208208
Log::debug('New event acceptance.');
209209
event(new CheckoutDeclined($acceptance));
210210
$return_msg = trans('admin/users/message.declined');

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

app/Http/Controllers/ReportsController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,9 @@ public function getAssetAcceptanceReport($deleted = false) : View
11481148
$query->withTrashed();
11491149
}
11501150

1151-
$itemsForReport = $query->get()->map(fn ($unaccepted) => Checkoutable::fromAcceptance($unaccepted));
1151+
$itemsForReport = $query->get()
1152+
->filter(fn ($unaccepted) => $unaccepted->checkoutable)
1153+
->map(fn ($unaccepted) => Checkoutable::fromAcceptance($unaccepted));
11521154

11531155
return view('reports/unaccepted_assets', compact('itemsForReport','showDeleted' ));
11541156
}
@@ -1288,7 +1290,9 @@ public function postAssetAcceptanceReport($deleted = false) : Response
12881290
$acceptances->withTrashed();
12891291
}
12901292

1291-
$itemsForReport = $acceptances->get()->map(fn ($unaccepted) => Checkoutable::fromAcceptance($unaccepted));
1293+
$itemsForReport = $acceptances->get()
1294+
->filter(fn ($unaccepted) => $unaccepted->checkoutable)
1295+
->map(fn ($unaccepted) => Checkoutable::fromAcceptance($unaccepted));
12921296

12931297
$rows = [];
12941298

app/Mail/BaseMailable.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace App\Mail;
3+
4+
use Illuminate\Mail\Mailable;
5+
use Illuminate\Mail\Mailables\Headers;
6+
7+
class BaseMailable extends Mailable
8+
{
9+
public function headers(): Headers
10+
{
11+
return new Headers(
12+
text: [
13+
'X-Auto-Response-Suppress' => 'OOF, DR, RN, NRN, AutoReply',
14+
'X-System-Sender' => 'Snipe-IT',
15+
]
16+
);
17+
}
18+
}

app/Mail/CheckinAccessoryMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
use App\Models\Setting;
77
use App\Models\User;
88
use Illuminate\Bus\Queueable;
9-
use Illuminate\Contracts\Queue\ShouldQueue;
10-
use Illuminate\Mail\Mailable;
119
use Illuminate\Mail\Mailables\Address;
1210
use Illuminate\Mail\Mailables\Content;
1311
use Illuminate\Mail\Mailables\Envelope;
1412
use Illuminate\Queue\SerializesModels;
1513

16-
class CheckinAccessoryMail extends Mailable
14+
class CheckinAccessoryMail extends BaseMailable
1715
{
1816
use Queueable, SerializesModels;
1917

app/Mail/CheckinAssetMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
use App\Models\Setting;
88
use App\Models\User;
99
use Illuminate\Bus\Queueable;
10-
use Illuminate\Contracts\Queue\ShouldQueue;
11-
use Illuminate\Mail\Mailable;
1210
use Illuminate\Mail\Mailables\Address;
1311
use Illuminate\Mail\Mailables\Content;
1412
use Illuminate\Mail\Mailables\Envelope;
1513
use Illuminate\Notifications\Messages\MailMessage;
1614
use Illuminate\Queue\SerializesModels;
1715

18-
class CheckinAssetMail extends Mailable
16+
class CheckinAssetMail extends BaseMailable
1917
{
2018
use Queueable, SerializesModels;
2119

app/Mail/CheckinComponentMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
use App\Models\Setting;
88
use App\Models\User;
99
use Illuminate\Bus\Queueable;
10-
use Illuminate\Contracts\Queue\ShouldQueue;
11-
use Illuminate\Mail\Mailable;
1210
use Illuminate\Mail\Mailables\Address;
1311
use Illuminate\Mail\Mailables\Content;
1412
use Illuminate\Mail\Mailables\Envelope;
1513
use Illuminate\Queue\SerializesModels;
1614

17-
class CheckinComponentMail extends Mailable
15+
class CheckinComponentMail extends BaseMailable
1816
{
1917
use Queueable, SerializesModels;
2018

app/Mail/CheckinLicenseMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
use App\Models\Setting;
77
use App\Models\User;
88
use Illuminate\Bus\Queueable;
9-
use Illuminate\Contracts\Queue\ShouldQueue;
10-
use Illuminate\Mail\Mailable;
119
use Illuminate\Mail\Mailables\Address;
1210
use Illuminate\Mail\Mailables\Content;
1311
use Illuminate\Mail\Mailables\Envelope;
1412
use Illuminate\Queue\SerializesModels;
1513

16-
class CheckinLicenseMail extends Mailable
14+
class CheckinLicenseMail extends BaseMailable
1715
{
1816
use Queueable, SerializesModels;
1917

app/Mail/CheckoutAcceptanceResponseMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
use App\Models\CheckoutAcceptance;
66
use App\Models\User;
77
use Illuminate\Bus\Queueable;
8-
use Illuminate\Contracts\Queue\ShouldQueue;
9-
use Illuminate\Mail\Mailable;
108
use Illuminate\Mail\Mailables\Content;
119
use Illuminate\Mail\Mailables\Envelope;
1210
use Illuminate\Queue\SerializesModels;
1311

14-
class CheckoutAcceptanceResponseMail extends Mailable
12+
class CheckoutAcceptanceResponseMail extends BaseMailable
1513
{
1614
use Queueable, SerializesModels;
1715

app/Mail/CheckoutAccessoryMail.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
use App\Models\Setting;
99
use App\Models\User;
1010
use Illuminate\Bus\Queueable;
11-
use Illuminate\Contracts\Queue\ShouldQueue;
12-
use Illuminate\Mail\Mailable;
1311
use Illuminate\Mail\Mailables\Address;
1412
use Illuminate\Mail\Mailables\Content;
1513
use Illuminate\Mail\Mailables\Envelope;
1614
use Illuminate\Queue\SerializesModels;
1715
use Illuminate\Support\Facades\Log;
1816

19-
class CheckoutAccessoryMail extends Mailable
17+
class CheckoutAccessoryMail extends BaseMailable
2018
{
2119
use Queueable, SerializesModels;
2220

0 commit comments

Comments
 (0)