Skip to content

Commit cb7654a

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 00c3943 + 113b762 commit cb7654a

File tree

24 files changed

+205
-81
lines changed

24 files changed

+205
-81
lines changed

.github/workflows/tests-mysql.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,16 @@ jobs:
7676
DB_DATABASE: snipeit
7777
DB_PORT: ${{ job.services.mysql.ports[3306] }}
7878
DB_USERNAME: root
79+
LOG_CHANNEL: single
80+
LOG_LEVEL: debug
7981
run: php artisan test
82+
83+
- name: Upload Laravel logs as artifacts
84+
if: always()
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: laravel-logs-php-${{ matrix.php-version }}-run-${{ github.run_attempt }}
88+
path: |
89+
storage/logs/*.log
90+
if-no-files-found: ignore
91+
retention-days: 7

.github/workflows/tests-postgres.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,16 @@ jobs:
7575
DB_PORT: ${{ job.services.postgresql.ports[5432] }}
7676
DB_USERNAME: snipeit
7777
DB_PASSWORD: password
78+
LOG_CHANNEL: single
79+
LOG_LEVEL: debug
7880
run: php artisan test
81+
82+
- name: Upload Laravel logs as artifacts
83+
if: always()
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: laravel-logs-php-${{ matrix.php-version }}-run-${{ github.run_attempt }}
87+
path: |
88+
storage/logs/*.log
89+
if-no-files-found: ignore
90+
retention-days: 7

.github/workflows/tests-sqlite.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ jobs:
6161
- name: Execute tests (Unit and Feature tests) via PHPUnit
6262
env:
6363
DB_CONNECTION: sqlite
64+
LOG_CHANNEL: single
65+
LOG_LEVEL: debug
6466
run: php artisan test
67+
68+
- name: Upload Laravel logs as artifacts
69+
if: always()
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: laravel-logs-php-${{ matrix.php-version }}-run-${{ github.run_attempt }}
73+
path: |
74+
storage/logs/*.log
75+
if-no-files-found: ignore
76+
retention-days: 7

app/Helpers/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,5 +1706,5 @@ class_basename(get_class($item)),
17061706
}
17071707
}
17081708
return $mismatched;
1709-
}
1709+
}
17101710
}

app/Http/Controllers/Api/ImportController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function store() : JsonResponse
6969
if (function_exists('iconv')) {
7070
$file_contents = $file->getContent(); //TODO - this *does* load the whole file in RAM, but we need that to be able to 'iconv' it?
7171
$encoding = $detector->getEncoding($file_contents);
72-
\Log::warning("Discovered encoding: $encoding in uploaded CSV");
72+
\Log::debug("Discovered encoding: $encoding in uploaded CSV");
7373
$reader = null;
7474
if (strcasecmp($encoding, 'UTF-8') != 0) {
7575
$transliterated = false;
@@ -103,7 +103,7 @@ public function store() : JsonResponse
103103
$reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak?
104104
105105
try {
106-
$import->header_row = $reader->fetchOne(0);
106+
$import->header_row = $reader->nth(0);
107107
} catch (JsonEncodingException $e) {
108108
return response()->json(
109109
Helper::formatStandardApiResponse(
@@ -136,7 +136,7 @@ public function store() : JsonResponse
136136

137137
try {
138138
// Grab the first row to display via ajax as the user picks fields
139-
$import->first_row = $reader->fetchOne(1);
139+
$import->first_row = $reader->nth(1);
140140
} catch (JsonEncodingException $e) {
141141
return response()->json(
142142
Helper::formatStandardApiResponse(

app/Http/Controllers/Api/LicenseSeatsController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
128128
// nothing to update
129129
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
130130
}
131-
131+
if( $touched && $licenseSeat->unreassignable_seat) {
132+
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.checkout.unavailable')));
133+
}
132134
// the logging functions expect only one "target". if both asset and user are present in the request,
133135
// we simply let assets take precedence over users...
134136
if ($licenseSeat->isDirty('assigned_to')) {
@@ -145,7 +147,11 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
145147
if ($licenseSeat->save()) {
146148

147149
if ($is_checkin) {
148-
$licenseSeat->logCheckin($target, $request->input('notes'));
150+
if(!$licenseSeat->license->reassignable){
151+
$licenseSeat->unreassignable_seat = true;
152+
$licenseSeat->save();
153+
}
154+
$licenseSeat->logCheckin($target, $licenseSeat->notes);
149155

150156
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
151157
}

app/Http/Controllers/Licenses/LicenseCheckinController.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ public function store(Request $request, $seatId = null, $backTo = null)
6464

6565
$this->authorize('checkout', $license);
6666

67-
if (! $license->reassignable) {
68-
// Not allowed to checkin
69-
Session::flash('error', trans('admin/licenses/message.checkin.not_reassignable') . '.');
7067

71-
return redirect()->back()->withInput();
72-
}
7368

7469
// Declare the rules for the form validation
7570
$rules = [
@@ -98,6 +93,9 @@ public function store(Request $request, $seatId = null, $backTo = null)
9893
$licenseSeat->assigned_to = null;
9994
$licenseSeat->asset_id = null;
10095
$licenseSeat->notes = $request->input('notes');
96+
if (! $licenseSeat->license->reassignable) {
97+
$licenseSeat->unreassignable_seat = true;
98+
}
10199

102100
session()->put(['redirect_option' => $request->get('redirect_option')]);
103101
if ($request->get('redirect_option') === 'target'){
@@ -106,7 +104,7 @@ public function store(Request $request, $seatId = null, $backTo = null)
106104

107105
// Was the asset updated?
108106
if ($licenseSeat->save()) {
109-
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes')));
107+
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $licenseSeat->notes));
110108

111109

112110
return Helper::getRedirectOption($request, $license->id, 'Licenses')
@@ -132,21 +130,17 @@ public function bulkCheckin(Request $request, $licenseId) {
132130
$license = License::findOrFail($licenseId);
133131
$this->authorize('checkin', $license);
134132

135-
if (! $license->reassignable) {
136-
// Not allowed to checkin
137-
Session::flash('error', 'License not reassignable.');
138-
139-
return redirect()->back()->withInput();
140-
}
141-
142133
$licenseSeatsByUser = LicenseSeat::where('license_id', '=', $licenseId)
143134
->whereNotNull('assigned_to')
144-
->with('user')
135+
->with('user', 'license')
145136
->get();
146137

138+
$license = $licenseSeatsByUser->first()?->license;
147139
foreach ($licenseSeatsByUser as $user_seat) {
148140
$user_seat->assigned_to = null;
149-
141+
if ($license && ! $license->reassignable) {
142+
$user_seat->unreassignable_seat = true;
143+
}
150144
if ($user_seat->save()) {
151145
Log::debug('Checking in '.$license->name.' from user '.$user_seat->username);
152146
$user_seat->logCheckin($user_seat->user, trans('admin/licenses/general.bulk.checkin_all.log_msg'));
@@ -159,9 +153,12 @@ public function bulkCheckin(Request $request, $licenseId) {
159153
->get();
160154

161155
$count = 0;
156+
$license = $licenseSeatsByAsset->first()?->license;
162157
foreach ($licenseSeatsByAsset as $asset_seat) {
163158
$asset_seat->asset_id = null;
164-
159+
if ($license && ! $license->reassignable) {
160+
$asset_seat->unreassignable_seat = true;
161+
}
165162
if ($asset_seat->save()) {
166163
Log::debug('Checking in '.$license->name.' from asset '.$asset_seat->asset_tag);
167164
$asset_seat->logCheckin($asset_seat->asset, trans('admin/licenses/general.bulk.checkin_all.log_msg'));

app/Http/Controllers/Licenses/LicensesController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,25 @@ public function show(License $license)
245245
$license = License::with('assignedusers')->find($license->id);
246246

247247
$users_count = User::where('autoassign_licenses', '1')->count();
248-
$total_seats_count = $license->totalSeatsByLicenseID();
248+
249+
$total_seats_count = (int) $license->totalSeatsByLicenseID();
249250
$available_seats_count = $license->availCount()->count();
250-
$checkedout_seats_count = ($total_seats_count - $available_seats_count);
251+
$unreassignable_seats_count = License::unReassignableCount($license);
252+
253+
if(!$license->reassignable){
254+
$checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );
255+
}
256+
else {
257+
$checkedout_seats_count = ($total_seats_count - $available_seats_count);
258+
}
251259

252260
$this->authorize('view', $license);
253261
return view('licenses.view', compact('license'))
254262
->with('users_count', $users_count)
255263
->with('total_seats_count', $total_seats_count)
256264
->with('available_seats_count', $available_seats_count)
257-
->with('checkedout_seats_count', $checkedout_seats_count);
265+
->with('checkedout_seats_count', $checkedout_seats_count)
266+
->with('unreassignable_seats_count', $unreassignable_seats_count);
258267

259268
}
260269

app/Http/Controllers/ReportsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ public function postCustom(CustomAssetReportRequest $request) : StreamedResponse
856856
}
857857

858858
if ($request->filled('assigned_to')) {
859-
$row[] = ($asset->checkedOutToUser() && $asset->assigned) ?? $asset->assigned->display_name;
859+
$row[] = ($asset->checkedOutToUser() && $asset->assigned) ? $asset->assigned->display_name : '';
860860
$row[] = ($asset->checkedOutToUser() && $asset->assigned) ? 'user' : $asset->assignedType();
861861
}
862862

app/Http/Transformers/LicenseSeatsTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\Models\LicenseSeat;
88
use Illuminate\Support\Facades\Gate;
99
use Illuminate\Database\Eloquent\Collection;
10-
1110
class LicenseSeatsTransformer
1211
{
1312
public function transformLicenseSeats(Collection $seats, $total)
@@ -52,6 +51,7 @@ public function transformLicenseSeat(LicenseSeat $seat)
5251
'reassignable' => (bool) $seat->license->reassignable,
5352
'notes' => e($seat->notes),
5453
'user_can_checkout' => (($seat->assigned_to == '') && ($seat->asset_id == '')),
54+
'disabled' => $seat->unreassignable_seat,
5555
];
5656

5757
$permissions_array['available_actions'] = [

0 commit comments

Comments
 (0)