From 3131937af204be4e4663a0f33bab8edd5945d07f Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Wed, 9 Sep 2026 22:24:03 +0200 Subject: [PATCH] Add mediaauth.Service.SetLoginRequired for cross-service login pushes Lets a trusted internal caller (ProjectConfigurator's central "Require Login" toggle) set a service's auth_required flag directly, without an admin session - UpdateAccessSettings now delegates to it too. Co-Authored-By: Claude Sonnet 5 --- backend/mediaauth/auth.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/mediaauth/auth.go b/backend/mediaauth/auth.go index aeb095e..76d3504 100644 --- a/backend/mediaauth/auth.go +++ b/backend/mediaauth/auth.go @@ -531,17 +531,27 @@ func (s *Service) UpdateAccessSettings(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusBadRequest, "loginRequired must be a boolean") return } - if _, err := s.db.Exec(r.Context(), ` - INSERT INTO settings (key, value, updated_at) - VALUES ($1, $2, NOW()) - ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW() - `, loginRequiredSettingKey, strconv.FormatBool(*input.LoginRequired)); err != nil { + if err := s.SetLoginRequired(r.Context(), *input.LoginRequired); err != nil { writeError(w, http.StatusInternalServerError, "access setting could not be saved") return } writeJSON(w, http.StatusOK, map[string]bool{"loginRequired": *input.LoginRequired}) } +// SetLoginRequired writes the auth_required flag directly, the same one UpdateAccessSettings +// exposes to a manager-authenticated session - callers reach this from an X-Internal-Auth-gated +// route instead (see each service's own setLoginRequiredInternal), letting ProjectConfigurator's +// central "Require Login" toggle (ConfigWorkspace.svelte's loginControls) apply here without an +// admin session of its own. +func (s *Service) SetLoginRequired(ctx context.Context, required bool) error { + _, err := s.db.Exec(ctx, ` + INSERT INTO settings (key, value, updated_at) + VALUES ($1, $2, NOW()) + ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW() + `, loginRequiredSettingKey, strconv.FormatBool(required)) + return err +} + func (s *Service) Status(w http.ResponseWriter, r *http.Request) { if !s.enabled() { user := localProfile