summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api4/post.go2
-rw-r--r--app/plugin_api.go2
-rw-r--r--app/post.go4
-rw-r--r--model/post.go1
-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
8 files changed, 39 insertions, 17 deletions
diff --git a/api4/post.go b/api4/post.go
index b4392a74e..68c1967ff 100644
--- a/api4/post.go
+++ b/api4/post.go
@@ -264,7 +264,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if _, err := c.App.DeletePost(c.Params.PostId); err != nil {
+ if _, err := c.App.DeletePost(c.Params.PostId, c.Session.UserId); err != nil {
c.Err = err
return
}
diff --git a/app/plugin_api.go b/app/plugin_api.go
index b09a0c419..06eeee146 100644
--- a/app/plugin_api.go
+++ b/app/plugin_api.go
@@ -158,7 +158,7 @@ func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError
}
func (api *PluginAPI) DeletePost(postId string) *model.AppError {
- _, err := api.app.DeletePost(postId)
+ _, err := api.app.DeletePost(postId, api.id)
return err
}
diff --git a/app/post.go b/app/post.go
index 2efa4c90e..4f4c6f65c 100644
--- a/app/post.go
+++ b/app/post.go
@@ -569,14 +569,14 @@ func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, be
}
}
-func (a *App) DeletePost(postId string) (*model.Post, *model.AppError) {
+func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
if result := <-a.Srv.Store.Post().GetSingle(postId); result.Err != nil {
result.Err.StatusCode = http.StatusBadRequest
return nil, result.Err
} else {
post := result.Data.(*model.Post)
- if result := <-a.Srv.Store.Post().Delete(postId, model.GetMillis()); result.Err != nil {
+ if result := <-a.Srv.Store.Post().Delete(postId, model.GetMillis(), deleteByID); result.Err != nil {
return nil, result.Err
}
diff --git a/model/post.go b/model/post.go
index 1db4b842a..3d7a31ab5 100644
--- a/model/post.go
+++ b/model/post.go
@@ -50,6 +50,7 @@ const (
POST_CUSTOM_TYPE_PREFIX = "custom_"
PROPS_ADD_CHANNEL_MEMBER = "add_channel_member"
POST_PROPS_ADDED_USER_ID = "addedUserId"
+ POST_PROPS_DELETE_BY = "deleteBy"
)
type Post struct {
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))