From e1effd2a45f98aa3fb46d091e264b2ecc1133177 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Wed, 1 May 2019 18:53:33 -0400 Subject: [PATCH] comment_list.go: check for moderator status conditionally --- api/comment_list.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/api/comment_list.go b/api/comment_list.go index 21f9629..f451d08 100644 --- a/api/comment_list.go +++ b/api/comment_list.go @@ -131,24 +131,31 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) { } commenterHex := "anonymous" - c, err := commenterGetByCommenterToken(*x.CommenterToken) - if err != nil { - if err == errorNoSuchToken { - commenterHex = "anonymous" - } else { - bodyMarshal(w, response{"success": false, "message": err.Error()}) - return - } - } else { - commenterHex = c.CommenterHex - } - isModerator := false modList := map[string]bool{} - for _, mod := range d.Moderators { - modList[mod.Email] = true - if mod.Email == c.Email { - isModerator = true + + if *x.CommenterToken != "anonymous" { + c, err := commenterGetByCommenterToken(*x.CommenterToken) + if err != nil { + if err == errorNoSuchToken { + commenterHex = "anonymous" + } else { + bodyMarshal(w, response{"success": false, "message": err.Error()}) + return + } + } else { + commenterHex = c.CommenterHex + } + + for _, mod := range d.Moderators { + modList[mod.Email] = true + if mod.Email == c.Email { + isModerator = true + } + } + } else { + for _, mod := range d.Moderators { + modList[mod.Email] = true } }