user's event save is fixed.
This commit is contained in:
@@ -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]);
|
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' });
|
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 };
|
const fields = { title, eventTypeId, startAt, endAt, allDay, location, description, isPublic, trackAvailability, recurrenceRule, origEvent: event };
|
||||||
|
|||||||
@@ -555,7 +555,8 @@ function EventForm({ event, userGroups, eventTypes, selectedDate, onSave, onCanc
|
|||||||
const [desc,setDesc]=useState(event?.description||'');
|
const [desc,setDesc]=useState(event?.description||'');
|
||||||
const [pub,setPub]=useState(event?!!event.is_public:!!isToolManager);
|
const [pub,setPub]=useState(event?!!event.is_public:!!isToolManager);
|
||||||
const [track,setTrack]=useState(!!event?.track_availability);
|
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 [saving,setSaving]=useState(false);
|
||||||
const [showTypeForm,setShowTypeForm]=useState(false);
|
const [showTypeForm,setShowTypeForm]=useState(false);
|
||||||
const [localTypes,setLocalTypes]=useState(eventTypes);
|
const [localTypes,setLocalTypes]=useState(eventTypes);
|
||||||
|
|||||||
Reference in New Issue
Block a user