user's event save is fixed.

This commit is contained in:
2026-03-28 21:45:32 -04:00
parent 36e1be8f40
commit f4dfa6eeca
2 changed files with 11 additions and 1 deletions

View File

@@ -308,6 +308,15 @@ router.patch('/:id', authMiddleware, async (req, res) => {
const member = await queryOne(req.schema, 'SELECT 1 FROM user_group_members WHERE user_id=$1 AND user_group_id=$2', [req.user.id, ugId]);
if (!member) return res.status(403).json({ error: 'You can only assign groups you belong to' });
}
// Preserve any existing groups on this event that the user doesn't belong to
// (e.g. groups added by an admin) — silently merge them back into the submitted list
const existingGroupIds = (await query(req.schema, 'SELECT user_group_id FROM event_user_groups WHERE event_id=$1', [req.params.id])).map(r => r.user_group_id);
const submittedSet = new Set(userGroupIds.map(Number));
for (const gid of existingGroupIds) {
if (submittedSet.has(gid)) continue;
const member = await queryOne(req.schema, 'SELECT 1 FROM user_group_members WHERE user_id=$1 AND user_group_id=$2', [req.user.id, gid]);
if (!member) userGroupIds.push(gid);
}
}
}
const fields = { title, eventTypeId, startAt, endAt, allDay, location, description, isPublic, trackAvailability, recurrenceRule, origEvent: event };

View File

@@ -555,7 +555,8 @@ function EventForm({ event, userGroups, eventTypes, selectedDate, onSave, onCanc
const [desc,setDesc]=useState(event?.description||'');
const [pub,setPub]=useState(event?!!event.is_public:!!isToolManager);
const [track,setTrack]=useState(!!event?.track_availability);
const [grps,setGrps]=useState(new Set((event?.user_groups||[]).map(g=>g.id)));
const accessibleGroupIds = new Set(userGroups.map(g=>g.id));
const [grps,setGrps]=useState(new Set((event?.user_groups||[]).map(g=>g.id).filter(id=>isToolManager||accessibleGroupIds.has(id))));
const [saving,setSaving]=useState(false);
const [showTypeForm,setShowTypeForm]=useState(false);
const [localTypes,setLocalTypes]=useState(eventTypes);