aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-10 13:00:53 (UTC)
committerjan <jan@ruken.pw>2016-10-10 13:00:53 (UTC)
commit9d4ebd033d5f0d6ad6d1d6f52fd16e0bdc17a49e (patch)
treed47debc0d888b23e35cbf7f0628cc5ca3dea5eb7
parent985930bd454a9732e31f460821be43d036afe411 (diff)
list: listen loeschen
-rw-r--r--modules/lists/lists.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 9e78ac7..6129502 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -79,6 +79,7 @@ func (m *Module) Init(g *grilist.Grilist) {
79 m.g.Router.POST("/list/:id/settings", m.updateListSettings) 79 m.g.Router.POST("/list/:id/settings", m.updateListSettings)
80 m.g.Router.GET("/new/list", m.displayCreateList) 80 m.g.Router.GET("/new/list", m.displayCreateList)
81 m.g.Router.POST("/new/list", m.createList) 81 m.g.Router.POST("/new/list", m.createList)
82 m.g.Router.GET("/list/:id/delete", m.deleteList)
82 83
83 m.g.Router.GET("/api/lists/user", m.APIgetUserLists) 84 m.g.Router.GET("/api/lists/user", m.APIgetUserLists)
84 85
@@ -287,6 +288,54 @@ func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.P
287 m.g.Renderer.RenderPage("list", w, data) 288 m.g.Renderer.RenderPage("list", w, data)
288} 289}
289 290
291func (m *Module) deleteList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
292 user, err := m.g.Charakterin.GetUserFromRequest(r)
293 if err != nil {
294 log.Println("invalid deleteList user")
295 http.Redirect(w, r, fmt.Sprintf("/list/%s", p.ByName("id")), 403)
296 return
297 }
298
299 id, err := strconv.Atoi(p.ByName("id"))
300 if err != nil {
301 log.Println("invalid deleteList ID")
302 http.Redirect(w, r, "/", 400)
303 return
304 }
305
306 list, err := m.FromID(id, false)
307 if err != nil {
308 log.Println("invalid deleteList ID (could not get list)")
309 http.Redirect(w, r, fmt.Sprintf("/list/%d", id), 500)
310 return
311 }
312
313 // checken, ob der user auch list owner ist
314 if user.ID != list.Owner.ID {
315 log.Println("invalid deleteList request: user not list owner")
316 http.Redirect(w, r, fmt.Sprintf("/list/%d", id), 403)
317 return
318 }
319
320 // aus der Datenbank loeschen
321 _, err = m.g.DB.Query(`DELETE FROM grilist.lists WHERE id = $1`, id)
322 if err != nil {
323 log.Println("could not delete list:", err)
324 data := m.g.Renderer.DefaultData()
325 data["user"] = user
326 data["list"] = list
327 data["error"] = "Liste konnte nicht geloescht werden."
328
329 m.g.Renderer.RenderPage("list_settings", w, data)
330 return
331 }
332 // aus dem Cache loeschen
333 m.c.Remove(list.ID)
334
335 log.Printf("list %d has been deleted by the owner %d(%s)", list.ID, list.Owner.ID, list.Owner.GetName())
336 http.Redirect(w, r, "/", 302)
337}
338
290func (m *Module) viewListSettings(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 339func (m *Module) viewListSettings(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
291 user, err := m.g.Charakterin.GetUserFromRequest(r) 340 user, err := m.g.Charakterin.GetUserFromRequest(r)
292 if err != nil { 341 if err != nil {