Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Fix status-page Edit modal and notes Edit Notes for non-owners

Omega (QA)3c27b7c949d8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7d98d13..70a099b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -76,6 +76,8 @@
- _Files: `backend/warranties_routes.py`, `tests/test_csv_date_formats.py`_
- **SSO login fixed:** the single-use code exchange added for OIDC sign-in used `await` inside a plain (non-async) page-load callback, so the whole login redirect script failed to parse and sign-in through an identity provider stalled at "Authenticating, please wait..." with no error shown. The callback is now async, so the code exchange runs, the token and user info are stored, and sign-in completes. The no-params fallback redirect to the login page works again too.
- _Files: `frontend/auth-redirect.html`, `tests/test_auth_redirect_script.py`_
+- **Status page Edit button now opens the edit modal:** on the status page the Edit button threw a ReferenceError and the modal never opened, for owners and admins alike, because the edit form calls a serial-number helper that only exists on pages loading the main app module tree. The status page now loads just that helper module, so the modal opens. Opening it also exposed a second failure in the same flow: a warranty with an exact expiration date and no duration opened with the duration method selected and all-zero duration, which the save validation refuses, so the method detection now infers the exact-date method from zero duration plus an expiration date, matching the main page edit modal. An edit started from the status page saves through the existing endpoint and refreshes the status table afterwards. The notes modal Edit Notes button is now disabled for viewers who are neither the owner nor an admin, matching the Edit Warranty button there, because notes save through the same ownership-gated endpoint and previously failed on save.
+ - _Files: `frontend/status.html`, `frontend/script.js`, `frontend/js/components/notes.js`, `tests/test_status_edit_and_notes.py`_
## 1.0.6 - 2026-11-10
diff --git a/frontend/js/components/notes.js b/frontend/js/components/notes.js
index a69b69e..8b89098 100644
--- a/frontend/js/components/notes.js
+++ b/frontend/js/components/notes.js
@@ -296,6 +296,18 @@ export function showNotesModal(notes, warrantyOrId = null) {
refs.editWarrantyBtn.title = 'View only - not your warranty';
}
}
+ if (refs.editBtn) {
+ // Notes save through the same ownership-gated PUT, so the
+ // Edit Notes button gets the same treatment: disabled for
+ // viewers who are neither the owner nor an admin.
+ const canEdit = canEditWarranty(warranty);
+ refs.editBtn.disabled = !canEdit;
+ if (canEdit) {
+ refs.editBtn.removeAttribute('title');
+ } else {
+ refs.editBtn.title = 'View only - not your warranty';
+ }
+ }
exitEditMode();
refs.modal.classList.add('active');
}
diff --git a/frontend/script.js b/frontend/script.js
index a5b04ad..1ba6ca2 100644
--- a/frontend/script.js
+++ b/frontend/script.js
@@ -2895,7 +2895,20 @@ async function openEditModal(warranty) {
// Use the original input method if available, otherwise fall back to previous logic
if (!warranty.is_lifetime) {
- if (warranty.original_input_method === 'exact_date') {
+ // The status page passes raw API objects that never went
+ // through the list processing that computes
+ // original_input_method, so infer the exact-date method
+ // from zero duration plus an expiration date, mirroring
+ // the module edit modal. Without this, an exact-date
+ // warranty opens with the duration method selected and
+ // all-zero duration, and the legacy save validation
+ // refuses it.
+ const useExactDate = warranty.original_input_method === 'exact_date' ||
+ ((warranty.warranty_duration_years || 0) === 0 &&
+ (warranty.warranty_duration_months || 0) === 0 &&
+ (warranty.warranty_duration_days || 0) === 0 &&
+ !!warranty.expiration_date);
+ if (useExactDate) {
// Use exact date method
editExactDateMethodRadio.checked = true;
editDurationMethodRadio.checked = false;
diff --git a/frontend/status.html b/frontend/status.html
index 9e0a0d4..09ab3fb 100644
--- a/frontend/status.html
+++ b/frontend/status.html
@@ -39,6 +39,14 @@
<!-- Load fix for auth buttons -->
<script src="fix-auth-buttons-loader.js?v=20250119001"></script>
<script src="script.js?v=20261101003" defer></script> <!-- Added script.js -->
+ <!-- Serial-number inputs for the edit modal: script.js calls the
+ bare window.addSerialNumberInput, which only exists on pages
+ that load the js/index.js module tree. The status page does
+ not load that tree (it would bootstrap the dashboard), so
+ load just this import-free module; it exposes the function
+ on window itself. Without it the Edit button throws
+ ReferenceError and the modal never opens. -->
+ <script type="module" src="js/components/serialNumbers.js?v=20261119001"></script>
<style>
.user-menu {
position: relative;
diff --git a/tests/test_status_edit_and_notes.py b/tests/test_status_edit_and_notes.py
new file mode 100644
index 0000000..836ae46
--- /dev/null
+++ b/tests/test_status_edit_and_notes.py
@@ -0,0 +1,40 @@
+"""Status-page Edit and notes Edit Notes (1.0.7 adjacent fixes).
+
+Pins for the two fixes Sassan ordered before 1.0.7:
+- status.html must load the serialNumbers module, because the
+ legacy openEditModal in script.js calls the bare
+ window.addSerialNumberInput, which only exists on pages that load
+ the js/index.js module tree. Without it the Edit button throws
+ ReferenceError and the modal never opens.
+- The legacy openEditModal method detection must infer the
+ exact-date method from zero duration plus an expiration date: the
+ status page passes raw API objects that never went through the
+ list processing that computes original_input_method, so without
+ the inference an exact-date warranty opens with the duration
+ method selected and all-zero duration, and the legacy save
+ validation refuses it.
+- notes.js must disable the Edit Notes button for non-owners, the
+ same as the Edit Warranty button, because notes save through the
+ same ownership-gated PUT.
+"""
+from pathlib import Path
+
+REPO = Path(__file__).resolve().parent.parent
+
+
+def test_status_page_loads_serial_numbers_module():
+ html = (REPO / "frontend" / "status.html").read_text()
+ assert 'type="module"' in html
+ assert "js/components/serialNumbers.js" in html
+
+
+def test_legacy_edit_modal_infers_exact_date_method():
+ script = (REPO / "frontend" / "script.js").read_text()
+ assert "warranty.original_input_method === 'exact_date' ||" in script
+ assert "warranty_duration_years || 0) === 0" in script
+
+
+def test_notes_modal_disables_edit_notes_for_non_owners():
+ notes = (REPO / "frontend" / "js" / "components" / "notes.js").read_text()
+ assert "refs.editBtn.disabled = !canEdit" in notes
+ assert "refs.editBtn.title = 'View only - not your warranty'" in notes