From 57372bd06b5d2f5c203143d4d57d74b5a3f51da7 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Thu, 12 Dec 2024 10:12:21 -0500 Subject: [PATCH] [MM-62092] Allow system admins to pull posts in from DMs they're not in (#29557) --- server/channels/api4/post.go | 2 +- server/channels/api4/post_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/channels/api4/post.go b/server/channels/api4/post.go index 8280877f5a..2c2e3f88df 100644 --- a/server/channels/api4/post.go +++ b/server/channels/api4/post.go @@ -214,7 +214,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = err return } - if !c.App.SessionHasPermissionToReadChannel(c.AppContext, *c.AppContext.Session(), channel) { + if !c.IsSystemAdmin() && !c.App.SessionHasPermissionToReadChannel(c.AppContext, *c.AppContext.Session(), channel) { c.SetPermissionError(model.PermissionReadChannelContent) return } diff --git a/server/channels/api4/post_test.go b/server/channels/api4/post_test.go index 3cc142bf29..9c831a04bd 100644 --- a/server/channels/api4/post_test.go +++ b/server/channels/api4/post_test.go @@ -1994,6 +1994,14 @@ func TestGetPostsForChannel(t *testing.T) { require.NoError(t, err) CheckOKStatus(t, resp) require.Len(t, posts.Order, 10, "expected 10 posts") + + // allow viewing of direct messages + dmChannel := th.CreateDmChannel(th.BasicUser2) + th.CreateMessagePostNoClient(dmChannel, "test1", model.GetMillis()) + + posts, resp, err = c.GetPostsForChannel(context.Background(), dmChannel.Id, 0, 100, "", false, false) + require.NoError(t, err) + CheckOKStatus(t, resp) }) }