Add district settings management
This commit is contained in:
1 parent
8a2ac56844
commit
b37427535c
5 files changed
+627
-2
No files matched your search
@@ -283,6 +283,70 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
case "district-create":
|
||||
|
||||
err = s.store.CreateDistrict(
|
||||
r.FormValue("district_name"),
|
||||
r.FormValue("district_title"),
|
||||
r.FormValue("district_domain"),
|
||||
r.FormValue("district_enabled") == "1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
case "district-update":
|
||||
|
||||
id, parseErr :=
|
||||
strconv.ParseInt(
|
||||
r.FormValue("district_id"),
|
||||
10,
|
||||
64,
|
||||
)
|
||||
|
||||
if parseErr != nil {
|
||||
http.Error(w, "invalid district id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.store.UpdateDistrict(
|
||||
id,
|
||||
r.FormValue("district_name"),
|
||||
r.FormValue("district_title"),
|
||||
r.FormValue("district_domain"),
|
||||
r.FormValue("district_enabled") == "1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
case "district-delete":
|
||||
|
||||
id, parseErr :=
|
||||
strconv.ParseInt(
|
||||
r.FormValue("district_id"),
|
||||
10,
|
||||
64,
|
||||
)
|
||||
|
||||
if parseErr != nil {
|
||||
http.Error(w, "invalid district id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.store.DeleteDistrict(
|
||||
id,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
case "zombie-purge":
|
||||
|
||||
_, err = s.store.PurgeZombieObjects(
|
||||
@@ -312,6 +376,10 @@ func (s *Server) handleConfig(
|
||||
panel = "objects"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(section, "district-") {
|
||||
panel = "districts"
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w,
|
||||
r,
|
||||
@@ -369,6 +437,14 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
districts, err :=
|
||||
s.store.ListDistricts()
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
s.renderWithContext(
|
||||
w,
|
||||
r,
|
||||
@@ -390,6 +466,7 @@ func (s *Server) handleConfig(
|
||||
"ZombieGraceHours": zombieGraceHours,
|
||||
"Objects": recent,
|
||||
"ZombieObjects": zombies,
|
||||
"Districts": districts,
|
||||
"HomeNavItemsConfig": s.getHomeNavItems(),
|
||||
"SystemNavItemsConfig": s.getSystemNavItems(),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package server
|
||||
|
||||
import "pageswiki/internal/store"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func (s *Server) currentDistrict() *store.District {
|
||||
|
||||
@@ -18,3 +22,23 @@ func (s *Server) currentDistrict() *store.District {
|
||||
|
||||
return sp
|
||||
}
|
||||
|
||||
func (s *Server) districtForRequest(
|
||||
r *http.Request,
|
||||
) *store.District {
|
||||
|
||||
if r == nil {
|
||||
return s.currentDistrict()
|
||||
}
|
||||
|
||||
sp, err :=
|
||||
s.store.GetDistrictByHost(
|
||||
r.Host,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return s.currentDistrict()
|
||||
}
|
||||
|
||||
return sp
|
||||
}
|
||||
@@ -15,7 +15,9 @@ func (s *Server) BuildRequestContext(
|
||||
) *RequestContext {
|
||||
|
||||
return &RequestContext{
|
||||
District: s.currentDistrict(),
|
||||
District: s.districtForRequest(
|
||||
r,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user