summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorMartin Kraft <mkraft@users.noreply.github.com>2018-06-01 12:45:46 -0400
committerGitHub <noreply@github.com>2018-06-01 12:45:46 -0400
commit260d7a0f850a6f772b14b011022f1f65213a08a1 (patch)
tree1090ef2c0c1447be9e64baecd0d7336514922927 /store
parent5992a729c50989b7a39e42a0aaed42bc3914fb13 (diff)
downloadchat-260d7a0f850a6f772b14b011022f1f65213a08a1.tar.gz
chat-260d7a0f850a6f772b14b011022f1f65213a08a1.tar.bz2
chat-260d7a0f850a6f772b14b011022f1f65213a08a1.zip
MM-10412: Adds deleteBy prop to posts. (#8896)
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/post_store.go19
-rw-r--r--store/store.go2
-rw-r--r--store/storetest/mocks/PostStore.go6
-rw-r--r--store/storetest/post_store.go20
4 files changed, 34 insertions, 13 deletions
diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go
index e4872fe11..229005b73 100644
--- a/store/sqlstore/post_store.go
+++ b/store/sqlstore/post_store.go
@@ -398,11 +398,24 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.Stor
})
}
-func (s *SqlPostStore) Delete(postId string, time int64) store.StoreChannel {
+func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
- _, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId})
+
+ appErr := func(errMsg string) *model.AppError {
+ return model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+errMsg, http.StatusInternalServerError)
+ }
+
+ var post model.Post
+ err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": postId})
+ if err != nil {
+ result.Err = appErr(err.Error())
+ }
+
+ post.Props[model.POST_PROPS_DELETE_BY] = deleteByID
+
+ _, err = s.GetMaster().Exec("UPDATE Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt, Props = :Props WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId, "Props": model.StringInterfaceToJson(post.Props)})
if err != nil {
- result.Err = model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+err.Error(), http.StatusInternalServerError)
+ result.Err = appErr(err.Error())
}
})
}
diff --git a/store/store.go b/store/store.go
index bfc0ab845..d8b875459 100644
--- a/store/store.go
+++ b/store/store.go
@@ -181,7 +181,7 @@ type PostStore interface {
Update(newPost *model.Post, oldPost *model.Post) StoreChannel
Get(id string) StoreChannel
GetSingle(id string) StoreChannel
- Delete(postId string, time int64) StoreChannel
+ Delete(postId string, time int64, deleteByID string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
PermanentDeleteByChannel(channelId string) StoreChannel
GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
diff --git a/store/storetest/mocks/PostStore.go b/store/storetest/mocks/PostStore.go
index 130bfafd7..8f56bc4b2 100644
--- a/store/storetest/mocks/PostStore.go
+++ b/store/storetest/mocks/PostStore.go
@@ -67,12 +67,12 @@ func (_m *PostStore) ClearCaches() {
}
// Delete provides a mock function with given fields: postId, time
-func (_m *PostStore) Delete(postId string, time int64) store.StoreChannel {
+func (_m *PostStore) Delete(postId string, time int64, deleteByID string) store.StoreChannel {
ret := _m.Called(postId, time)
var r0 store.StoreChannel
- if rf, ok := ret.Get(0).(func(string, int64) store.StoreChannel); ok {
- r0 = rf(postId, time)
+ if rf, ok := ret.Get(0).(func(string, int64, string) store.StoreChannel); ok {
+ r0 = rf(postId, time, deleteByID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go
index 6ebb875bf..1159af37f 100644
--- a/store/storetest/post_store.go
+++ b/store/storetest/post_store.go
@@ -247,6 +247,7 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "zz" + model.NewId() + "b"
+ deleteByID := model.NewId()
etag1 := (<-ss.Post().GetEtag(o1.ChannelId, false)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".") != 0 {
@@ -263,10 +264,17 @@ func testPostStoreDelete(t *testing.T, ss store.Store) {
}
}
- if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
+ if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis(), deleteByID); r2.Err != nil {
t.Fatal(r2.Err)
}
+ r5 := <-ss.Post().GetPostsCreatedAt(o1.ChannelId, o1.CreateAt)
+ post := r5.Data.([]*model.Post)[0]
+ actual := post.Props[model.POST_PROPS_DELETE_BY]
+ if actual != deleteByID {
+ t.Errorf("Expected (*Post).Props[model.POST_PROPS_DELETE_BY] to be %v but got %v.", deleteByID, actual)
+ }
+
if r3 := (<-ss.Post().Get(o1.Id)); r3.Err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed")
@@ -293,7 +301,7 @@ func testPostStoreDelete1Level(t *testing.T, ss store.Store) {
o2.RootId = o1.Id
o2 = (<-ss.Post().Save(o2)).Data.(*model.Post)
- if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
+ if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis(), ""); r2.Err != nil {
t.Fatal(r2.Err)
}
@@ -335,7 +343,7 @@ func testPostStoreDelete2Level(t *testing.T, ss store.Store) {
o4.Message = "zz" + model.NewId() + "b"
o4 = (<-ss.Post().Save(o4)).Data.(*model.Post)
- if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis()); r2.Err != nil {
+ if r2 := <-ss.Post().Delete(o1.Id, model.GetMillis(), ""); r2.Err != nil {
t.Fatal(r2.Err)
}
@@ -468,7 +476,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
}
}
- store.Must(ss.Post().Delete(o3.Id, model.GetMillis()))
+ store.Must(ss.Post().Delete(o3.Id, model.GetMillis(), ""))
if r2 := <-ss.Post().Get(o1.Id); r2.Err != nil {
t.Fatal(r2.Err)
@@ -479,7 +487,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
}
}
- store.Must(ss.Post().Delete(o2.Id, model.GetMillis()))
+ store.Must(ss.Post().Delete(o2.Id, model.GetMillis(), ""))
if r3 := <-ss.Post().Get(o1.Id); r3.Err != nil {
t.Fatal(r3.Err)
@@ -1589,7 +1597,7 @@ func testPostStoreGetPostsByIds(t *testing.T, ss store.Store) {
t.Fatalf("Expected 3 posts in results. Got %v", len(ro4))
}
- store.Must(ss.Post().Delete(ro1.Id, model.GetMillis()))
+ store.Must(ss.Post().Delete(ro1.Id, model.GetMillis(), ""))
if ro5 := store.Must(ss.Post().GetPostsByIds(postIds)).([]*model.Post); len(ro5) != 2 {
t.Fatalf("Expected 2 posts in results. Got %v", len(ro5))