Skip to content

Commit eb475e8

Browse files
Add visibility + role-based access fields with validation for events
1 parent a05049b commit eb475e8

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

pkg/handlers/event.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ func UpdateEventByID(c *gin.Context) {
170170
return
171171
}
172172

173+
// Validate patch fields for #36 visibility/status support
174+
if err := event.ValidateUpdateFields(fields); err != nil {
175+
c.JSON(http.StatusBadRequest, gin.H{
176+
"error": err.Error(),
177+
})
178+
return
179+
}
180+
181+
// Normalize public events: if visibility is being set to public in PATCH,
182+
// clear minimum_visible_role automatically.
183+
if visibilityRaw, ok := fields["visibility"]; ok {
184+
if visibility, ok := visibilityRaw.(string); ok && strings.TrimSpace(visibility) == event.VisibilityPublic {
185+
fields["minimum_visible_role"] = ""
186+
}
187+
}
188+
173189
err = db.UpdateEventByID(id, fields)
174190
if err != nil {
175191
if err == mongo.ErrNoDocuments {

0 commit comments

Comments
 (0)