1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-11-19 00:25:20 +00:00

Make the lock work

There is a new config field: Authorization.Locked.

I am a little bit sorry for how actually the lock is implemented. I've added the check on almost every handler there is. Good luck maintaining that ❤️
This commit is contained in:
Timur Ismagilov
2021-07-11 00:04:21 +05:00
parent d8f4f40f52
commit 5d45ae67d4
9 changed files with 123 additions and 26 deletions

View File

@@ -42,6 +42,9 @@ func factoryHandlerAsker(
h = hyphae.ByName(hyphaName)
u = user.FromRequest(rq)
)
if shown := u.ShowLockMaybe(w, rq); shown {
return
}
if err, errtitle := asker(u, h); err != nil {
httpErr(
w,
@@ -92,6 +95,9 @@ func factoryHandlerConfirmer(
h = hyphae.ByName(hyphaName)
u = user.FromRequest(rq)
)
if shown := u.ShowLockMaybe(w, rq); shown {
return
}
if hop, errtitle := confirmer(h, u, rq); hop.HasErrors() {
httpErr(w, http.StatusInternalServerError, hyphaName,
errtitle,
@@ -139,6 +145,9 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
err error
u = user.FromRequest(rq)
)
if shown := u.ShowLockMaybe(w, rq); shown {
return
}
if err, errtitle := shroom.CanEdit(u, h); err != nil {
httpErr(w, http.StatusInternalServerError, hyphaName,
errtitle,
@@ -178,6 +187,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
hop *history.HistoryOp
errtitle string
)
if shown := u.ShowLockMaybe(w, rq); shown {
return
}
if action != "Preview" {
hop, errtitle = shroom.UploadText(h, []byte(textData), message, u)
@@ -219,6 +231,9 @@ func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) {
u = user.FromRequest(rq)
file, handler, err = rq.FormFile("binary")
)
if shown := u.ShowLockMaybe(w, rq); shown {
return
}
if err != nil {
httpErr(w, http.StatusInternalServerError, hyphaName,
"Error",