From 50f447587fe6d86da1da576b0d9158ef24cb414c Mon Sep 17 00:00:00 2001 From: Umputun Date: Wed, 3 Jan 2018 13:55:43 -0600 Subject: [PATCH] limit edit window --- app/store/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/store/service.go b/app/store/service.go index 7831a3ec..f3f1bc17 100644 --- a/app/store/service.go +++ b/app/store/service.go @@ -6,6 +6,8 @@ import ( "github.com/pkg/errors" ) +var editDuration = 5 * time.Minute + // Service wraps store.Interface with additional methods type Service struct { Interface @@ -55,6 +57,11 @@ func (s *Service) EditComment(locator Locator, commentID string, text string, ed return comment, errors.Errorf("comment %s already edited at %s", commentID, comment.Edit.Timestamp) } + // edit allowed in editDuration window only + if comment.Timestamp.Add(editDuration).After(time.Now()) { + return comment, errors.Errorf("too late to edit %s", commentID) + } + comment.Text = text comment.Edit = &edit comment.Edit.Timestamp = time.Now()