From 1b15bb3c1a2dc8f3a73260e4034913089d7bbcfc Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Sun, 21 May 2017 22:54:44 -0700 Subject: 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. --- system/admin/handlers.go | 17 +++++++++++++++++ system/api/create.go | 13 +++++++++++++ 2 files changed, 30 insertions(+) (limited to 'system') 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) -- cgit v1.2.3