summaryrefslogtreecommitdiff
path: root/system/api/external.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2017-02-07 16:43:26 -0800
committerGitHub <noreply@github.com>2017-02-07 16:43:26 -0800
commita21c1485ec4ab973afc9a8e5dbf742d88ae32e84 (patch)
tree8a8d6beca70f2113cdebd433f80c321c9fa5d36f /system/api/external.go
parent28891b797bb24fde70df46fa2cd791af48526aae (diff)
parent7c2d4c7e609ff56541fd8787133d33d9f7951393 (diff)
Merge pull request #68 from ponzu-cms/ponzu-dev
[core] Documentation typo fixes, adding new Hookable methods: BeforeAccept & AfterAccept
Diffstat (limited to 'system/api/external.go')
-rw-r--r--system/api/external.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/system/api/external.go b/system/api/external.go
index edb730f..7f13917 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -124,14 +124,6 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
}
}
- // call Accept with the request, enabling developer to add or chack data
- // before saving to DB
- err = ext.Accept(res, req)
- if err != nil {
- log.Println("[External] error calling Accept:", err)
- return
- }
-
hook, ok := post.(item.Hookable)
if !ok {
log.Println("[External] error: Type", t, "does not implement item.Hookable or embed item.Item.")
@@ -139,6 +131,18 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ err = hook.BeforeAccept(res, req)
+ if err != nil {
+ log.Println("[External] error calling BeforeAccept:", err)
+ return
+ }
+
+ err = ext.Accept(res, req)
+ if err != nil {
+ log.Println("[External] error calling Accept:", err)
+ return
+ }
+
err = hook.BeforeSave(res, req)
if err != nil {
log.Println("[External] error calling BeforeSave:", err)
@@ -148,7 +152,10 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
// set specifier for db bucket in case content is/isn't Trustable
var spec string
- // check if the content is Trustable should be auto-approved
+ // check if the content is Trustable should be auto-approved, if so the
+ // content is immediately added to the public content API. If not, then it
+ // is added to a "pending" list, only visible to Admins in the CMS and only
+ // if the type implements editor.Mergable
trusted, ok := post.(Trustable)
if ok {
err := trusted.AutoApprove(res, req)
@@ -177,6 +184,12 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ err = hook.AfterAccept(res, req)
+ if err != nil {
+ log.Println("[External] error calling AfterAccept:", err)
+ return
+ }
+
// create JSON response to send data back to client
var data map[string]interface{}
if spec != "" {