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 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-09 22:24:03 +02:00
1 parent 8d7d6ee35b
commit 3131937af2
1 file changed
+15 -5
+15 -5
View File
@@ -531,17 +531,27 @@ func (s *Service) UpdateAccessSettings(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "loginRequired must be a boolean") writeError(w, http.StatusBadRequest, "loginRequired must be a boolean")
return return
} }
if _, err := s.db.Exec(r.Context(), ` if err := s.SetLoginRequired(r.Context(), *input.LoginRequired); err != nil {
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 {
writeError(w, http.StatusInternalServerError, "access setting could not be saved") writeError(w, http.StatusInternalServerError, "access setting could not be saved")
return return
} }
writeJSON(w, http.StatusOK, map[string]bool{"loginRequired": *input.LoginRequired}) 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) { func (s *Service) Status(w http.ResponseWriter, r *http.Request) {
if !s.enabled() { if !s.enabled() {
user := localProfile user := localProfile