From 516fd29da423432ef6dfded21a984f1d15dcab1a Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 5 Oct 2026 17:31:50 -0400 Subject: fix: slop casino and economy fixes --- internal/admin/api_room_courses.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'internal/admin/api_room_courses.go') diff --git a/internal/admin/api_room_courses.go b/internal/admin/api_room_courses.go index db74adf..099ebef 100644 --- a/internal/admin/api_room_courses.go +++ b/internal/admin/api_room_courses.go @@ -420,8 +420,9 @@ func (s *AdminServer) handleRoomAttachCourse(w http.ResponseWriter, r *http.Requ // Detach a room from its course; delete the course file if it becomes empty -// detachRoomFromCourse removes roomID from the course it belongs to, if any. -// Returns the course ID that was modified, or "" if none match. +// detachRoomFromCourse removes roomID from every course it belongs to, if any. +// Returns the first affected course ID (or "" if none match) and whether any +// course was deleted. func (s *AdminServer) detachRoomFromCourse(roomID int) (courseID string, deleted bool) { ids, err := s.listCourseIDs() if err != nil { @@ -448,15 +449,23 @@ func (s *AdminServer) detachRoomFromCourse(roomID int) (courseID string, deleted remaining = append(remaining, obstacles[idx+1:]...) if len(remaining) == 0 { - os.Remove(path) + // A failed unlink must not be reported as a detach: the course + // would keep listing a deleted room. + if err := os.Remove(path); err != nil { + continue + } s.undoStack.Push(ChangeDesc{ Description: fmt.Sprintf("delete course %s (last obstacle removed)", id), FilePath: path, OldContent: oldContent, IsDelete: true, }) + if courseID == "" { + courseID = id + } + deleted = true s.reloadCoursesIfWired() - return id, true + continue } anyList := make([]any, len(remaining)) @@ -466,7 +475,7 @@ func (s *AdminServer) detachRoomFromCourse(roomID int) (courseID string, deleted m["obstacles"] = anyList newContent, err := writeMapAsYAML(path, m) if err != nil { - return "", false + continue } s.undoStack.Push(ChangeDesc{ Description: fmt.Sprintf("detach room %d from course %s", roomID, id), @@ -474,10 +483,12 @@ func (s *AdminServer) detachRoomFromCourse(roomID int) (courseID string, deleted OldContent: oldContent, NewContent: newContent, }) + if courseID == "" { + courseID = id + } s.reloadCoursesIfWired() - return id, false } - return "", false + return courseID, deleted } func (s *AdminServer) handleRoomDetachCourse(w http.ResponseWriter, r *http.Request, roomID int) { -- cgit v1.2.3