From f5f12f50f571cb9bfc7517c25c3558acc1f0e57e Mon Sep 17 00:00:00 2001 From: elpatron Date: Sat, 30 May 2026 14:04:43 +0200 Subject: [PATCH] fix(sync): READ-Zugriff darf Sync-Queue nicht als erfolgreich leeren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bei READ-only oder unbekannter Rolle gibt pushChanges false zurück, solange noch Einträge in der Queue sind, damit lokale Änderungen nicht verloren gehen. Co-authored-by: Cursor --- client/src/services/sync.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/client/src/services/sync.ts b/client/src/services/sync.ts index 9690dd1..9d3f14b 100644 --- a/client/src/services/sync.ts +++ b/client/src/services/sync.ts @@ -126,16 +126,36 @@ function scheduleResync(logbookId: string) { }) } +type LogbookPushAccess = 'OWNER' | 'WRITE' | 'READ' | 'UNKNOWN' + +async function resolveLogbookPushAccess(logbookId: string): Promise { + const access = await getLogbookAccess(logbookId) + if (access) { + return access.isOwner || access.role === 'OWNER' ? 'OWNER' : access.role + } + + const local = await db.logbooks.get(logbookId) + if (local?.isShared !== 1) return 'OWNER' + if (local.collaborationRole === 'READ') return 'READ' + if (local.collaborationRole === 'WRITE') return 'WRITE' + return 'UNKNOWN' +} + // Push local sync queue items to the server async function pushChanges(logbookId: string): Promise { if (!getActiveMasterKey() || !localStorage.getItem('active_userid')) return false - const access = await getLogbookAccess(logbookId) - if (access && access.role === 'READ') return true - const pending = await coalesceSyncQueue(logbookId) if (pending.length === 0) return true + const pushAccess = await resolveLogbookPushAccess(logbookId) + if (pushAccess === 'READ' || pushAccess === 'UNKNOWN') { + console.warn( + `[sync] Skipping push for logbook ${logbookId} (${pushAccess}); ${pending.length} queue item(s) retained` + ) + return false + } + try { const response = await apiFetch(`${API_BASE}/push`, { method: 'POST',