limit edit window

This commit is contained in:
Umputun
2018-01-03 13:55:43 -06:00
parent 1de76f2b5e
commit 50f447587f
+7
View File
@@ -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()