MCPcopy Index your code
hub / github.com/writefreely/writefreely / existingCollection

Function existingCollection

collections.go:1245–1332  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1243}
1244
1245func existingCollection(app *App, w http.ResponseWriter, r *http.Request) error {
1246 reqJSON := IsJSON(r)
1247 vars := mux.Vars(r)
1248 collAlias := vars["alias"]
1249 isWeb := r.FormValue("web") == "1"
1250
1251 u := &User{}
1252 if reqJSON && !isWeb {
1253 // Ensure an access token was given
1254 accessToken := r.Header.Get("Authorization")
1255 u.ID = app.db.GetUserID(accessToken)
1256 if u.ID == -1 {
1257 return ErrBadAccessToken
1258 }
1259 } else {
1260 u = getUserSession(app, r)
1261 if u == nil {
1262 return ErrNotLoggedIn
1263 }
1264 }
1265
1266 silenced, err := app.db.IsUserSilenced(u.ID)
1267 if err != nil {
1268 log.Error("existing collection: %v", err)
1269 return ErrInternalGeneral
1270 }
1271
1272 if silenced {
1273 return ErrUserSilenced
1274 }
1275
1276 if r.Method == "DELETE" {
1277 err := app.db.DeleteCollection(collAlias, u.ID)
1278 if err != nil {
1279 // TODO: if not HTTPError, report error to admin
1280 log.Error("Unable to delete collection: %s", err)
1281 return err
1282 }
1283 addSessionFlash(app, w, r, "Deleted your blog, "+collAlias+".", nil)
1284 return impart.HTTPError{Status: http.StatusNoContent}
1285 }
1286
1287 c := SubmittedCollection{OwnerID: uint64(u.ID)}
1288
1289 if reqJSON {
1290 // Decode JSON request
1291 decoder := json.NewDecoder(r.Body)
1292 err = decoder.Decode(&c)
1293 if err != nil {
1294 log.Error("Couldn't parse collection update JSON request: %v\n", err)
1295 return ErrBadJSON
1296 }
1297 } else {
1298 err = r.ParseForm()
1299 if err != nil {
1300 log.Error("Couldn't parse collection update form request: %v\n", err)
1301 return ErrBadFormData
1302 }

Callers

nothing calls this directly

Calls 7

IsJSONFunction · 0.85
getUserSessionFunction · 0.85
addSessionFlashFunction · 0.85
IsUserSilencedMethod · 0.80
GetUserIDMethod · 0.65
DeleteCollectionMethod · 0.65
UpdateCollectionMethod · 0.65

Tested by

no test coverage detected