5.7 KiB
Doctor desktop embedded eSign delivery
Implemented the shared prescription signing dialog as a 1040 × 800 in-system screen (minimum 900 × 700). The doctor explicitly chooses 核身并签署 and sees that successful authentication will continue signing. The official authentication URL opens only in the embedded QtWebEngine view. There is no external-browser action or fallback.
Safety and lifecycle
- Each authentication view uses an off-the-record, memory-cache profile with no persistent cookies and no application bridge. The profile outlives its page and is deleted after page teardown.
- HTTPS navigation and network resources are restricted to official
*.esign.cn/*.tsign.cnhosts; port 8890 is allowed only for the existing officialsmlfront.esign.cnsandbox host. Initial URLs retain the existing exact official entry-host allowlist. - Popups, custom app schemes, external navigation, uploads, downloads, clipboard privileges, device permission requests and invalid TLS certificates are denied. Blocked flows show an actionable inline error. Provider console messages are not logged.
- Missing QtWebEngine produces an inline repair/update instruction before a start request is sent.
- A visible, explicitly started authentication uses one read-only
GET esignIdentityStatusat a time, every 5 seconds, bounded to 10 minutes. Its ApiClient call hasmax_retries=0; default retry behavior for unrelated GETs remains unchanged. - Signing is dispatched once only after a structurally valid server response has
identity_status=SUCCESS,can_complete=true,status=authenticating, and current actor signing permission. Browser loads, redirects and client events cannot authorize completion. - The completion latch is set before dispatch. A timeout, error, ambiguous response or manual refresh never resubmits the signing POST from the same dialog.
- Hide, close, failure, terminal server state and timeout stop polling. Generation checks reject stale results; callbacks verify the dialog still exists. Old webview errors cannot affect a new explicit flow. The close action remains usable during requests.
- Manual recheck performs the identity GET and preserves an already-loaded SMS form. Signed-PDF downloads retain authoritative recheck and SHA-256 validation.
Changed files
app/src/doctor_workstation/ui/dialogs/prescription_esign.pyapp/src/doctor_workstation/ui/dialogs/esign_webview.py(new)app/src/doctor_workstation/core/esign.pyapp/src/doctor_workstation/services/repository.pyapp/src/doctor_workstation/services/mock_repository.pyapp/src/doctor_workstation/services/api_client.py(parent-authorized per-call retry override)app/tests/test_prescription_esign.pyapp/tests/test_esign_webview.py(new)
Added lines use LF; unchanged baseline line endings in the large repository modules are preserved to avoid unrelated churn. app/src/doctor_workstation/__init__.py was not edited.
Verification
164 passed in 1.91 seconds across test_prescription_esign.py, test_esign_webview.py, test_api_client.py, test_repository_parity.py, and test_mock_repository.py. Targeted Ruff checks passed. Tests cover in-system entry, no external browser, identity DTO validation, permission gating, single-flight polling, one-shot signing, timeout/error recovery, stale/hide/close callbacks, no completion on browser loads, unchanged GET retry defaults, navigation/permission/TLS restrictions and original download validation. No vendor requests or real authentication were performed by this agent.
Native QtWebEngine construction in the restricted execution sandbox exits with Windows code -2147483645 at QWebEngineProfile(parent), both with offscreen and ordinary windows platforms; this also reproduces with bare Qt classes outside the application code. The parent will verify the real visible launcher outside that execution restriction. No Chromium --no-sandbox workaround or TLS relaxation was introduced.
Native initialization follow-up
The parent's elevated visible launch exposed a real Qt lifecycle issue: adding the first WebEngine view to an already visible dialog asynchronously recreates the native parent window. Qt emits a non-spontaneous hide/show pair after the start handler returns. The original hide handler invalidated the pending start response and removed the embedded page.
The fix now scopes a native-window ID check to creation of a fresh identity view. During the transient hide, polling and completion pause, and pending response callbacks defer. The flow resumes only if the same dialog is visible again with a different native-window ID. A still-hidden window, same-ID hide/show, explicit hide(), minimize, close, or already-completed initialization continues to cancel the flow. Normal hideEvent safety remains in force outside that narrow initialization transition. Renderer initialization is not identity proof and never authorizes signing.
Verification after this fix: 167 passed, 2 opt-in native tests skipped in the targeted delivery set; 2 native Windows Qt tests passed in 4.38 seconds when run elevated with ESIGN_NATIVE_QT_TEST=1 and QT_QPA_PLATFORM=windows. The native test constructs the actual embedded WebEngine, verifies the native handle really changed, verifies authentication state/polling survive, and verifies a genuine user hide cancels. Both tests replace provider URL loading and use a fake repository; no provider calls occur. Ruff passed. The reproducible native tests are in app/tests/test_esign_native_lifecycle.py.
An optional combined run including test_prescription_security_ui.py aborted in that existing suite at line 157 (application.processEvents()). The isolated 164-test delivery set above subsequently passed. This broader suite was not modified.