summaryrefslogtreecommitdiff
path: root/system/api/external.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-11-16 02:51:26 -0800
committerGitHub <noreply@github.com>2016-11-16 02:51:26 -0800
commitf252472047f86d1bdf956dc59b89541ea0260d68 (patch)
tree6c0d5938c21505325ad50446f5ebcd1483d6b278 /system/api/external.go
parent9a531ac701990bb932664039b11614227467e03a (diff)
parent6f5893828077eb0034dca01344f3742eb5cd5fa6 (diff)
Merge pull request #17 from bosssauce/ponzu-dev
[core] Adding lifecycle hooks for Save, Delete, Approve, Reject
Diffstat (limited to 'system/api/external.go')
-rw-r--r--system/api/external.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/system/api/external.go b/system/api/external.go
index c9fb2a7..5c50172 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -19,14 +19,6 @@ type Externalable interface {
Accepts() bool
}
-// Mergeable allows external post content to be approved and published through
-// the public-facing API
-type Mergeable interface {
- // Approve copies an external post to the internal collection and triggers
- // a re-sort of its content type posts
- Approve(req *http.Request) error
-}
-
func externalPostHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost {
res.WriteHeader(http.StatusMethodNotAllowed)
@@ -99,11 +91,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
+ }
}
}