🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Grey out Edit buttons for warranties the viewer cannot edit
Omega (QA)bb67c291375a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e5dc3b7..212818d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,8 @@- _Files: `frontend/js/controllers/warrantyListController.js`_- **Status page detail now honors global view:** with global view on, a plain user could see another user's warranty row on the status page but expanding it failed, because the detail endpoint restricted non-admins to their own warranties and ignored the global view setting, so no detail panel or Edit button appeared. The endpoint now follows the same rule as the warranty list: with global view enabled and not restricted to admins, any authenticated user may view any warranty. With global view off, or restricted to admins, non-owners are still turned away as before. Editing another user's warranty remains owner and admin only.- _Files: `backend/warranties_routes.py`, `tests/test_debug_warranty_global_view.py`_+- **Edit button greyed out for warranties you cannot edit:** now that the status page detail panel opens for another user's warranty under global view, its Edit button no longer promises an edit that fails on save. For a viewer who is neither the owner nor an admin, the button renders greyed out and disabled and does nothing on click. Owners and admins keep a working Edit button. The same disabled state applies to the Edit Warranty button in the notes modal, which opens from warranty cards. The main page cards already showed no Edit button for other users' warranties, so they are unchanged, and the server side restriction on editing is unchanged. The statistics payloads now carry the owner id for each warranty so the status page can make that decision from its cached list.+ - _Files: `frontend/status.js`, `frontend/js/components/notes.js`, `frontend/style.css`, `backend/statistics_routes.py`_## 1.0.6 - 2026-11-10diff --git a/backend/statistics_routes.py b/backend/statistics_routes.pyindex bc313c1..38f8068 100644--- a/backend/statistics_routes.py+++ b/backend/statistics_routes.py@@ -221,7 +221,7 @@ def get_statistics():logger.info(f"Fetching all warranties for user {user_id}...")cur.execute(f"""SELECT- id, product_name, purchase_date,+ id, user_id, product_name, purchase_date,warranty_duration_years, warranty_duration_months, warranty_duration_days,expiration_date, invoice_path, manual_path, other_document_path, product_url, purchase_price, is_lifetime,model_number, notes, currency, vendor, warranty_type,@@ -450,9 +450,9 @@ def get_global_statistics():# Get all warranties with user informationcur.execute("""SELECT- w.id, w.product_name, w.purchase_date,+ w.id, w.user_id, w.product_name, w.purchase_date,w.warranty_duration_years, w.warranty_duration_months, w.warranty_duration_days,- w.expiration_date, w.invoice_path, w.manual_path, w.other_document_path,+ w.expiration_date, w.invoice_path, w.manual_path, w.other_document_path,w.product_url, w.purchase_price, w.is_lifetime,u.username, u.email, u.first_name, u.last_name,w.model_number, w.notes, w.currency, w.vendor, w.warranty_type,diff --git a/frontend/js/components/notes.js b/frontend/js/components/notes.jsindex 35a051b..a69b69e 100644--- a/frontend/js/components/notes.js+++ b/frontend/js/components/notes.js@@ -38,6 +38,17 @@ function getToken() {return callIfExists(window.auth?.getToken) || localStorage.getItem('auth_token');}+// Editing is owner and admin only: the update endpoint rejects anyone+// else, so the Edit Warranty button is disabled for other viewers rather+// than promising an edit that fails on save. When ownership cannot be+// determined, keep the previous behavior.+function canEditWarranty(warranty) {+ if (!warranty || warranty.user_id === undefined || warranty.user_id === null) return true;+ const currentUser = callIfExists(window.auth?.getCurrentUser) || null;+ if (!currentUser) return true;+ return Boolean(currentUser.is_admin) || Number(warranty.user_id) === Number(currentUser.id);+}+function ensureModal() {let modal = document.getElementById('notesModal');if (!modal) {@@ -276,6 +287,15 @@ export function showNotesModal(notes, warrantyOrId = null) {if (!refs.modal) return;refs.content.textContent = contentText || '';refs.textarea.value = contentText || '';+ if (refs.editWarrantyBtn) {+ const canEdit = canEditWarranty(warranty);+ refs.editWarrantyBtn.disabled = !canEdit;+ if (canEdit) {+ refs.editWarrantyBtn.removeAttribute('title');+ } else {+ refs.editWarrantyBtn.title = 'View only - not your warranty';+ }+ }exitEditMode();refs.modal.classList.add('active');}diff --git a/frontend/status.js b/frontend/status.jsindex d97759e..08ab0cd 100644--- a/frontend/status.js+++ b/frontend/status.js@@ -228,6 +228,20 @@}}+ // Editing is owner and admin only: the update endpoint rejects anyone+ // else, so the Edit button is disabled for other viewers rather than+ // promising an edit that fails on save.+ function canEditWarranty(warrantyUserId) {+ try {+ const userInfo = JSON.parse(localStorage.getItem('user_info') || '{}');+ if (userInfo.is_admin) return true;+ return userInfo.id !== undefined && userInfo.id !== null &&+ Number(warrantyUserId) === Number(userInfo.id);+ } catch {+ return false;+ }+ }+/*** Get the appropriate localStorage key prefix based on user type* @returns {string} The prefix to use for localStorage keys@@ -571,6 +585,7 @@} else {allWarranties = recentWarrantiesData.map(warranty => ({id: warranty.id || String(Math.random()).slice(2, 11), // Ensure ID is a string for consistency+ user_id: warranty.user_id,product_name: warranty.product_name || warranty.name || 'Unknown Product',purchase_date: warranty.purchase_date,expiration_date: warranty.expiration_date,@@ -986,7 +1001,10 @@}dHtml += '</div>'; // end warranty-details-contentdHtml += '<div class="warranty-details-actions" style="margin-top: 15px; text-align: right;">';- dHtml += `<button class="btn btn-primary edit-warranty-status-btn" data-warranty-id="${warrantyDetails.id}">Edit Warranty</button></div>`;+ const canEdit = canEditWarranty(warrantyDetails.user_id);+ dHtml += canEdit+ ? `<button class="btn btn-primary edit-warranty-status-btn" data-warranty-id="${warrantyDetails.id}">Edit Warranty</button></div>`+ : `<button class="btn btn-primary edit-warranty-status-btn" data-warranty-id="${warrantyDetails.id}" disabled title="View only - not your warranty">Edit Warranty</button></div>`;detailsCell.innerHTML = dHtml;detailsRow.appendChild(detailsCell);diff --git a/frontend/style.css b/frontend/style.cssindex b3cd599..3de56e2 100644--- a/frontend/style.css+++ b/frontend/style.css@@ -26,6 +26,16 @@color: #fff !important;border-color: var(--primary-dark) !important;}+/* Greyed out when the viewer cannot edit (another user's warranty under global view) */+.edit-warranty-status-btn:disabled,+.edit-warranty-status-btn:disabled:hover,+.edit-warranty-status-btn:disabled:focus {+ background: transparent !important;+ color: var(--text-muted, #909090) !important;+ border-color: var(--text-muted, #909090) !important;+ opacity: 0.7;+ cursor: not-allowed;+}/* ===== GLOBAL STYLES ===== */:root {/* Icon spacing for LTR/RTL: applies to icons next to text */@@ -626,6 +636,12 @@ input.invalid {background-color: var(--primary-dark);}+/* Disabled buttons read as greyed out and inert, e.g. Edit actions the viewer cannot use */+.btn:disabled {+ opacity: 0.55;+ cursor: not-allowed;+}+.btn-secondary {color: var(--white);background-color: var(--secondary-color);