From a1802a2bf53b277f751b48c72f7d6774ae9d810f Mon Sep 17 00:00:00 2001 From: cproudlock Date: Thu, 3 Sep 2026 17:00:49 -0400 Subject: [PATCH] Match the number on the bin, and let an unset kiosk say so The last two kiosk findings. Keypad entry collected EVERY digit in an item's code, and the shipped prefix contains one: '3DP0004' collapsed to 30004, so an operator typing the 4 printed on the label was told no part matches that barcode and had to work out that the leading 3 belonged to the prefix. The number on a label is the number at the end, so the trailing digit run is what is compared now. An ambiguous number is still refused rather than guessed - taking from the wrong bin is worse than being asked to scan the label. A parts kiosk that had never been provisioned drew its normal "Scan the barcode on the bin" screen and answered "Not found" to every scan, which reads as "we do not stock that part" rather than "this screen was never set up". The server cannot say which: the routes answer a bare 404 on purpose, so a caller without the device token does not learn the door exists, and that stays. But the BROWSER knows whether it holds a token, and saying so discloses nothing - an unprovisioned screen now says it is not set up and how to fix it. For the case the client genuinely cannot distinguish - kiosk switched off versus a part that is not stocked, both a 404 by design - three misses in a row add a line suggesting the kiosk may have been switched off. Truthful without the server having to leak anything. Three tests, verified by planting the all-digits match back. Scope: product --- plugins/printedparts/api/routes.py | 11 +++- .../frontend/views/PartsKiosk.vue | 54 ++++++++++++++++- .../test_plugins/test_printedparts_ledger.py | 58 +++++++++++++++++++ 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/plugins/printedparts/api/routes.py b/plugins/printedparts/api/routes.py index be6191ba..58dc5688 100644 --- a/plugins/printedparts/api/routes.py +++ b/plugins/printedparts/api/routes.py @@ -75,6 +75,7 @@ def get_item(item_id: int): import glob import os +import re from flask import current_app from werkzeug.utils import secure_filename @@ -560,8 +561,14 @@ def _kiosk_find_item(itemcode): matches = [] for candidate in PrintedItem.query.filter_by(isactive=True).all(): for value in (candidate.itemcode, candidate.gagelabtag): - tail = ''.join(ch for ch in (value or '') if ch.isdigit()) - if tail and int(tail) == wanted: + # The TRAILING digit run, not every digit in the string. A + # prefix can contain digits - the shipped default is '3DP' - + # and collecting all of them turned 3DP0004 into 30004, so the + # operator typing the 4 printed on the bin got "no part matches + # that barcode" and had to work out that the 3 belonged to the + # prefix. The number on the label is the number at the end. + digits = re.search(r'(\d+)$', (value or '').strip()) + if digits and int(digits.group(1)) == wanted: matches.append(candidate) break if len(matches) == 1: diff --git a/plugins/printedparts/frontend/views/PartsKiosk.vue b/plugins/printedparts/frontend/views/PartsKiosk.vue index 37e7e82e..98ee9997 100644 --- a/plugins/printedparts/frontend/views/PartsKiosk.vue +++ b/plugins/printedparts/frontend/views/PartsKiosk.vue @@ -7,10 +7,31 @@ -
{{ error }}
+
+ {{ error }} +

+ Several scans in a row have found nothing. The kiosk may have been + switched off, or this screen's setup link may have been replaced - ask + an administrator to check Settings > 3D Printed Parts. +

+
+ + +
+

This screen is not set up yet

+

+ An administrator opens it once using the kiosk link from + Settings > 3D Printed Parts. The screen remembers it after that. +

+
-
+

Scan the barcode on the bin

@@ -108,6 +129,13 @@ const item = ref(null) const badge = ref('') const quantity = ref('') const error = ref('') +// Whether THIS browser holds the kiosk's device token. The server will not say +// (see the template), and it does not need to: an unprovisioned screen should +// say so rather than pretending to be a working kiosk with an empty catalog. +const provisioned = ref(true) +// Consecutive lookups that found nothing. Every scan missing usually means the +// kiosk was switched off, not that no bin is known. +const misses = ref(0) const doneMessage = ref('') const submitting = ref(false) const manualCode = ref('') @@ -118,6 +146,14 @@ let resetTimer = null onMounted(async () => { claimKioskToken(KIOSK_TOKEN_KEYS['/printedparts/kiosk/']) + try { + provisioned.value = Boolean( + localStorage.getItem(KIOSK_TOKEN_KEYS['/printedparts/kiosk/'])) + } catch { + // A browser refusing localStorage cannot be provisioned at all, and + // saying so is more use than a scan box that answers nothing. + provisioned.value = false + } // A kiosk left running for weeks reads this once at load, which is fine: the // label format is a property of the site's physical tags, not something that // changes during a shift. @@ -153,11 +189,17 @@ async function lookupItem(itemcode) { try { const response = await printedpartsApi.kioskItem(code) item.value = response.data.data + misses.value = 0 step.value = 'badge' manualCode.value = '' } catch (lookupError) { error.value = lookupError.response?.data?.data?.error?.message || 'No part matches that barcode' + // The gate and a genuine miss both answer 404, deliberately, so the client + // cannot tell them apart from one response. What it CAN say is that + // repeated misses may mean the kiosk was switched off rather than that + // every bin is unknown. + misses.value += 1 } focusEntry() } @@ -215,6 +257,14 @@ function reset() {