fix: savePermissions preserves members; surface actual error message on failure

This commit is contained in:
James 2026-03-17 21:29:43 -04:00
parent 06ff5268ba
commit 3765adaf55
1 changed files with 21 additions and 6 deletions

View File

@ -2171,17 +2171,32 @@
? 'all'
: Array.from(document.querySelectorAll('.pm-list-check:checked')).map(cb => cb.value),
};
// Preserve existing members and other fields — only update permissions
const o = _dealOrgsMap[dealOrgId] || {};
const raw = o._raw || {};
const updatedData = {
org_id: orgId,
role: raw.role || role,
domain_lock: raw.domain_lock || false,
members: raw.members || [],
permissions: perms,
};
const btn = document.querySelector('#permModal button[onclick="savePermissions()"]');
if (btn) { btn.disabled = true; btn.textContent = 'Saving...'; }
try {
await fetchAPI('/api/projects/' + projectID + '/entries/' + dealOrgId, {
const res = await fetchAPI('/api/projects/' + projectID + '/entries/' + dealOrgId, {
method: 'PUT',
body: JSON.stringify({
data: JSON.stringify({ org_id: orgId, role, domain_lock: false, permissions: perms }),
version
})
body: JSON.stringify({ data: JSON.stringify(updatedData), version })
});
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Save failed (' + res.status + ')');
closePermModal();
loadOrgs();
} catch(e) { alert('Failed to save permissions'); }
} catch(e) {
alert('Failed to save permissions: ' + e.message);
} finally {
if (btn) { btn.disabled = false; btn.textContent = 'Save'; }
}
}
function openPermissionsTemplateModal() {