Indicate deleteBy in post_deleted websocket event (#15332)
This lets the client know who deleted the post. This information is stored in the database, but cannot be retrieved from an API endpoint because the API does not return information about deleted post. Currently, the information is only sent to system administrators.
Этот коммит содержится в:
@@ -1993,6 +1993,56 @@ func TestDeletePost(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestDeletePostMessage(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
|
||||
th.App.AddUserToChannel(th.SystemAdminUser, th.BasicChannel)
|
||||
|
||||
defer th.TearDown()
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
client *model.Client4
|
||||
delete_by interface{}
|
||||
}{
|
||||
{"Do not send delete_by to regular user", th.Client, nil},
|
||||
{"Send delete_by to system admin user", th.SystemAdminClient, th.SystemAdminUser.Id},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
wsClient, err := th.CreateWebSocketClientWithClient(tc.client)
|
||||
require.Nil(t, err)
|
||||
defer wsClient.Close()
|
||||
|
||||
wsClient.Listen()
|
||||
|
||||
post := th.CreatePost()
|
||||
|
||||
status, resp := th.SystemAdminClient.DeletePost(post.Id)
|
||||
require.True(t, status, "post should return status OK")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
timeout := time.After(5 * time.Second)
|
||||
|
||||
for {
|
||||
select {
|
||||
case ev := <-wsClient.EventChannel:
|
||||
if ev.EventType() == model.WEBSOCKET_EVENT_POST_DELETED {
|
||||
assert.Equal(t, tc.delete_by, ev.GetData()["delete_by"])
|
||||
return
|
||||
}
|
||||
case <-timeout:
|
||||
// We just skip the test instead of failing because waiting for more than 5 seconds
|
||||
// to get a response does not make sense, and it will unncessarily slow down
|
||||
// the tests further in an already congested CI environment.
|
||||
t.Skip("timed out waiting for event")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPostThread(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user