Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe
2024-07-10 08:56:29 +01:00
5 changed files with 38 additions and 15 deletions
@@ -8,6 +8,7 @@ use App\Http\Requests\StoreAssetModelRequest;
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;
@@ -457,7 +458,7 @@ class AssetModelsController extends Controller
* @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) {
@@ -466,17 +467,17 @@ class AssetModelsController extends Controller
$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);
@@ -499,7 +500,7 @@ class AssetModelsController extends Controller
* Removes all default values
*
*/
private function removeCustomFieldsDefaultValues(AssetModel $model) : void
private function removeCustomFieldsDefaultValues(AssetModel|SnipeModel $model): void
{
$model->defaultValues()->detach();
}
+1 -1
View File
@@ -70,7 +70,7 @@ class CheckoutAcceptance extends Model
*/
public function isCheckedOutTo(User $user)
{
return $this->assignedTo->is($user);
return $this->assignedTo?->is($user);
}
/**
+5 -3
View File
@@ -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>
+6 -6
View File
@@ -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')) }}">
@@ -386,18 +388,16 @@
<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
@@ -469,7 +469,7 @@
});
});
</script>
@endpush
</body>
@@ -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;
@@ -76,4 +78,22 @@ class AccessoryAcceptanceTest extends TestCase
}
);
}
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);
}
}