prepare frontend for different WireGuard backends (#426)

This commit is contained in:
Christoph Haas
2025-05-18 19:49:31 +02:00
parent 7fd2bbad02
commit 33dcc80078
17 changed files with 154 additions and 27 deletions

View File

@@ -96,10 +96,29 @@ func (e ConfigEndpoint) handleSettingsGet() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sessionUser := domain.GetUserInfo(r.Context())
nameFn := func(backend config.Backend) []model.SettingsBackendNames {
names := make([]model.SettingsBackendNames, 0, len(backend.Mikrotik)+1)
names = append(names, model.SettingsBackendNames{
Id: backend.Default,
Name: "modals.interface-edit.backend.local",
})
for _, b := range backend.Mikrotik {
names = append(names, model.SettingsBackendNames{
Id: b.Id,
Name: b.DisplayName,
})
}
return names
}
// For anonymous users, we return the settings object with minimal information
if sessionUser.Id == domain.CtxUnknownUserId || sessionUser.Id == "" {
respond.JSON(w, http.StatusOK, model.Settings{
WebAuthnEnabled: e.cfg.Auth.WebAuthn.Enabled,
WebAuthnEnabled: e.cfg.Auth.WebAuthn.Enabled,
AvailableBackends: []model.SettingsBackendNames{}, // return an empty list instead of null
})
} else {
respond.JSON(w, http.StatusOK, model.Settings{
@@ -109,6 +128,7 @@ func (e ConfigEndpoint) handleSettingsGet() http.HandlerFunc {
ApiAdminOnly: e.cfg.Advanced.ApiAdminOnly,
WebAuthnEnabled: e.cfg.Auth.WebAuthn.Enabled,
MinPasswordLength: e.cfg.Auth.MinPasswordLength,
AvailableBackends: nameFn(e.cfg.Backend),
})
}
}