Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Jul 10, 2024
2 parents 18f7ca8 + 71a5d07 commit 45d7e2d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Actionlog;
use App\Models\AssetModel;
use App\Models\CustomField;
use App\Models\SnipeModel;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -457,7 +458,7 @@ private function shouldAddDefaultValues(array $input) : bool
* @param AssetModel $model
* @param array $defaultValues
*/
private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues): bool
private function assignCustomFieldsDefaultValues(AssetModel|SnipeModel $model, array $defaultValues): bool
{
$data = array();
foreach ($defaultValues as $customFieldId => $defaultValue) {
Expand All @@ -466,17 +467,17 @@ private function assignCustomFieldsDefaultValues(AssetModel $model, array $defau
$data[$customField->db_column] = $defaultValue;
}

$fieldsets = $model->fieldset->validation_rules();
$allRules = $model->fieldset->validation_rules();
$rules = array();

foreach ($fieldsets as $fieldset => $validation){
foreach ($allRules as $field => $validation) {
// If the field is marked as required, eliminate the rule so it doesn't interfere with the default values
// (we are at model level, the rule still applies when creating a new asset using this model)
$index = array_search('required', $validation);
if ($index !== false){
$validation[$index] = 'nullable';
}
$rules[$fieldset] = $validation;
$rules[$field] = $validation;
}

$validator = Validator::make($data, $rules);
Expand All @@ -499,7 +500,7 @@ private function assignCustomFieldsDefaultValues(AssetModel $model, array $defau
* Removes all default values
*
*/
private function removeCustomFieldsDefaultValues(AssetModel $model) : void
private function removeCustomFieldsDefaultValues(AssetModel|SnipeModel $model): void
{
$model->defaultValues()->detach();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CheckoutAcceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function isPending()
*/
public function isCheckedOutTo(User $user)
{
return $this->assignedTo->is($user);
return $this->assignedTo?->is($user);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,13 @@

@if (($asset->assignedTo) && ($asset->deleted_at==''))
<div style="text-align: left">
<h2>{{ trans('admin/hardware/form.checkedout_to') }}</h2>
<h2>
{{ trans('admin/hardware/form.checkedout_to') }}
</h2>
<p>
@if($asset->checkedOutToUser()) <!-- Only users have avatars currently-->
@if (($asset->checkedOutToUser()) && ($asset->assignedTo->present()->gravatar()))
<img src="{{ $asset->assignedTo->present()->gravatar() }}" class="user-image-inline" alt="{{ $asset->assignedTo->present()->fullName() }}">
@endif
@endif
</p>
{!! $asset->assignedTo->present()->glyph() . ' ' .$asset->assignedTo->present()->nameUrl() !!}
</p>
Expand Down
12 changes: 6 additions & 6 deletions resources/views/users/print.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<link rel="shortcut icon" type="image/ico" href="{{ ($snipeSettings) && ($snipeSettings->favicon!='') ? Storage::disk('public')->url(e($snipeSettings->favicon)) : config('app.url').'/favicon.ico' }}">

<link rel="stylesheet" href="{{ url(mix('css/dist/bootstrap-table.css')) }}">

{{-- stylesheets --}}
<link rel="stylesheet" href="{{ url(mix('css/dist/all.css')) }}">

Expand Down Expand Up @@ -386,18 +388,16 @@ class="snipe-table table table-striped inventory"
<script src="{{ url(mix('js/dist/all.js')) }}" nonce="{{ csrf_token() }}"></script>


@push('css')
<link rel="stylesheet" href="{{ url(mix('css/dist/bootstrap-table.css')) }}">
@endpush

@push('js')



<script src="{{ url(mix('js/dist/bootstrap-table.js')) }}"></script>

<script>
$('.snipe-table').bootstrapTable('destroy').each(function () {
console.log('BS table loaded');
data_export_options = $(this).attr('data-export-options');
export_options = data_export_options ? JSON.parse(data_export_options) : {};
export_options['htmlContent'] = false; // this is already the default; but let's be explicit about it
Expand Down Expand Up @@ -469,7 +469,7 @@ classes: 'table table-responsive table-no-bordered',
});
});
</script>
@endpush



</body>
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Tests\Feature\CheckoutAcceptances\Ui;

use App\Models\Accessory;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
use App\Models\User;
use App\Notifications\AcceptanceAssetAcceptedNotification;
use App\Notifications\AcceptanceAssetDeclinedNotification;
use Notification;
Expand Down Expand Up @@ -76,4 +78,22 @@ function (AcceptanceAssetDeclinedNotification $notification) use ($acceptance) {
}
);
}

public function testUserIsNotAbleToAcceptAnAssetAssignedToADifferentUser()
{
Notification::fake();

$otherUser = User::factory()->create();

$acceptance = CheckoutAcceptance::factory()
->pending()
->for(Asset::factory()->laptopMbp(), 'checkoutable')
->create();

$this->actingAs($otherUser)
->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted'])
->assertSessionHas(['error' => trans('admin/users/message.error.incorrect_user_accepted')]);

$this->assertNull($acceptance->fresh()->accepted_at);
}
}

0 comments on commit 45d7e2d

Please sign in to comment.