Update openAddAssignmentModal and handleSaveAssignment

Ryan Danenberg committed commit3fcce4004aeeb9cf8566cfe74acb58bf19539c17 Browse files
1 file changed+11−3
index.html+11−3View file
@@ -3821,6 +3821,10 @@
// Modal: Add Assignment
function openAddAssignmentModal(projectId, projectName) {
+ if (!currentUser || currentUser.role !== 'admin') {
+ showToast('Access Denied', 'Administrator permissions required.', 'error');
+ return;
+ }
document.getElementById('assign-project-id').value = projectId;
document.getElementById('modal-assign-project-name').textContent = projectName;
document.getElementById('assign-freelance-name').value = '';
@@ -3837,6 +3841,10 @@
async function handleSaveAssignment(e) {
e.preventDefault();
+ if (!currentUser || currentUser.role !== 'admin') {
+ showToast('Access Denied', 'Administrator permissions required.', 'error');
+ return;
+ }
const projectId = document.getElementById('assign-project-id').value;
const project = state.projects.find(p => p._id === projectId);
const name = document.getElementById('assign-freelance-name').value.trim();
@@ -3859,15 +3867,15 @@
let newAssignment = null;
try {
- const res = await apiFetch('/api/assignments', {
+ const res = await apiFetch(tableUrl('assignments'), {
method: 'POST',
body: JSON.stringify(payload)
});
if (res.ok) {
- newAssignment = await res.json();
+ newAssignment = unwrapRow(await res.json());
}
} catch (err) {
- console.warn('POST /api/assignments failed, fallback to local store:', err);
+ console.warn('POST assignments failed, fallback to local store:', err);
}
if (!newAssignment || !newAssignment._id) {