summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorPaul Ivanov <pi@berkeley.edu>2017-05-21 22:54:44 -0700
committerPaul Ivanov <pi@berkeley.edu>2017-05-21 22:54:44 -0700
commit1b15bb3c1a2dc8f3a73260e4034913089d7bbcfc (patch)
treeca178b2ea9e48d01ce914a7c54c445c88b6de38c /system
parent66c3ad778ccf54566086d535a6ebe4805bf4241f (diff)
make a proper item for Hookable methods
We have all of the information, it's nice to be access the item's members in a natural way, without having to look at the reqest.
Diffstat (limited to 'system')
-rw-r--r--system/admin/handlers.go17
-rw-r--r--system/api/create.go13
2 files changed, 30 insertions, 0 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index babcff1..d579b2f 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -1926,6 +1926,23 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ // Let's be nice and make a proper item for the Hookable methods
+ dec := schema.NewDecoder()
+ dec.IgnoreUnknownKeys(true)
+ dec.SetAliasTag("json")
+ err = dec.Decode(post, req.PostForm)
+ if err != nil {
+ log.Println("Error decoding post form for edit handler:", t, err)
+ res.WriteHeader(http.StatusBadRequest)
+ errView, err := Error400()
+ if err != nil {
+ return
+ }
+
+ res.Write(errView)
+ return
+ }
+
if cid == "-1" {
err = hook.BeforeAdminCreate(res, req)
if err != nil {
diff --git a/system/api/create.go b/system/api/create.go
index 3328bd6..3b748cc 100644
--- a/system/api/create.go
+++ b/system/api/create.go
@@ -12,6 +12,8 @@ import (
"github.com/ponzu-cms/ponzu/system/admin/upload"
"github.com/ponzu-cms/ponzu/system/db"
"github.com/ponzu-cms/ponzu/system/item"
+
+ "github.com/gorilla/schema"
)
// Createable accepts or rejects external POST requests to endpoints such as:
@@ -131,6 +133,17 @@ func createContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ // Let's be nice and make a proper item for the Hookable methods
+ dec := schema.NewDecoder()
+ dec.IgnoreUnknownKeys(true)
+ dec.SetAliasTag("json")
+ err = dec.Decode(post, req.PostForm)
+ if err != nil {
+ log.Println("Error decoding post form for edit handler:", t, err)
+ res.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
err = hook.BeforeAPICreate(res, req)
if err != nil {
log.Println("[Create] error calling BeforeAccept:", err)