(app *App, w http.ResponseWriter, r *http.Request)
| 121 | } |
| 122 | |
| 123 | func handleViewMeta(app *App, w http.ResponseWriter, r *http.Request) error { |
| 124 | vars := mux.Vars(r) |
| 125 | action := vars["action"] |
| 126 | slug := vars["slug"] |
| 127 | collAlias := vars["collection"] |
| 128 | appData := &struct { |
| 129 | page.StaticPage |
| 130 | Post *RawPost |
| 131 | User *User |
| 132 | EditCollection *Collection // Collection of the post we're editing, if any |
| 133 | Flashes []string |
| 134 | NeedsToken bool |
| 135 | Silenced bool |
| 136 | }{ |
| 137 | StaticPage: pageForReq(app, r), |
| 138 | Post: &RawPost{Font: "norm"}, |
| 139 | User: getUserSession(app, r), |
| 140 | } |
| 141 | var err error |
| 142 | appData.Silenced, err = app.db.IsUserSilenced(appData.User.ID) |
| 143 | if err != nil { |
| 144 | log.Error("view meta: get user status: %v", err) |
| 145 | return ErrInternalGeneral |
| 146 | } |
| 147 | |
| 148 | if action == "" && slug == "" { |
| 149 | return ErrPostNotFound |
| 150 | } |
| 151 | |
| 152 | // Make sure this isn't cached, so user doesn't accidentally lose data |
| 153 | w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") |
| 154 | w.Header().Set("Expires", "Thu, 28 Jul 1989 12:00:00 GMT") |
| 155 | if slug != "" { |
| 156 | appData.Post = getRawCollectionPost(app, slug, collAlias) |
| 157 | if appData.Post.OwnerID != appData.User.ID { |
| 158 | // TODO: add ErrForbiddenEditPost message to flashes |
| 159 | return impart.HTTPError{http.StatusFound, r.URL.Path[:strings.LastIndex(r.URL.Path, "/meta")]} |
| 160 | } |
| 161 | if app.cfg.App.SingleUser { |
| 162 | // TODO: optimize this query just like we do in GetCollectionForPad (?) |
| 163 | appData.EditCollection, err = app.db.GetCollectionByID(1) |
| 164 | } else { |
| 165 | appData.EditCollection, err = app.db.GetCollectionForPad(collAlias) |
| 166 | } |
| 167 | if err != nil { |
| 168 | return err |
| 169 | } |
| 170 | appData.EditCollection.hostName = app.cfg.App.Host |
| 171 | } else { |
| 172 | // Editing a floating article |
| 173 | appData.Post = getRawPost(app, action) |
| 174 | appData.Post.Id = action |
| 175 | } |
| 176 | appData.NeedsToken = appData.User == nil || appData.User.ID != appData.Post.OwnerID |
| 177 | |
| 178 | if appData.Post.Gone { |
| 179 | return ErrPostUnpublished |
| 180 | } else if appData.Post.Found && appData.Post.Content != "" { |
nothing calls this directly
no test coverage detected