From 42b1577a1fb34d4312244f72717098704837058e Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 12 Mar 2018 03:24:09 -0500 Subject: [PATCH] minor renaming --- app/rest/api/rest.go | 2 +- app/store/comment.go | 15 +++------------ app/store/service.go | 3 +++ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/rest/api/rest.go b/app/rest/api/rest.go index 205798a5..f505bab6 100644 --- a/app/rest/api/rest.go +++ b/app/rest/api/rest.go @@ -134,7 +134,7 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) { return } - comment.Init() + comment.Prepare() // clean all fields user not suppoed to set comment.User = user comment.User.IP = strings.Split(r.RemoteAddr, ":")[0] comment.Text = string(blackfriday.Run([]byte(comment.Text), blackfriday.WithNoExtensions())) // render markdown diff --git a/app/store/comment.go b/app/store/comment.go index 975eb888..36158de1 100644 --- a/app/store/comment.go +++ b/app/store/comment.go @@ -58,8 +58,9 @@ type BlockedUser struct { Timestamp time.Time `json:"time"` } -// Init comment skeleton -func (c *Comment) Init() { +// Prepare comment received from untrusted source by clearing all autogen fields and +// reset everyting users not supposed to provide +func (c *Comment) Prepare() { c.ID = "" // don't allow user to define ID, force auto-gen c.Timestamp = time.Time{} // reset time, force auto-gen c.Votes = make(map[string]bool) @@ -95,13 +96,3 @@ type NotifUser struct { ID string `json:"id"` Destination string `json:"destination"` } - -// NotifScope defines "enum" of notification scopes -type NotifScope int - -// All NotifScope values -const ( - ScopeSite NotifScope = 1 - ScopePost NotifScope = 2 - ScopeReply NotifScope = 3 -) diff --git a/app/store/service.go b/app/store/service.go index c563da1a..1059214e 100644 --- a/app/store/service.go +++ b/app/store/service.go @@ -30,6 +30,9 @@ func (s *Service) Vote(locator Locator, commentID string, userID string, val boo return comment, err } + if comment.Votes == nil { + comment.Votes = make(map[string]bool) + } v, voted := comment.Votes[userID] if voted && v == val {