MM-31875 soft delete reactions (#16654)
- soft delete reaction by setting new field Reactions.DeleteAt to non-zero. - include new field Reactions.UpdateAt
Этот коммит содержится в:
@@ -15,6 +15,8 @@ type Reaction struct {
|
||||
PostId string `json:"post_id"`
|
||||
EmojiName string `json:"emoji_name"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
}
|
||||
|
||||
func (o *Reaction) ToJson() string {
|
||||
@@ -79,6 +81,10 @@ func (o *Reaction) IsValid() *AppError {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.UpdateAt == 0 {
|
||||
return NewAppError("Reaction.IsValid", "model.reaction.is_valid.update_at.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -86,4 +92,10 @@ func (o *Reaction) PreSave() {
|
||||
if o.CreateAt == 0 {
|
||||
o.CreateAt = GetMillis()
|
||||
}
|
||||
o.UpdateAt = GetMillis()
|
||||
o.DeleteAt = 0
|
||||
}
|
||||
|
||||
func (o *Reaction) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: false,
|
||||
@@ -35,6 +36,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "user id should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -45,6 +47,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "user id should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -55,6 +58,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: "",
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "post id should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -65,6 +69,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: "1234garbage",
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "post id should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -75,6 +80,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: strings.Repeat("a", 64),
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: false,
|
||||
@@ -85,6 +91,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji-",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: false,
|
||||
@@ -95,6 +102,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji_",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: false,
|
||||
@@ -105,6 +113,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "+1",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: false,
|
||||
@@ -115,6 +124,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji:",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "",
|
||||
shouldErr: true,
|
||||
@@ -125,6 +135,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "emoji name should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -135,6 +146,7 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: strings.Repeat("a", 65),
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "emoji name should be invalid",
|
||||
shouldErr: true,
|
||||
@@ -145,10 +157,22 @@ func TestReactionIsValid(t *testing.T) {
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji",
|
||||
CreateAt: 0,
|
||||
UpdateAt: GetMillis(),
|
||||
},
|
||||
errMsg: "create at should be invalid",
|
||||
shouldErr: true,
|
||||
},
|
||||
{
|
||||
reaction: Reaction{
|
||||
UserId: NewId(),
|
||||
PostId: NewId(),
|
||||
EmojiName: "emoji",
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: 0,
|
||||
},
|
||||
errMsg: "update at should be invalid",
|
||||
shouldErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Ссылка в новой задаче
Block a user