From 7fc144bee449641fb7d135cd6fdf59c8f5869a80 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 8 Nov 2016 17:01:53 -0800 Subject: adding remaining methods to Item for Hookable implementation and adding hooks to external submissions --- content/item.go | 10 ++++++++++ system/api/external.go | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/content/item.go b/content/item.go index 046ed04..cbf38af 100644 --- a/content/item.go +++ b/content/item.go @@ -55,6 +55,16 @@ func (i *Item) AfterDelete(req *http.Request) error { return nil } +// BeforeReject is a no-op to ensure structs which embed Item implement Hookable +func (i *Item) BeforeReject(req *http.Request) error { + return nil +} + +// AfterReject is a no-op to ensure structs which embed Item implement Hookable +func (i *Item) AfterReject(req *http.Request) error { + return nil +} + // Sluggable makes a struct locatable by URL with it's own path // As an Item implementing Sluggable, slugs may overlap. If this is an issue, // make your content struct (or one which imbeds Item) implement Sluggable diff --git a/system/api/external.go b/system/api/external.go index c9fb2a7..7eade92 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -99,11 +99,32 @@ func externalPostHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Del(discardKey) } + hook, ok := post.(content.Hookable) + if !ok { + log.Println("[External] error: Type", t, "does not implement content.Hookable or embed content.Item.") + res.WriteHeader(http.StatusBadRequest) + return + } + + err = hook.BeforeSave(req) + if err != nil { + log.Println("[External] error:", err) + res.WriteHeader(http.StatusInternalServerError) + return + } + _, err = db.SetContent(t+"_pending:-1", req.PostForm) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) return } + + err = hook.AfterSave(req) + if err != nil { + log.Println("[External] error:", err) + res.WriteHeader(http.StatusInternalServerError) + return + } } } -- cgit v1.2.3