mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-11-27 12:25:15 +00:00
Refactor the locking mechanism
This commit is contained in:
19
web/stuff.go
19
web/stuff.go
@@ -37,10 +37,6 @@ func initStuff(r *mux.Router) {
|
||||
|
||||
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
|
||||
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
||||
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
|
||||
content, err := help.Get(rq.URL.Path[6:]) // Drop /help/
|
||||
if err != nil && strings.HasPrefix(err.Error(), "open") {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
@@ -80,9 +76,6 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
||||
// handlerList shows a list of all hyphae in the wiki in random order.
|
||||
func handlerList(w http.ResponseWriter, rq *http.Request) {
|
||||
u := user.FromRequest(rq)
|
||||
if shown := u.ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
util.PrepareRq(rq)
|
||||
util.HTTP200Page(w, views.BaseHTML("List of pages", views.HyphaListHTML(), u))
|
||||
}
|
||||
@@ -90,9 +83,6 @@ func handlerList(w http.ResponseWriter, rq *http.Request) {
|
||||
// handlerReindex reindexes all hyphae by checking the wiki storage directory anew.
|
||||
func handlerReindex(w http.ResponseWriter, rq *http.Request) {
|
||||
util.PrepareRq(rq)
|
||||
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
if ok := user.CanProceed(rq, "reindex"); !ok {
|
||||
httpErr(w, http.StatusForbidden, cfg.HomeHypha, "Not enough rights", "You must be an admin to reindex hyphae.")
|
||||
log.Println("Rejected", rq.URL)
|
||||
@@ -110,9 +100,6 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) {
|
||||
// See https://mycorrhiza.wiki/hypha/configuration/header
|
||||
func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) {
|
||||
util.PrepareRq(rq)
|
||||
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
if ok := user.CanProceed(rq, "update-header-links"); !ok {
|
||||
httpErr(w, http.StatusForbidden, cfg.HomeHypha, "Not enough rights", "You must be a moderator to update header links.")
|
||||
log.Println("Rejected", rq.URL)
|
||||
@@ -125,9 +112,6 @@ func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) {
|
||||
// handlerRandom redirects to a random hypha.
|
||||
func handlerRandom(w http.ResponseWriter, rq *http.Request) {
|
||||
util.PrepareRq(rq)
|
||||
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
var (
|
||||
randomHyphaName string
|
||||
amountOfHyphae = hyphae.Count()
|
||||
@@ -149,9 +133,6 @@ func handlerRandom(w http.ResponseWriter, rq *http.Request) {
|
||||
|
||||
// handlerAbout shows a summary of wiki's software.
|
||||
func handlerAbout(w http.ResponseWriter, rq *http.Request) {
|
||||
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := io.WriteString(w, views.BaseHTML("About "+cfg.WikiName, views.AboutHTML(), user.FromRequest(rq)))
|
||||
|
||||
Reference in New Issue
Block a user