Update assignment dates and remove assignment with tableUrl and RBAC che
1 file changed+21−7
index.html+21−7View file
| @@ -3898,6 +3898,10 @@ | ||
| // Modal: Edit Assignment Dates | ||
| function openEditAssignmentModal(assignmentId) { | ||
| + if (!currentUser || currentUser.role !== 'admin') { | ||
| + showToast('Access Denied', 'Administrator permissions required.', 'error'); | ||
| + return; | ||
| + } | ||
| const a = state.assignments.find(x => x._id === assignmentId); | ||
| if (!a) return; | ||
| @@ -3916,6 +3920,10 @@ | ||
| async function handleUpdateAssignmentDates(e) { | ||
| e.preventDefault(); | ||
| + if (!currentUser || currentUser.role !== 'admin') { | ||
| + showToast('Access Denied', 'Administrator permissions required.', 'error'); | ||
| + return; | ||
| + } | ||
| const aId = document.getElementById('edit-assignment-id').value; | ||
| const a = state.assignments.find(x => x._id === aId); | ||
| if (!a) return; | ||
| @@ -3933,23 +3941,29 @@ | ||
| if (!isTempId(aId)) { | ||
| try { | ||
| - const res = await apiFetch(`/api/assignments/${aId}`, { | ||
| + const res = await apiFetch(tableUrl('assignments', aId), { | ||
| method: 'PATCH', | ||
| body: JSON.stringify(updateData) | ||
| }); | ||
| if (res.ok) { | ||
| - const serverData = await res.json(); | ||
| - Object.assign(a, serverData); | ||
| - saveStore(); | ||
| + const serverData = unwrapRow(await res.json()); | ||
| + if (serverData) { | ||
| + Object.assign(a, serverData); | ||
| + saveStore(); | ||
| + } | ||
| } | ||
| } catch (err) { | ||
| - console.warn('PATCH /api/assignments/:id failed, maintained locally:', err); | ||
| + console.warn('PATCH assignments/:id failed, maintained locally:', err); | ||
| } | ||
| } | ||
| showToast('Dates Updated', `Contract dates adjusted for ${a.freelanceName}.`, 'success'); | ||
| } | ||
| async function removeAssignment(assignmentId) { | ||
| + if (!currentUser || currentUser.role !== 'admin') { | ||
| + showToast('Access Denied', 'Administrator permissions required.', 'error'); | ||
| + return; | ||
| + } | ||
| const a = state.assignments.find(x => x._id === assignmentId); | ||
| if (!a) return; | ||
| if (!confirm(`Are you sure you want to remove ${a.freelanceName} from ${a.projectName}?`)) return; | ||
| @@ -3960,11 +3974,11 @@ | ||
| if (!isTempId(assignmentId)) { | ||
| try { | ||
| - await apiFetch(`/api/assignments/${assignmentId}`, { | ||
| + await apiFetch(tableUrl('assignments', assignmentId), { | ||
| method: 'DELETE' | ||
| }); | ||
| } catch (err) { | ||
| - console.warn('DELETE /api/assignments/:id failed, removed locally:', err); | ||
| + console.warn('DELETE assignments/:id failed, removed locally:', err); | ||
| } | ||
| } | ||
| showToast('Assignment Removed', `${a.freelanceName} has been unassigned.`, 'info'); | ||