mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-07-05 03:02:48 +00:00
Do not let mutate pages without rights for doing so
This commit is contained in:
parent
4686b79226
commit
cfdc7b82ae
@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/templates"
|
"github.com/bouncepaw/mycorrhiza/templates"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,6 +26,11 @@ func handlerRenameAsk(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaName = HyphaNameFromRq(rq, "rename-ask")
|
hyphaName = HyphaNameFromRq(rq, "rename-ask")
|
||||||
_, isOld = HyphaStorage[hyphaName]
|
_, isOld = HyphaStorage[hyphaName]
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "rename-confirm"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be a trusted editor to rename pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
util.HTTP200Page(w, base("Rename "+hyphaName+"?", templates.RenameAskHTML(hyphaName, isOld)))
|
util.HTTP200Page(w, base("Rename "+hyphaName+"?", templates.RenameAskHTML(hyphaName, isOld)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +43,11 @@ func handlerRenameConfirm(w http.ResponseWriter, rq *http.Request) {
|
|||||||
_, newNameIsUsed = HyphaStorage[newName]
|
_, newNameIsUsed = HyphaStorage[newName]
|
||||||
recursive bool
|
recursive bool
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "rename-confirm"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be a trusted editor to rename pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
if rq.PostFormValue("recursive") == "true" {
|
if rq.PostFormValue("recursive") == "true" {
|
||||||
recursive = true
|
recursive = true
|
||||||
}
|
}
|
||||||
@ -71,6 +82,11 @@ func handlerDeleteAsk(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaName = HyphaNameFromRq(rq, "delete-ask")
|
hyphaName = HyphaNameFromRq(rq, "delete-ask")
|
||||||
_, isOld = HyphaStorage[hyphaName]
|
_, isOld = HyphaStorage[hyphaName]
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "delete-ask"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be a moderator to delete pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
util.HTTP200Page(w, base("Delete "+hyphaName+"?", templates.DeleteAskHTML(hyphaName, isOld)))
|
util.HTTP200Page(w, base("Delete "+hyphaName+"?", templates.DeleteAskHTML(hyphaName, isOld)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +97,11 @@ func handlerDeleteConfirm(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaName = HyphaNameFromRq(rq, "delete-confirm")
|
hyphaName = HyphaNameFromRq(rq, "delete-confirm")
|
||||||
hyphaData, isOld = HyphaStorage[hyphaName]
|
hyphaData, isOld = HyphaStorage[hyphaName]
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "delete-confirm"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be a moderator to delete pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
if isOld {
|
if isOld {
|
||||||
// If deleted successfully
|
// If deleted successfully
|
||||||
if hop := hyphaData.DeleteHypha(hyphaName); len(hop.Errs) == 0 {
|
if hop := hyphaData.DeleteHypha(hyphaName); len(hop.Errs) == 0 {
|
||||||
@ -108,6 +129,11 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
|
|||||||
textAreaFill string
|
textAreaFill string
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "edit"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be an editor to edit pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
if isOld {
|
if isOld {
|
||||||
textAreaFill, err = FetchTextPart(hyphaData)
|
textAreaFill, err = FetchTextPart(hyphaData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -129,6 +155,11 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaData, isOld = HyphaStorage[hyphaName]
|
hyphaData, isOld = HyphaStorage[hyphaName]
|
||||||
textData = rq.PostFormValue("text")
|
textData = rq.PostFormValue("text")
|
||||||
)
|
)
|
||||||
|
if ok := user.CanProceed(rq, "upload-text"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be an editor to edit pages.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
if !isOld {
|
if !isOld {
|
||||||
hyphaData = &HyphaData{}
|
hyphaData = &HyphaData{}
|
||||||
}
|
}
|
||||||
@ -147,6 +178,11 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
|||||||
func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) {
|
func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) {
|
||||||
log.Println(rq.URL)
|
log.Println(rq.URL)
|
||||||
hyphaName := HyphaNameFromRq(rq, "upload-binary")
|
hyphaName := HyphaNameFromRq(rq, "upload-binary")
|
||||||
|
if ok := user.CanProceed(rq, "upload-binary"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, hyphaName, "Not enough rights", "You must be an editor to upload attachments.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
rq.ParseMultipartForm(10 << 20)
|
rq.ParseMultipartForm(10 << 20)
|
||||||
|
|
||||||
file, handler, err := rq.FormFile("binary")
|
file, handler, err := rq.FormFile("binary")
|
||||||
|
6
main.go
6
main.go
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/templates"
|
"github.com/bouncepaw/mycorrhiza/templates"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,6 +64,11 @@ var base = templates.BaseHTML
|
|||||||
// Reindex all hyphae by checking the wiki storage directory anew.
|
// Reindex all hyphae by checking the wiki storage directory anew.
|
||||||
func handlerReindex(w http.ResponseWriter, rq *http.Request) {
|
func handlerReindex(w http.ResponseWriter, rq *http.Request) {
|
||||||
log.Println(rq.URL)
|
log.Println(rq.URL)
|
||||||
|
if ok := user.CanProceed(rq, "reindex"); !ok {
|
||||||
|
HttpErr(w, http.StatusForbidden, util.HomePage, "Not enough rights", "You must be an admin to reindex hyphae.")
|
||||||
|
log.Println("Rejected", rq.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
HyphaStorage = make(map[string]*HyphaData)
|
HyphaStorage = make(map[string]*HyphaData)
|
||||||
log.Println("Wiki storage directory is", WikiDir)
|
log.Println("Wiki storage directory is", WikiDir)
|
||||||
log.Println("Start indexing hyphae...")
|
log.Println("Start indexing hyphae...")
|
||||||
|
@ -2,6 +2,7 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func groupFromString(s string) UserGroup {
|
func groupFromString(s string) UserGroup {
|
||||||
@ -59,3 +60,11 @@ func (ug UserGroup) CanAccessRoute(route string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CanProceed(rq *http.Request, route string) bool {
|
||||||
|
ug := UserAnon
|
||||||
|
if u := FromRequest(rq); u != nil {
|
||||||
|
ug = u.Group
|
||||||
|
}
|
||||||
|
return ug.CanAccessRoute(route)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user