Skip to content

Commit 280e778

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 6e471a2 + 60ba898 commit 280e778

File tree

10 files changed

+258
-100
lines changed

10 files changed

+258
-100
lines changed

.github/workflows/codacy-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
3838
- name: Run Codacy Analysis CLI
39-
uses: codacy/codacy-analysis-cli-action@v4.3.0
39+
uses: codacy/codacy-analysis-cli-action@v4.4.0
4040
with:
4141
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
4242
# You can also omit the token and run the tools that support default configurations

TESTING.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,21 @@ DB_PASSWORD={}
4545

4646
Now you are ready to run the entire test suite from your terminal:
4747

48-
`php artisan test`
48+
```shell
49+
php artisan test
50+
````
4951

5052
To run individual test files, you can pass the path to the test that you want to run:
5153

52-
`php artisan test tests/Unit/AccessoryTest.php`
54+
```shell
55+
php artisan test tests/Unit/AccessoryTest.php
56+
```
57+
58+
Some tests, like ones concerning LDAP, are marked with the `@group` annotation. Those groups can be run, or excluded, using the `--group` or `--exclude-group` flags:
59+
60+
```shell
61+
php artisan test --group=ldap
62+
63+
php artisan test --exclude-group=ldap
64+
```
65+
This can be helpful if a set of tests are failing because you don't have an extension, like LDAP, installed.

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public function store(ImageUploadRequest $request)
146146
$asset->next_audit_date = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
147147
}
148148

149-
if ($asset->assigned_to == '') {
149+
// Set location_id to rtd_location_id ONLY if the asset isn't being checked out
150+
if (!request('assigned_user') && !request('assigned_asset') && !request('assigned_location')) {
150151
$asset->location_id = $request->input('rtd_location_id', null);
151152
}
152153

app/Notifications/CheckinAccessoryNotification.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,8 @@ public function via()
6363
if ($this->target instanceof User && $this->target->email != '') {
6464
\Log::debug('The target is a user');
6565

66-
/**
67-
* Send an email if the asset requires acceptance,
68-
* so the user can accept or decline the asset
69-
*/
70-
if (($this->item->requireAcceptance()) || ($this->item->getEula()) || ($this->item->checkin_email())) {
71-
$notifyBy[] = 'mail';
72-
}
73-
74-
/**
75-
* Send an email if the asset requires acceptance,
76-
* so the user can accept or decline the asset
77-
*/
78-
if ($this->item->requireAcceptance()) {
79-
\Log::debug('This accessory requires acceptance');
80-
}
81-
82-
/**
83-
* Send an email if the item has a EULA, since the user should always receive it
84-
*/
85-
if ($this->item->getEula()) {
86-
\Log::debug('This accessory has a EULA');
87-
}
88-
89-
/**
90-
* Send an email if an email should be sent at checkin/checkout
91-
*/
9266
if ($this->item->checkin_email()) {
93-
\Log::debug('This accessory has a checkin_email()');
67+
$notifyBy[] = 'mail';
9468
}
9569
}
9670

composer.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/factories/AccessoryFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\Manufacturer;
99
use App\Models\Supplier;
1010
use App\Models\User;
11+
use Carbon\Carbon;
1112
use Illuminate\Database\Eloquent\Factories\Factory;
1213

1314
class AccessoryFactory extends Factory
@@ -140,4 +141,16 @@ public function requiringAcceptance()
140141
$accessory->category->update(['require_acceptance' => 1]);
141142
});
142143
}
144+
145+
public function checkedOutToUser(User $user = null)
146+
{
147+
return $this->afterCreating(function (Accessory $accessory) use ($user) {
148+
$accessory->users()->attach($accessory->id, [
149+
'accessory_id' => $accessory->id,
150+
'created_at' => Carbon::now(),
151+
'user_id' => 1,
152+
'assigned_to' => $user->id ?? User::factory()->create()->id,
153+
]);
154+
});
155+
}
143156
}

resources/views/layouts/default.blade.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,23 @@
140140
<div class="navbar-custom-menu">
141141
<ul class="nav navbar-nav">
142142
@can('index', \App\Models\Asset::class)
143-
<li aria-hidden="true"
144-
{!! (Request::is('hardware*') ? ' class="active"' : '') !!} tabindex="-1">
143+
<li aria-hidden="true"{!! (Request::is('hardware*') ? ' class="active"' : '') !!}>
145144
<a href="{{ url('hardware') }}" accesskey="1" tabindex="-1">
146-
<i class="fas fa-barcode fa-fw" aria-hidden="true"></i>
145+
<i class="fas fa-barcode fa-fw"></i>
147146
<span class="sr-only">{{ trans('general.assets') }}</span>
148147
</a>
149148
</li>
150149
@endcan
151150
@can('view', \App\Models\License::class)
152-
<li aria-hidden="true"
153-
{!! (Request::is('licenses*') ? ' class="active"' : '') !!} tabindex="-1">
151+
<li aria-hidden="true"{!! (Request::is('licenses*') ? ' class="active"' : '') !!}>
154152
<a href="{{ route('licenses.index') }}" accesskey="2" tabindex="-1">
155153
<i class="far fa-save fa-fw"></i>
156154
<span class="sr-only">{{ trans('general.licenses') }}</span>
157155
</a>
158156
</li>
159157
@endcan
160158
@can('index', \App\Models\Accessory::class)
161-
<li aria-hidden="true"
162-
{!! (Request::is('accessories*') ? ' class="active"' : '') !!} tabindex="-1">
159+
<li aria-hidden="true"{!! (Request::is('accessories*') ? ' class="active"' : '') !!}>
163160
<a href="{{ route('accessories.index') }}" accesskey="3" tabindex="-1">
164161
<i class="far fa-keyboard fa-fw"></i>
165162
<span class="sr-only">{{ trans('general.accessories') }}</span>
@@ -233,7 +230,8 @@
233230
<li {!! (Request::is('accessories/create') ? 'class="active"' : '') !!}>
234231
<a href="{{ route('accessories.create') }}" tabindex="-1">
235232
<i class="far fa-keyboard fa-fw" aria-hidden="true"></i>
236-
{{ trans('general.accessory') }}</a>
233+
{{ trans('general.accessory') }}
234+
</a>
237235
</li>
238236
@endcan
239237
@can('create', \App\Models\Consumable::class)
@@ -982,7 +980,7 @@ class="sr-only">love</span> by <a href="https://twitter.com/snipeitapp" rel="noo
982980
container: 'body',
983981
animation: true,
984982
});
985-
983+
986984
$('[data-toggle="popover"]').popover();
987985
$('.select2 span').addClass('needsclick');
988986
$('.select2 span').removeAttr('title');
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Tests\Feature\Checkins;
4+
5+
use App\Events\CheckoutableCheckedIn;
6+
use App\Models\Accessory;
7+
use App\Models\User;
8+
use App\Notifications\CheckinAccessoryNotification;
9+
use Illuminate\Support\Facades\Event;
10+
use Illuminate\Support\Facades\Notification;
11+
use Tests\Support\InteractsWithSettings;
12+
use Tests\TestCase;
13+
14+
class AccessoryCheckinTest extends TestCase
15+
{
16+
use InteractsWithSettings;
17+
18+
public function testCheckingInAccessoryRequiresCorrectPermission()
19+
{
20+
$accessory = Accessory::factory()->checkedOutToUser()->create();
21+
22+
$this->actingAs(User::factory()->create())
23+
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id))
24+
->assertForbidden();
25+
}
26+
27+
public function testAccessoryCanBeCheckedIn()
28+
{
29+
Event::fake([CheckoutableCheckedIn::class]);
30+
31+
$user = User::factory()->create();
32+
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
33+
34+
$this->assertTrue($accessory->users->contains($user));
35+
36+
$this->actingAs(User::factory()->checkinAccessories()->create())
37+
->post(route('accessories.checkin.store', $accessory->users->first()->pivot->id));
38+
39+
$this->assertFalse($accessory->fresh()->users->contains($user));
40+
41+
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
42+
}
43+
44+
public function testEmailSentToUserIfSettingEnabled()
45+
{
46+
Notification::fake();
47+
48+
$user = User::factory()->create();
49+
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
50+
51+
$accessory->category->update(['checkin_email' => true]);
52+
53+
event(new CheckoutableCheckedIn(
54+
$accessory,
55+
$user,
56+
User::factory()->checkinAccessories()->create(),
57+
'',
58+
));
59+
60+
Notification::assertSentTo(
61+
[$user],
62+
function (CheckinAccessoryNotification $notification, $channels) {
63+
return in_array('mail', $channels);
64+
},
65+
);
66+
}
67+
68+
public function testEmailNotSentToUserIfSettingDisabled()
69+
{
70+
Notification::fake();
71+
72+
$user = User::factory()->create();
73+
$accessory = Accessory::factory()->checkedOutToUser($user)->create();
74+
75+
$accessory->category->update(['checkin_email' => false]);
76+
77+
event(new CheckoutableCheckedIn(
78+
$accessory,
79+
$user,
80+
User::factory()->checkinAccessories()->create(),
81+
'',
82+
));
83+
84+
Notification::assertNotSentTo(
85+
[$user],
86+
function (CheckinAccessoryNotification $notification, $channels) {
87+
return in_array('mail', $channels);
88+
},
89+
);
90+
}
91+
}

0 commit comments

Comments
 (0)