diff --git a/app/rest/admin.go b/app/rest/admin.go index ae31ddc6..662e8c3f 100644 --- a/app/rest/admin.go +++ b/app/rest/admin.go @@ -111,3 +111,16 @@ func (a *admin) importCtrl(w http.ResponseWriter, r *http.Request) { func (a *admin) checkBlocked(locator store.Locator, user store.User) bool { return a.dataService.IsBlocked(locator, user.ID) } + +func (a *admin) maskBlockedUsers(comments []store.Comment) (res []store.Comment) { + for _, c := range comments { + if a.dataService.IsBlocked(c.Locator, c.User.ID) { + c.User.Blocked = true + c.Text = "this comment was deleted" + c.Score = 0 + c.Votes = map[string]bool{} + } + res = append(res, c) + } + return res +} diff --git a/app/rest/server.go b/app/rest/server.go index 51a03a39..f0350d29 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -160,7 +160,7 @@ func (s *Server) deleteCommentCtrl(w http.ResponseWriter, r *http.Request) { } // GET /find?site=siteID&url=post-url&format=[tree|plain]&sort=[+/-time|+/-score] -// find comments for given post. Retruns in tree or plain formats, sorted +// find comments for given post. Returns in tree or plain formats, sorted func (s *Server) findCommentsCtrl(w http.ResponseWriter, r *http.Request) { locator := store.Locator{SiteID: r.URL.Query().Get("site"), URL: r.URL.Query().Get("url")} log.Printf("[DEBUG] get comments for %+v", locator) @@ -177,6 +177,8 @@ func (s *Server) findCommentsCtrl(w http.ResponseWriter, r *http.Request) { httpError(w, r, http.StatusInternalServerError, err, "can't load comments comment") return } + comments = s.mod.maskBlockedUsers(comments) + if r.URL.Query().Get("format") == "tree" { s.respCache.Set(cacheKey, comments, time.Hour) renderJSONWithHTML(w, r, format.MakeTree(comments, r.URL.Query().Get("sort"))) @@ -207,6 +209,7 @@ func (s *Server) lastCommentsCtrl(w http.ResponseWriter, r *http.Request) { httpError(w, r, http.StatusInternalServerError, err, "can't get last comments") return } + comments = s.mod.maskBlockedUsers(comments) s.respCache.Set(cacheKey, comments, time.Hour) render.Status(r, http.StatusOK) @@ -231,7 +234,7 @@ func (s *Server) commentByIDCtrl(w http.ResponseWriter, r *http.Request) { renderJSONWithHTML(w, r, comment) } -// GET /comments?site=siteID&user=id - returns commens for given userID +// GET /comments?site=siteID&user=id - returns comments for given userID func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) { userID := r.URL.Query().Get("user") diff --git a/app/store/store.go b/app/store/store.go index 44ecfb09..a9567b96 100644 --- a/app/store/store.go +++ b/app/store/store.go @@ -40,6 +40,7 @@ type User struct { Picture string `json:"picture"` Profile string `json:"profile"` Admin bool `json:"admin"` + Blocked bool `json:"block,omitempty"` IP string `json:"-"` }