diff --git a/pad.go b/pad.go index 017b8e4..8391ff0 100644 --- a/pad.go +++ b/pad.go @@ -124,7 +124,12 @@ func handleViewMeta(app *app, w http.ResponseWriter, r *http.Request) error { // TODO: add ErrForbiddenEditPost message to flashes return impart.HTTPError{http.StatusFound, r.URL.Path[:strings.LastIndex(r.URL.Path, "/meta")]} } - appData.EditCollection, err = app.db.GetCollectionForPad(collAlias) + if app.cfg.App.SingleUser { + // TODO: optimize this query just like we do in GetCollectionForPad (?) + appData.EditCollection, err = app.db.GetCollectionByID(1) + } else { + appData.EditCollection, err = app.db.GetCollectionForPad(collAlias) + } if err != nil { return err } diff --git a/posts.go b/posts.go index 205e2ad..e016ace 100644 --- a/posts.go +++ b/posts.go @@ -681,7 +681,11 @@ func existingPost(app *app, w http.ResponseWriter, r *http.Request) error { collectionAlias := vars["alias"] redirect := "/" + postID + "/meta" if collectionAlias != "" { - redirect = "/" + collectionAlias + "/" + pRes.Slug.String + "/edit/meta" + collPre := "/" + collectionAlias + if app.cfg.App.SingleUser { + collPre = "" + } + redirect = collPre + "/" + pRes.Slug.String + "/edit/meta" } w.Header().Set("Location", redirect) w.WriteHeader(http.StatusFound) @@ -1131,8 +1135,13 @@ func getRawCollectionPost(app *app, slug, collAlias string) *RawPost { var created time.Time var ownerID null.Int var views int64 + var err error - err := app.db.QueryRow("SELECT id, title, content, text_appearance, language, rtl, view_count, created, owner_id FROM posts WHERE slug = ? AND collection_id = (SELECT id FROM collections WHERE alias = ?)", slug, collAlias).Scan(&id, &title, &content, &font, &lang, &isRTL, &views, &created, &ownerID) + if app.cfg.App.SingleUser { + err = app.db.QueryRow("SELECT id, title, content, text_appearance, language, rtl, view_count, created, owner_id FROM posts WHERE slug = ? AND collection_id = 1", slug).Scan(&id, &title, &content, &font, &lang, &isRTL, &views, &created, &ownerID) + } else { + err = app.db.QueryRow("SELECT id, title, content, text_appearance, language, rtl, view_count, created, owner_id FROM posts WHERE slug = ? AND collection_id = (SELECT id FROM collections WHERE alias = ?)", slug, collAlias).Scan(&id, &title, &content, &font, &lang, &isRTL, &views, &created, &ownerID) + } switch { case err == sql.ErrNoRows: return &RawPost{Content: "", Found: false, Gone: false} diff --git a/templates/edit-meta.tmpl b/templates/edit-meta.tmpl index 93c36ba..5d2bf1a 100644 --- a/templates/edit-meta.tmpl +++ b/templates/edit-meta.tmpl @@ -53,7 +53,7 @@
-

Edit metadata: {{if .Post.Title}}{{.Post.Title}}{{else}}{{.Post.Id}}{{end}} view post

+

Edit metadata: {{if .Post.Title}}{{.Post.Title}}{{else}}{{.Post.Id}}{{end}} view post

{{if .Flashes}}