This commit is contained in:
1 parent
fc24ae2f60
commit
20e9461d46
1 file changed
+15
-5
@@ -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
|
||||||
|
|||||||
Reference in new issue
Block a user