From c178f2e403b0b711d8aa3c0155d1368827f88afd Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Fri, 28 Oct 2016 12:58:25 -0700 Subject: adding some clean up code and UI toggle for future external vs. internal posted content --- cmd/ponzu/main.go | 6 ++++++ content/post.go | 5 ----- system/admin/handlers.go | 55 +++++++++++++++++++++++++++++++++++++++++++++--- system/db/content.go | 2 -- system/db/init.go | 18 +++++++++++----- 5 files changed, 71 insertions(+), 15 deletions(-) diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index 48aef9e..234d3b6 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -11,6 +11,7 @@ import ( "github.com/bosssauce/ponzu/system/admin" "github.com/bosssauce/ponzu/system/api" + "github.com/bosssauce/ponzu/system/api/analytics" "github.com/bosssauce/ponzu/system/db" "github.com/bosssauce/ponzu/system/tls" ) @@ -169,6 +170,11 @@ func main() { case "serve", "s": db.Init() + defer db.Close() + + analytics.Init() + defer analytics.Close() + if len(args) > 1 { services := strings.Split(args[1], ",") diff --git a/content/post.go b/content/post.go index 37ad660..dcdfeff 100644 --- a/content/post.go +++ b/content/post.go @@ -88,8 +88,3 @@ func (p *Post) SetSlug(slug string) { p.Slug = slug } // Editor partially implements editor.Editable func (p *Post) Editor() *editor.Editor { return &p.editor } - -// // Accepts accepts or recjects external requests to submit Post content -// func (p *Post) Accepts() bool { -// return true -// } diff --git a/system/admin/handlers.go b/system/admin/handlers.go index d508ef2..8cbfe0a 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -15,6 +15,7 @@ import ( "github.com/bosssauce/ponzu/management/manager" "github.com/bosssauce/ponzu/system/admin/config" "github.com/bosssauce/ponzu/system/admin/user" + "github.com/bosssauce/ponzu/system/api" "github.com/bosssauce/ponzu/system/db" "github.com/nilslice/jwt" @@ -535,7 +536,21 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { posts := db.ContentAll(t + "_sorted") b := &bytes.Buffer{} - p, ok := content.Types[t]().(editor.Editable) + + if _, ok := content.Types[t]; !ok { + res.WriteHeader(http.StatusBadRequest) + errView, err := Error405() + if err != nil { + return + } + + res.Write(errView) + return + } + + pt := content.Types[t]() + + p, ok := pt.(editor.Editable) if !ok { res.WriteHeader(http.StatusInternalServerError) errView, err := Error500() @@ -547,6 +562,12 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { return } + var hasExt bool + ext, ok := pt.(api.Externalable) + if ok { + hasExt = true + } + html := `
@@ -604,8 +625,36 @@ func postsHandler(res http.ResponseWriter, req *http.Request) {
-
-
` + if hasExt { + created := q.Get("created") + switch created { + q.Set("created", "internal") + intURL := strings.TrimPrefix(req.URL.String(), req.URL.Scheme+req.URL.Host) + + q.Set("created", "external") + extURL := strings.TrimPrefix(req.URL.String(), req.URL.Scheme+req.URL.Host) + + case "internal": + + html += `
+ Created by: + Internal +  |  + External +
` + + case "external": + html += `
+ Created by: + Internal +  |  + External +
` + } + + } + html += `