summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--cmd/ponzu/usage.go2
-rw-r--r--deployment/README.md4
-rw-r--r--system/api/external.go31
-rw-r--r--system/item/item.go13
5 files changed, 39 insertions, 13 deletions
diff --git a/README.md b/README.md
index 58a4fd3..963aede 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,7 @@ $ ponzu gen content review title:"string" body:"string" rating:"int" tags:"[]str
```
The command above will generate the file `content/review.go` with boilerplate
-methods, as well as struct definition, and cooresponding field tags like:
+methods, as well as struct definition, and corresponding field tags like:
```go
type Review struct {
diff --git a/cmd/ponzu/usage.go b/cmd/ponzu/usage.go
index a2f6e1c..3418cc1 100644
--- a/cmd/ponzu/usage.go
+++ b/cmd/ponzu/usage.go
@@ -66,7 +66,7 @@ generate, gen, g <generator type (,...fields)>
$ ponzu gen content review title:"string" body:"string" rating:"int" tags:"[]string"
The command above will generate a file 'content/review.go' with boilerplate
- methods, as well as struct definition, and cooresponding field tags like:
+ methods, as well as struct definition, and corresponding field tags like:
type Review struct {
Title string ` + "`json:" + `"title"` + "`" + `
diff --git a/deployment/README.md b/deployment/README.md
index d7d9a3e..7fad586 100644
--- a/deployment/README.md
+++ b/deployment/README.md
@@ -4,8 +4,8 @@ This is a set of deployment scripts for starting up `ponzu-server` processes on
system boot and run levels.
To add one for a missing platform / OS, fork the ponzu repository and create a
-new pull request with the script inside a directory named by the cooresponding
+new pull request with the script inside a directory named by the corresponding
init system.
Questions? Reach out to [@ponzu_cms](https://twitter.com/ponzu_cms) on Twitter,
-or open an issue at https://github.com/ponzu-cms/ponzu \ No newline at end of file
+or open an issue at https://github.com/ponzu-cms/ponzu
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 != "" {
diff --git a/system/item/item.go b/system/item/item.go
index e356c7c..f35d7f6 100644
--- a/system/item/item.go
+++ b/system/item/item.go
@@ -42,6 +42,9 @@ type Sortable interface {
// to the different lifecycles/events a struct may encounter. Item implements
// Hookable with no-ops so our user can override only whichever ones necessary.
type Hookable interface {
+ BeforeAccept(http.ResponseWriter, *http.Request) error
+ AfterAccept(http.ResponseWriter, *http.Request) error
+
BeforeSave(http.ResponseWriter, *http.Request) error
AfterSave(http.ResponseWriter, *http.Request) error
@@ -121,6 +124,16 @@ func (i Item) String() string {
return fmt.Sprintf("Item ID: %s", i.UniqueID())
}
+// BeforeAccept is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) BeforeAccept(res http.ResponseWriter, req *http.Request) error {
+ return nil
+}
+
+// AfterAccept is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) AfterAccept(res http.ResponseWriter, req *http.Request) error {
+ return nil
+}
+
// BeforeSave is a no-op to ensure structs which embed Item implement Hookable
func (i Item) BeforeSave(res http.ResponseWriter, req *http.Request) error {
return nil