Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2024-08-23 07:32:39 +01:00
commit 50cb7e65c9
7 changed files with 96 additions and 17 deletions

View file

@ -3199,6 +3199,15 @@
"contributions": [
"code"
]
},
{
"login": "setpill",
"name": "setpill",
"avatar_url": "https://avatars.githubusercontent.com/u/37372069?v=4",
"profile": "https://github.com/setpill",
"contributions": [
"code"
]
}
]
}

View file

@ -52,7 +52,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken
| [<img src="https://avatars.githubusercontent.com/u/47315739?v=4" width="110px;"/><br /><sub>bilias</sub>](https://github.com/bilias)<br />[💻](https://github.com/snipe/snipe-it/commits?author=bilias "Code") | [<img src="https://avatars.githubusercontent.com/u/2565989?v=4" width="110px;"/><br /><sub>coach1988</sub>](https://github.com/coach1988)<br />[💻](https://github.com/snipe/snipe-it/commits?author=coach1988 "Code") | [<img src="https://avatars.githubusercontent.com/u/11910225?v=4" width="110px;"/><br /><sub>MrM</sub>](https://github.com/mauro-miatello)<br />[💻](https://github.com/snipe/snipe-it/commits?author=mauro-miatello "Code") | [<img src="https://avatars.githubusercontent.com/u/60405354?v=4" width="110px;"/><br /><sub>koiakoia</sub>](https://github.com/koiakoia)<br />[💻](https://github.com/snipe/snipe-it/commits?author=koiakoia "Code") | [<img src="https://avatars.githubusercontent.com/u/5323832?v=4" width="110px;"/><br /><sub>Mustafa Online</sub>](https://github.com/mustafa-online)<br />[💻](https://github.com/snipe/snipe-it/commits?author=mustafa-online "Code") | [<img src="https://avatars.githubusercontent.com/u/104601439?v=4" width="110px;"/><br /><sub>franceslui</sub>](https://github.com/franceslui)<br />[💻](https://github.com/snipe/snipe-it/commits?author=franceslui "Code") | [<img src="https://avatars.githubusercontent.com/u/125313163?v=4" width="110px;"/><br /><sub>Q4kK</sub>](https://github.com/Q4kK)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Q4kK "Code") |
| [<img src="https://avatars.githubusercontent.com/u/55590532?v=4" width="110px;"/><br /><sub>squintfox</sub>](https://github.com/squintfox)<br />[💻](https://github.com/snipe/snipe-it/commits?author=squintfox "Code") | [<img src="https://avatars.githubusercontent.com/u/1380084?v=4" width="110px;"/><br /><sub>Jeff Clay</sub>](https://github.com/jeffclay)<br />[💻](https://github.com/snipe/snipe-it/commits?author=jeffclay "Code") | [<img src="https://avatars.githubusercontent.com/u/52716446?v=4" width="110px;"/><br /><sub>Phil J R</sub>](https://github.com/PP-JN-RL)<br />[💻](https://github.com/snipe/snipe-it/commits?author=PP-JN-RL "Code") | [<img src="https://avatars.githubusercontent.com/u/1496725?v=4" width="110px;"/><br /><sub>i_virus</sub>](https://www.corelight.com/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=chandanchowdhury "Code") | [<img src="https://avatars.githubusercontent.com/u/1020541?v=4" width="110px;"/><br /><sub>Paul Grime</sub>](https://github.com/gitgrimbo)<br />[💻](https://github.com/snipe/snipe-it/commits?author=gitgrimbo "Code") | [<img src="https://avatars.githubusercontent.com/u/922815?v=4" width="110px;"/><br /><sub>Lee Porte</sub>](https://leeporte.co.uk)<br />[💻](https://github.com/snipe/snipe-it/commits?author=LeePorte "Code") | [<img src="https://avatars.githubusercontent.com/u/23613427?v=4" width="110px;"/><br /><sub>BRYAN </sub>](https://github.com/bryanlopezinc)<br />[💻](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Code") [⚠️](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Tests") |
| [<img src="https://avatars.githubusercontent.com/u/64061710?v=4" width="110px;"/><br /><sub>U-H-T</sub>](https://github.com/U-H-T)<br />[💻](https://github.com/snipe/snipe-it/commits?author=U-H-T "Code") | [<img src="https://avatars.githubusercontent.com/u/5395363?v=4" width="110px;"/><br /><sub>Matt Tyree</sub>](https://github.com/Tyree)<br />[📖](https://github.com/snipe/snipe-it/commits?author=Tyree "Documentation") | [<img src="https://avatars.githubusercontent.com/u/292081?v=4" width="110px;"/><br /><sub>Florent Bervas</sub>](http://spoontux.net)<br />[💻](https://github.com/snipe/snipe-it/commits?author=FlorentDotMe "Code") | [<img src="https://avatars.githubusercontent.com/u/4498077?v=4" width="110px;"/><br /><sub>Daniel Albertsen</sub>](https://ditscheri.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=dbakan "Code") | [<img src="https://avatars.githubusercontent.com/u/100710244?v=4" width="110px;"/><br /><sub>r-xyz</sub>](https://github.com/r-xyz)<br />[💻](https://github.com/snipe/snipe-it/commits?author=r-xyz "Code") | [<img src="https://avatars.githubusercontent.com/u/47491036?v=4" width="110px;"/><br /><sub>Steven Mainor</sub>](https://github.com/DrekiDegga)<br />[💻](https://github.com/snipe/snipe-it/commits?author=DrekiDegga "Code") | [<img src="https://avatars.githubusercontent.com/u/65785975?v=4" width="110px;"/><br /><sub>arne-kroeger</sub>](https://github.com/arne-kroeger)<br />[💻](https://github.com/snipe/snipe-it/commits?author=arne-kroeger "Code") |
| [<img src="https://avatars.githubusercontent.com/u/167117705?v=4" width="110px;"/><br /><sub>Glukose1</sub>](https://github.com/Glukose1)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | [<img src="https://avatars.githubusercontent.com/u/1197791?v=4" width="110px;"/><br /><sub>Scarzy</sub>](https://github.com/Scarzy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Scarzy "Code") |
| [<img src="https://avatars.githubusercontent.com/u/167117705?v=4" width="110px;"/><br /><sub>Glukose1</sub>](https://github.com/Glukose1)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | [<img src="https://avatars.githubusercontent.com/u/1197791?v=4" width="110px;"/><br /><sub>Scarzy</sub>](https://github.com/Scarzy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Scarzy "Code") | [<img src="https://avatars.githubusercontent.com/u/37372069?v=4" width="110px;"/><br /><sub>setpill</sub>](https://github.com/setpill)<br />[💻](https://github.com/snipe/snipe-it/commits?author=setpill "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

View file

@ -47,9 +47,10 @@ class SendAcceptanceReminder extends Command
{
$pending = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')
->whereHas('checkoutable', function($query) {
$query->where('archived', 0);
$query->where('accepted_at', null)
->where('declined_at', null);
})
->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])
->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.admin'])
->get();
$count = 0;

View file

@ -151,17 +151,17 @@ class AssetModelsController extends Controller
$model->notes = $request->input('notes');
$model->requestable = $request->input('requestable', '0');
$this->removeCustomFieldsDefaultValues($model);
$model->fieldset_id = $request->input('fieldset_id');
if ($this->shouldAddDefaultValues($request->input())) {
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
}
}
if ($model->save()) {
$this->removeCustomFieldsDefaultValues($model);
if ($this->shouldAddDefaultValues($request->input())) {
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))) {
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
}
}
if ($model->wasChanged('eol')) {
if ($model->eol > 0) {
$newEol = $model->eol;

View file

@ -14,6 +14,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\NoSessionStore::class,
\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Session\Middleware\StartSession::class,

View file

@ -647,7 +647,7 @@ dir="{{ Helper::determineLanguageDirection() }}">
<a href="#" id="settings">
<x-icon type="settings" />
<span>{{ trans('general.settings') }}</span>
<x-icon type="angle-left" class="fa-fw"/>
<x-icon type="angle-left" class="pull-right fa-fw"/>
</a>
<ul class="treeview-menu">

View file

@ -4,6 +4,8 @@ namespace Tests\Feature\AssetModels\Ui;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Tests\TestCase;
@ -12,14 +14,13 @@ class UpdateAssetModelsTest extends TestCase
public function testPermissionRequiredToStoreAssetModel()
{
$this->actingAs(User::factory()->create())
->post(route('models.store'), [
'name' => 'Test Model',
'category_id' => Category::factory()->create()->id
->put(route('models.update', ['model' => AssetModel::factory()->create()]), [
'name' => 'Changed Name',
'category_id' => Category::factory()->create()->id,
])
->assertStatus(403)
->assertForbidden();
}
public function testUserCanEditAssetModels()
{
$category = Category::factory()->forAssets()->create();
@ -62,4 +63,71 @@ class UpdateAssetModelsTest extends TestCase
}
public function test_default_values_remain_unchanged_after_validation_error_occurs()
{
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
$assetModel = AssetModel::factory()->create();
$customFieldset = CustomFieldset::factory()->create();
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
$customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]);
$assetModel->fieldset()->associate($customFieldset);
$assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']);
$assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']);
$this->actingAs(User::factory()->superuser()->create())
->put(route('models.update', ['model' => $assetModel]), [
// should trigger validation error without name, etc, and NOT remove or change default values
'add_default_values' => '1',
'fieldset_id' => $customFieldset->id,
'default_values' => [
$customFieldOne->id => 'first changed value',
$customFieldTwo->id => 'second changed value',
],
]);
$potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value');
$this->assertCount(2, $potentiallyChangedDefaultValues);
$this->assertContains('first default value', $potentiallyChangedDefaultValues);
$this->assertContains('second default value', $potentiallyChangedDefaultValues);
}
public function test_default_values_can_be_updated()
{
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
$assetModel = AssetModel::factory()->create();
$customFieldset = CustomFieldset::factory()->create();
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
$customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]);
$assetModel->fieldset()->associate($customFieldset);
$assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']);
$assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']);
$this->actingAs(User::factory()->superuser()->create())
->put(route('models.update', ['model' => $assetModel]), [
// should trigger validation error without name, etc, and NOT remove or change default values
'name' => 'Test Model Edited',
'category_id' => $assetModel->category_id,
'add_default_values' => '1',
'fieldset_id' => $customFieldset->id,
'default_values' => [
$customFieldOne->id => 'first changed value',
$customFieldTwo->id => 'second changed value',
],
]);
$potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value');
$this->assertCount(2, $potentiallyChangedDefaultValues);
$this->assertContains('first changed value', $potentiallyChangedDefaultValues);
$this->assertContains('second changed value', $potentiallyChangedDefaultValues);
}
}