D1 Part 1: settings-split routes + per-page data builders
- server.go: GET /storage (Tárhely page), GET /settings/notifications (GET->page, POST->save dispatch on the same path), GET /settings/security; the enrollment wizards move to /storage/init + /storage/attach with 301s from the old /settings/storage/* URLs. - handlers.go: settingsData() decomposed into settingsBaseData + systemPageData / storagePageData / notificationsPageData / securityPageData; the legacy merge remains only while the monolithic settings.html exists (Part 2 deletes it). All five storage action redirects (add/remove/default/schedulable/label) now land on /storage?storage_msg=... (incl. the two error-branch redirects). - Every page keeps rendering the full legacy template in this commit — the site stays functional; the split lands in Part 2. - Tests: four pages 200, wizard 301s + new URLs render, storage-label redirect Location prefix + flash renders on /storage, wrong-password inline re-render. Red-proven vs pre-split code (Location was /settings?..., no 301s).
This commit is contained in:
@@ -895,10 +895,19 @@ func (s *Server) backupRestoreHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/backups?flash="+msg, http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) settingsData() map[string]interface{} {
|
||||
data := s.baseData("settings", "Beállítások")
|
||||
// settingsBaseData is the shared identity block used by every settings-family subpage
|
||||
// (D1 split: /settings, /settings/notifications, /settings/security, /storage).
|
||||
func (s *Server) settingsBaseData(page, title string) map[string]interface{} {
|
||||
data := s.baseData(page, title)
|
||||
data["CustomerID"] = s.cfg.Customer.ID
|
||||
data["CustomerDomain"] = s.cfg.Customer.Domain
|
||||
return data
|
||||
}
|
||||
|
||||
// systemPageData builds the Rendszer subpage: read-only configuration, version/update,
|
||||
// controller + server restart.
|
||||
func (s *Server) systemPageData() map[string]interface{} {
|
||||
data := s.settingsBaseData("settings", "Beállítások")
|
||||
data["GitRepoURL"] = s.cfg.Git.RepoURL
|
||||
data["GitSyncInterval"] = s.cfg.Git.SyncInterval
|
||||
data["BackupEnabled"] = s.cfg.Backup.Enabled
|
||||
@@ -928,15 +937,13 @@ func (s *Server) settingsData() map[string]interface{} {
|
||||
// to. Empty = none set by the operator.
|
||||
data["ControllerFloor"] = s.updater.GetFloor()
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
data["NotificationPrefs"] = s.settings.GetNotificationPrefs()
|
||||
|
||||
// App-email (SMTP relay) — global toggle. Only meaningful when a hub is configured (the relay
|
||||
// path runs through the hub); the template hides the control otherwise.
|
||||
appEmail := s.settings.GetAppEmail()
|
||||
data["AppEmailEnabled"] = appEmail.Enabled
|
||||
data["AppEmailFromName"] = appEmail.FromName
|
||||
data["AppEmailAvailable"] = s.cfg.Hub.URL != "" && s.cfg.MailRelay.HardEnabled()
|
||||
// storagePageData builds the Tárhely page: physical drive registry, NAS shares, and the
|
||||
// data the unified agent-enriched drive view needs.
|
||||
func (s *Server) storagePageData() map[string]interface{} {
|
||||
data := s.settingsBaseData("storage", "Tárhely")
|
||||
|
||||
// Storage paths with display data
|
||||
storagePaths := s.settings.GetStoragePaths()
|
||||
@@ -983,6 +990,28 @@ func (s *Server) settingsData() map[string]interface{} {
|
||||
// NAS network storage (Part A2) — separate section with the agent's per-share health (ok/idle/
|
||||
// unreachable/unknown). Distinct from the physical-drive list above; no drive lifecycle actions.
|
||||
data["NetworkStoragePaths"] = s.networkStorageItems(context.Background())
|
||||
return data
|
||||
}
|
||||
|
||||
// notificationsPageData builds the Értesítések subpage: notification prefs + app-email.
|
||||
func (s *Server) notificationsPageData() map[string]interface{} {
|
||||
data := s.settingsBaseData("settings-notifications", "Értesítések")
|
||||
data["HubEnabled"] = s.cfg.Hub.Enabled
|
||||
data["NotificationPrefs"] = s.settings.GetNotificationPrefs()
|
||||
|
||||
// App-email (SMTP relay) — global toggle. Only meaningful when a hub is configured (the relay
|
||||
// path runs through the hub); the template hides the control otherwise.
|
||||
appEmail := s.settings.GetAppEmail()
|
||||
data["AppEmailEnabled"] = appEmail.Enabled
|
||||
data["AppEmailFromName"] = appEmail.FromName
|
||||
data["AppEmailAvailable"] = s.cfg.Hub.URL != "" && s.cfg.MailRelay.HardEnabled()
|
||||
return data
|
||||
}
|
||||
|
||||
// securityPageData builds the Biztonság és hozzáférés subpage: password, geo-restriction,
|
||||
// emergency/recovery info.
|
||||
func (s *Server) securityPageData() map[string]interface{} {
|
||||
data := s.settingsBaseData("settings-security", "Biztonság és hozzáférés")
|
||||
|
||||
// Recovery info for emergency section
|
||||
data["RetrievalPassword"] = s.settings.GetRetrievalPassword()
|
||||
@@ -1016,11 +1045,30 @@ func (s *Server) settingsData() map[string]interface{} {
|
||||
})
|
||||
}
|
||||
data["DeployedApps"] = deployedApps
|
||||
return data
|
||||
}
|
||||
|
||||
// settingsData merges every subpage builder — legacy glue kept ONLY while the monolithic
|
||||
// settings.html exists (deleted with the D1 Part 2 template split).
|
||||
func (s *Server) settingsData() map[string]interface{} {
|
||||
data := s.systemPageData()
|
||||
for _, m := range []map[string]interface{}{s.storagePageData(), s.notificationsPageData(), s.securityPageData()} {
|
||||
for k, v := range m {
|
||||
if k == "Page" || k == "Title" {
|
||||
continue
|
||||
}
|
||||
data[k] = v
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func (s *Server) settingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.executeTemplate(w, r, "settings", s.settingsData())
|
||||
}
|
||||
|
||||
// storagePageHandler serves the Tárhely main-nav page (D1). Storage action flashes land here.
|
||||
func (s *Server) storagePageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := s.settingsData()
|
||||
if msg := r.URL.Query().Get("storage_msg"); msg == "success" {
|
||||
data["StorageSuccess"] = r.URL.Query().Get("storage_detail")
|
||||
@@ -1028,6 +1076,17 @@ func (s *Server) settingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.executeTemplate(w, r, "settings", data)
|
||||
}
|
||||
|
||||
// settingsNotificationsPageHandler serves GET /settings/notifications (the POST on the same
|
||||
// path is the save handler — dispatch is split in the router).
|
||||
func (s *Server) settingsNotificationsPageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.executeTemplate(w, r, "settings", s.settingsData())
|
||||
}
|
||||
|
||||
// settingsSecurityPageHandler serves GET /settings/security.
|
||||
func (s *Server) settingsSecurityPageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.executeTemplate(w, r, "settings", s.settingsData())
|
||||
}
|
||||
|
||||
func (s *Server) settingsPasswordHandler(w http.ResponseWriter, r *http.Request) {
|
||||
_ = r.ParseForm()
|
||||
currentPassword := r.FormValue("current_password")
|
||||
@@ -1492,7 +1551,7 @@ func (s *Server) settingsStorageAddHandler(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
s.logger.Printf("[INFO] [web] Storage path added: %s (%s)", path, label)
|
||||
go s.SyncFileBrowserMounts()
|
||||
http.Redirect(w, r, "/settings?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló sikeresen hozzáadva: "+path), http.StatusFound)
|
||||
http.Redirect(w, r, "/storage?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló sikeresen hozzáadva: "+path), http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) settingsStorageRemoveHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1538,7 +1597,7 @@ func (s *Server) settingsStorageRemoveHandler(w http.ResponseWriter, r *http.Req
|
||||
s.logger.Printf("[INFO] [web] Storage path removed: %s", path)
|
||||
// Sync FileBrowser mounts after storage path removal
|
||||
go s.SyncFileBrowserMounts()
|
||||
http.Redirect(w, r, "/settings?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló eltávolítva: "+path), http.StatusFound)
|
||||
http.Redirect(w, r, "/storage?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló eltávolítva: "+path), http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) settingsStorageDefaultHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1551,11 +1610,11 @@ func (s *Server) settingsStorageDefaultHandler(w http.ResponseWriter, r *http.Re
|
||||
|
||||
if err := s.settings.SetDefaultStoragePath(path); err != nil {
|
||||
s.logger.Printf("[ERROR] [web] Failed to set default storage path: %v", err)
|
||||
http.Redirect(w, r, "/settings", http.StatusFound)
|
||||
http.Redirect(w, r, "/storage", http.StatusFound)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] [web] Default storage path set to %s", path)
|
||||
http.Redirect(w, r, "/settings?storage_msg=success&storage_detail="+url.QueryEscape("Alapértelmezett adattároló beállítva: "+path), http.StatusFound)
|
||||
http.Redirect(w, r, "/storage?storage_msg=success&storage_detail="+url.QueryEscape("Alapértelmezett adattároló beállítva: "+path), http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) settingsStorageSchedulableHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1569,11 +1628,11 @@ func (s *Server) settingsStorageSchedulableHandler(w http.ResponseWriter, r *htt
|
||||
|
||||
if err := s.settings.SetSchedulable(path, schedulable); err != nil {
|
||||
s.logger.Printf("[ERROR] [web] Failed to update schedulable: %v", err)
|
||||
http.Redirect(w, r, "/settings", http.StatusFound)
|
||||
http.Redirect(w, r, "/storage", http.StatusFound)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[INFO] [web] Storage schedulable updated: %s → %v", path, schedulable)
|
||||
http.Redirect(w, r, "/settings?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló állapot módosítva: "+path), http.StatusFound)
|
||||
http.Redirect(w, r, "/storage?storage_msg=success&storage_detail="+url.QueryEscape("Adattároló állapot módosítva: "+path), http.StatusFound)
|
||||
}
|
||||
|
||||
func (s *Server) settingsStorageLabelHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1601,7 +1660,7 @@ func (s *Server) settingsStorageLabelHandler(w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
|
||||
s.logger.Printf("[INFO] [web] Storage label updated: %s → %q", path, label)
|
||||
http.Redirect(w, r, "/settings?storage_msg=success&storage_detail="+url.QueryEscape("Megnevezés módosítva: "+label), http.StatusFound)
|
||||
http.Redirect(w, r, "/storage?storage_msg=success&storage_detail="+url.QueryEscape("Megnevezés módosítva: "+label), http.StatusFound)
|
||||
}
|
||||
|
||||
// SyncFileBrowserMounts regenerates FileBrowser's docker-compose.yml and config.yaml
|
||||
|
||||
Reference in New Issue
Block a user