Skip to content

A free open source IT asset/license management system

Proted locations edit to blade components

snipe4a5e796116b8
diff --git a/resources/views/blade/input/user-select.blade.php b/resources/views/blade/input/user-select.blade.php
new file mode 100644
index 0000000000..380f9b9b42
--- /dev/null
+++ b/resources/views/blade/input/user-select.blade.php
@@ -0,0 +1,81 @@
+@use('App\Models\User', 'User')
+
+{{-- companyId scopes the ajax lookup to a specific company (via
+ data-company-ids consumed by the js-data-ajax initializer in
+ snipeit.js). excludeId hides a specific user from the list — used
+ by the users/edit page's manager picker so a user can't select
+ themselves as their own manager. wrapperId and id default to the
+ legacy "assigned_user" / "assigned_user_select" values so pages
+ with JS that toggles #assigned_user (asset checkout target
+ picker) keep working after the migration off
+ partials.forms.edit.user-select. --}}
+@props([
+ 'label',
+ 'name',
+ 'selected' => null,
+ 'required' => false,
+ 'hideNewButton' => false,
+ 'companyId' => null,
+ 'excludeId' => null,
+ 'wrapperId' => 'assigned_user',
+ 'id' => 'assigned_user_select',
+ 'style' => null,
+])
+
+<div
+ id="{{ $wrapperId }}"
+ @class([
+ 'form-group',
+ 'has-error' => $errors->has($name),
+ ])
+ @if ($style) style="{{ $style }}" @endif
+>
+ <label for="{{ $id }}" class="col-md-3 control-label">{{ $label }}</label>
+
+ <div class="col-md-7">
+ <select
+ class="js-data-ajax"
+ data-endpoint="users"
+ data-placeholder="{{ trans('general.select_user') }}"
+ @if ($companyId) data-company-ids="{{ $companyId }}" @endif
+ @if ($excludeId) data-exclude-id="{{ $excludeId }}" @endif
+ name="{{ $name }}"
+ id="{{ $id }}"
+ style="width: 100%"
+ aria-label="{{ $name }}"
+ @required($required)
+ >
+ @if ($selected)
+ <option value="{{ $selected }}" selected="selected" role="option" aria-selected="true">
+ {{ User::find($selected)?->present()->fullName }}
+ </option>
+ @else
+ <option value="" role="option">{{ trans('general.select_user') }}</option>
+ @endif
+ </select>
+ </div>
+
+ @unless ($hideNewButton)
+ <div class="col-md-1 col-sm-1 text-left">
+ @can('create', User::class)
+ <a
+ href="{{ route('modal.show', 'user') }}"
+ data-toggle="modal"
+ data-target="#createModal"
+ data-select="{{ $id }}"
+ class="btn btn-sm btn-theme"
+ >{{ trans('button.new') }}</a>
+ @endcan
+ </div>
+ @endunless
+
+ @if ($snipeSettings->full_multiple_companies_support == '1')
+ @cannot('superadmin')
+ <div class="col-md-7 col-md-offset-3">
+ <p class="help-block"><x-icon type="tip" /> {{ trans('general.fmcs_select_note') }}</p>
+ </div>
+ @endcannot
+ @endif
+
+ <div class="col-md-8 col-md-offset-3"><x-form.error :name="$name" /></div>
+</div>
diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php
index 7a39e22bf4..0eff2fbf22 100755
--- a/resources/views/locations/edit.blade.php
+++ b/resources/views/locations/edit.blade.php
@@ -55,7 +55,11 @@
id="parent_id_location_select"
/>
- @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/users/table.manager'), 'fieldname' => 'manager_id'])
+ <x-input.user-select
+ :label="trans('admin/users/table.manager')"
+ name="manager_id"
+ :selected="old('manager_id', $item->manager_id)"
+ />
<x-form.row
:label="trans('admin/suppliers/table.phone')"
diff --git a/tests/Feature/Locations/Ui/UpdateLocationsTest.php b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
index c00ecaf0de..0c07ccc35a 100644
--- a/tests/Feature/Locations/Ui/UpdateLocationsTest.php
+++ b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
@@ -28,6 +28,27 @@ class UpdateLocationsTest extends TestCase
->assertOk();
}
+ public function test_edit_page_ships_manager_select_and_submit_controls()
+ {
+ // Regression guard for the migration off @include('partials.forms
+ // .edit.user-select') to <x-input.user-select>. The manager
+ // picker must still emit the assigned_user_select select id (the
+ // "+ New user" quick-create modal targets it via data-select), and
+ // the bottom cancel/save controls come from <x-box.footer /> which
+ // <x-box> renders when its parent <x-form> exposes a route.
+ $manager = User::factory()->create();
+ $location = Location::factory()->create(['manager_id' => $manager->id]);
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('locations.edit', $location))
+ ->assertOk();
+
+ $response->assertSee('id="assigned_user_select"', false);
+ $response->assertSee('name="manager_id"', false);
+ $response->assertSee('value="'.$manager->id.'"', false);
+ $response->assertSee('id="submit_button"', false);
+ }
+
public function test_user_can_edit_locations()
{
$location = Location::factory()->create(['name' => 'Test Location']);