[MM-68697] Preserve sender file ID in plugin-relayed shared channel attachments (#36468)

Set ReqFileId on the UploadSession created in
  ReceiveSharedChannelAttachmentSyncMsg so the attachment is persisted
  under the sender's file ID. Without this, the receiving server stored
  the bytes under a freshly generated ID while the synced post's FileIds
  still referenced the sender's ID, leaving the attachment invisible in
  the UI even though the file and FileInfo row existed on disk.

  Mirrors the existing cluster-to-cluster path in
  platform/services/sharedchannel/attachment.go.

  Also tightens TestPluginAPIReceiveSharedChannelAttachmentSyncMsg to
  pass a sender-side fi.Id and assert the saved FileInfo keeps it. The
  prior assertion only checked that some ID was assigned, which the
  buggy code also satisfied.
This commit is contained in:
Doug Lauder 2026-05-07 21:04:10 -04:00 committed by GitHub
parent 6d30bff0a6
commit 97f0ad7c3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -339,6 +339,7 @@ func (a *App) ReceiveSharedChannelAttachmentSyncMsg(rctx request.CTX, pluginID,
Filename: fi.Name,
FileSize: fi.Size,
RemoteId: rc.RemoteId,
ReqFileId: fi.Id,
}
us, appErr := a.CreateUploadSession(rctx, us)

View file

@ -1360,7 +1360,11 @@ func TestPluginAPIReceiveSharedChannelAttachmentSyncMsg(t *testing.T) {
remoteUser, appErr := th.App.CreateUser(th.Context, remoteUser)
require.Nil(t, appErr)
// The sender-side file ID must be preserved on the receiving server so the
// post's FileIds (which reference the sender ID) resolve to the saved file.
senderFileID := model.NewId()
fi := &model.FileInfo{
Id: senderFileID,
CreatorId: remoteUser.Id,
Name: "hello.txt",
Size: 13,
@ -1369,12 +1373,13 @@ func TestPluginAPIReceiveSharedChannelAttachmentSyncMsg(t *testing.T) {
saved, err := api.ReceiveSharedChannelAttachmentSyncMsg(rc.RemoteId, channel.Id, fi, bytes.NewReader([]byte("hello, world!")))
require.NoError(t, err)
require.NotNil(t, saved)
assert.NotEmpty(t, saved.Id)
assert.Equal(t, senderFileID, saved.Id, "saved FileInfo must keep the sender's file ID")
assert.Equal(t, rc.RemoteId, *saved.RemoteId)
// Verify the FileInfo was persisted with a server-constructed path
storedFI, appErr := th.App.GetFileInfo(th.Context, saved.Id)
require.Nil(t, appErr)
assert.Equal(t, senderFileID, storedFI.Id)
assert.Equal(t, "hello.txt", storedFI.Name)
assert.NotEmpty(t, storedFI.Path)
assert.Contains(t, storedFI.Path, "hello.txt")