summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-11-08 17:01:53 -0800
committerSteve Manuel <nilslice@gmail.com>2016-11-08 17:01:53 -0800
commit7fc144bee449641fb7d135cd6fdf59c8f5869a80 (patch)
treeba5a51c110973a12dc392c60860908cebaedd4e8
parentdfa5e33f99f8727d36420981156c1ba8400b17b8 (diff)
adding remaining methods to Item for Hookable implementation and adding hooks to external submissions
-rw-r--r--content/item.go10
-rw-r--r--system/api/external.go21
2 files changed, 31 insertions, 0 deletions
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
+ }
}
}