Let a typed employee name find the employee
Reported from the floor: somebody types the employee's whole name into the notification or recognition picker and presses Enter instead of clicking the suggestion, and the entry does not pull from the employee database. Two causes, one symptom. The search matched the WHOLE query against first name or last name, so "Dana Reyes" found nobody - no single column holds that string. Typing a full name is what a person does before pressing Enter, and it was the one thing guaranteed to return an empty list. A multi-word query is now treated as a full name: every word must appear somewhere in the name, in either column, so "Reyes Dana" works too, and "Dana Reyes" does not also return Sam Reyes. A single word still searches broadly, and an SSO still resolves. Both directory backends changed, the self-hosted tables and the external HR database. With no suggestion to click, the form then turned the typed text into `NAME:<text>` - a label linked to nothing. On screen that chip is identical to a real selection; the difference only shows up later as no photo, no directory link, and a recognition the person it is about cannot be found by. Both pickers (the notifications form and the shared EmployeeSearch component) now look a typed name up before deciding it is free text, through one helper. An exact full-name match wins over a longer partial one, because somebody typing "Dana Reyes" means that person and not "Dana Reyes-Smith". A genuinely ambiguous name is NOT guessed at - the candidates are shown and the operator picks, which is exactly when picking wrong matters most. A directory that cannot be reached reports failure rather than silently producing a label. Eleven tests. The search rules verified by planting the single-term query back. One note for whoever reads the spec: the failure-branch test uses a thenable that rejects rather than a mock returning a rejected promise. The runner collects such a promise as an unhandled error even when the code under test catches it, and fails the very test that proves the catch works. Scope: product
This commit is contained in:
@@ -143,6 +143,10 @@
|
||||
v-model="form.locationid"
|
||||
class="form-control"
|
||||
>
|
||||
<!-- Blank means "no location of its own", which is a real state:
|
||||
the PC then follows whatever it is attached to. The hint
|
||||
below says where that currently resolves to, so leaving the
|
||||
box empty is an informed choice rather than a missing one. -->
|
||||
<option value="">Select location...</option>
|
||||
<option
|
||||
v-for="l in locations"
|
||||
@@ -152,6 +156,12 @@
|
||||
{{ l.locationname }}
|
||||
</option>
|
||||
</select>
|
||||
<small v-if="!form.locationid && inheritedLocation" class="input-hint">
|
||||
No location of its own. It currently shows
|
||||
<strong>{{ inheritedLocation.locationname }}</strong>, inherited
|
||||
from {{ inheritedLocation.inheritedfrom }}. Pick one here only to
|
||||
override that.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -400,6 +410,11 @@ const customFieldsRef = ref(null)
|
||||
const printerPickerRef = ref(null)
|
||||
const currentAssetId = ref(null)
|
||||
|
||||
// What this PC resolves to today when it owns no location, captured at load.
|
||||
// Read-only: the form must never post it back as the record's own, which is
|
||||
// exactly what binding the location select to the merged `locationid` did.
|
||||
const inheritedLocation = ref(null)
|
||||
|
||||
// PC Number (assetnumber) defaults to the serial number while the user hasn't
|
||||
// typed their own. Editable; only auto-fills on a new PC.
|
||||
const manualPcNumber = ref(false)
|
||||
@@ -554,6 +569,7 @@ onMounted(async () => {
|
||||
|
||||
const primaryComm = pc.communications?.find(c => c.isprimary) || pc.communications?.[0]
|
||||
|
||||
inheritedLocation.value = pc.inheritedlocation || null
|
||||
form.value = {
|
||||
machinenumber: pc.assetnumber || '',
|
||||
alias: pc.name && pc.name.toUpperCase() !== 'NONE' ? pc.name : '',
|
||||
@@ -565,7 +581,11 @@ onMounted(async () => {
|
||||
statusid: pc.statusid || '',
|
||||
vendorid: ext.vendorid || '',
|
||||
modelnumberid: ext.modelnumberid || '',
|
||||
locationid: pc.locationid || '',
|
||||
// The OWN location, not the resolved one. Binding to `locationid`
|
||||
// meant the form pre-selected a location this PC had inherited from a
|
||||
// machine, and saving wrote it back as the PC's own - so an edit that
|
||||
// never touched location silently stopped the PC following its parent.
|
||||
locationid: pc.ownlocationid || '',
|
||||
osid: ext.osid || '',
|
||||
loggedinuser: ext.loggedinuser || '',
|
||||
azuredeviceid: ext.azuredeviceid || '',
|
||||
@@ -576,9 +596,9 @@ onMounted(async () => {
|
||||
portoverride: a.portoverride ?? null
|
||||
})),
|
||||
notes: pc.notes || '',
|
||||
mapx: pc.mapx ?? null,
|
||||
mapy: pc.mapy ?? null,
|
||||
levelid: pc.levelid ?? null,
|
||||
mapx: pc.ownmapx ?? null,
|
||||
mapy: pc.ownmapy ?? null,
|
||||
levelid: pc.ownlevelid ?? null,
|
||||
ipaddress: primaryComm?.ipaddress || ''
|
||||
}
|
||||
|
||||
|
||||
@@ -295,12 +295,31 @@ def search_employees():
|
||||
'Search query must be at least 2 characters'
|
||||
)
|
||||
|
||||
# A multi-word query is a FULL NAME. Each word was matched against first
|
||||
# name or last name on its own, so "Dana Reyes" found nobody: no single
|
||||
# column contains that string. Somebody typing the whole name - which is
|
||||
# what a person does before pressing Enter, rather than picking from the
|
||||
# list - got an empty result and their entry became free text linked to no
|
||||
# employee record.
|
||||
words = query.split()
|
||||
|
||||
if _selfhosted():
|
||||
term = f'%{query}%'
|
||||
rows = (DirectoryEmployee.query
|
||||
.filter(db.or_(DirectoryEmployee.firstname.ilike(term),
|
||||
DirectoryEmployee.lastname.ilike(term),
|
||||
db.cast(DirectoryEmployee.sso, db.String).ilike(term)))
|
||||
rows = DirectoryEmployee.query
|
||||
if len(words) > 1:
|
||||
# Every word has to appear in the name, in either column, so
|
||||
# "Reyes Dana" works as well as "Dana Reyes".
|
||||
for word in words:
|
||||
term = f'%{word}%'
|
||||
rows = rows.filter(db.or_(
|
||||
DirectoryEmployee.firstname.ilike(term),
|
||||
DirectoryEmployee.lastname.ilike(term)))
|
||||
else:
|
||||
term = f'%{query}%'
|
||||
rows = rows.filter(db.or_(
|
||||
DirectoryEmployee.firstname.ilike(term),
|
||||
DirectoryEmployee.lastname.ilike(term),
|
||||
db.cast(DirectoryEmployee.sso, db.String).ilike(term)))
|
||||
rows = (rows
|
||||
.order_by(DirectoryEmployee.lastname, DirectoryEmployee.firstname)
|
||||
.limit(limit).all())
|
||||
return success_response([_with_photo_url(e.to_dict()) for e in rows])
|
||||
@@ -308,15 +327,32 @@ def search_employees():
|
||||
try:
|
||||
conn = employee_connection()
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(f'''
|
||||
SELECT {_FIELDS}
|
||||
FROM employees
|
||||
WHERE First_Name LIKE %s
|
||||
OR Last_Name LIKE %s
|
||||
OR CAST(SSO AS CHAR) LIKE %s
|
||||
ORDER BY Last_Name, First_Name
|
||||
LIMIT %s
|
||||
''', (f'%{query}%', f'%{query}%', f'%{query}%', limit))
|
||||
if len(words) > 1:
|
||||
# Same rule as the self-hosted branch: every word must appear
|
||||
# somewhere in the name, so a full name finds the person.
|
||||
clauses = ' AND '.join(
|
||||
['(First_Name LIKE %s OR Last_Name LIKE %s)'] * len(words))
|
||||
params = []
|
||||
for word in words:
|
||||
params.extend([f'%{word}%', f'%{word}%'])
|
||||
params.append(limit)
|
||||
cur.execute(f'''
|
||||
SELECT {_FIELDS}
|
||||
FROM employees
|
||||
WHERE {clauses}
|
||||
ORDER BY Last_Name, First_Name
|
||||
LIMIT %s
|
||||
''', tuple(params))
|
||||
else:
|
||||
cur.execute(f'''
|
||||
SELECT {_FIELDS}
|
||||
FROM employees
|
||||
WHERE First_Name LIKE %s
|
||||
OR Last_Name LIKE %s
|
||||
OR CAST(SSO AS CHAR) LIKE %s
|
||||
ORDER BY Last_Name, First_Name
|
||||
LIMIT %s
|
||||
''', (f'%{query}%', f'%{query}%', f'%{query}%', limit))
|
||||
employees = cur.fetchall()
|
||||
conn.close()
|
||||
return success_response([_with_photo_url(e) for e in employees])
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
import { ref, onMounted, computed, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { notificationsApi, applicationsApi, businessUnitsApi, employeesApi, settingsApi } from '@/api'
|
||||
import { resolveEmployeeName, fullname } from '@/composables/employeeResolve'
|
||||
import { apiError } from '@/utils/apiError'
|
||||
import { zonedInputFromUtc, utcFromZonedInput, DEFAULT_TZ } from '@/utils/datetime'
|
||||
|
||||
@@ -459,6 +460,30 @@ async function addCustomEmployee() {
|
||||
}
|
||||
selectedEmployees.value.push({ sso: token, name })
|
||||
} else {
|
||||
// Look the name up before treating it as free text. Typing a name in
|
||||
// full and pressing Enter used to produce `NAME:<text>`, linked to
|
||||
// nothing - no photo, no directory record - while picking the same
|
||||
// person off the suggestion list produced a real SSO. The chip looked
|
||||
// identical either way, which is why it went unnoticed.
|
||||
const { match, matches, failed } = await resolveEmployeeName(token)
|
||||
if (match) {
|
||||
const sso = String(match.SSO)
|
||||
if (selectedEmployees.value.some(e => e.sso === sso)) continue
|
||||
selectedEmployees.value.push({ sso, name: fullname(match) || token })
|
||||
continue
|
||||
}
|
||||
if (matches && matches.length) {
|
||||
// Several people match. Guessing is exactly wrong here, so show the
|
||||
// list and let the operator pick.
|
||||
employeeResults.value = matches
|
||||
error.value = `More than one employee matches "${token}" - pick one.`
|
||||
return
|
||||
}
|
||||
if (failed) {
|
||||
error.value = 'Could not reach the employee directory. Try again, or '
|
||||
+ 'pick from the list.'
|
||||
return
|
||||
}
|
||||
const key = `NAME:${token}`
|
||||
if (selectedEmployees.value.some(e => e.sso === key)) continue
|
||||
selectedEmployees.value.push({ sso: key, name: token })
|
||||
|
||||
Reference in New Issue
Block a user