[MM-41998] Channel Info RHS: display number of files for a channel (#19822)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -709,6 +709,33 @@ func (th *TestHelper) CreateMessagePost(message string) *model.Post {
|
||||
return th.CreateMessagePostWithClient(th.Client, th.BasicChannel, message)
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreatePostWithFiles(files ...*model.FileInfo) *model.Post {
|
||||
return th.CreatePostWithFilesWithClient(th.Client, th.BasicChannel, files...)
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreatePostInChannelWithFiles(channel *model.Channel, files ...*model.FileInfo) *model.Post {
|
||||
return th.CreatePostWithFilesWithClient(th.Client, channel, files...)
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreatePostWithFilesWithClient(client *model.Client4, channel *model.Channel, files ...*model.FileInfo) *model.Post {
|
||||
var fileIds model.StringArray
|
||||
for i := range files {
|
||||
fileIds = append(fileIds, files[i].Id)
|
||||
}
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: channel.Id,
|
||||
Message: "message_" + model.NewId(),
|
||||
FileIds: fileIds,
|
||||
}
|
||||
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return rpost
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreatePostWithClient(client *model.Client4, channel *model.Channel) *model.Post {
|
||||
id := model.NewId()
|
||||
|
||||
|
||||
@@ -642,11 +642,18 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
filesCount, err := c.App.GetChannelFileCount(c.Params.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
stats := model.ChannelStats{
|
||||
ChannelId: c.Params.ChannelId,
|
||||
MemberCount: memberCount,
|
||||
GuestCount: guestCount,
|
||||
PinnedPostCount: pinnedPostCount,
|
||||
FilesCount: filesCount,
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(stats); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/utils/testutils"
|
||||
)
|
||||
|
||||
func TestCreateChannel(t *testing.T) {
|
||||
@@ -2507,12 +2508,24 @@ func TestGetChannelStats(t *testing.T) {
|
||||
require.Equal(t, channel.Id, stats.ChannelId, "couldn't get extra info")
|
||||
require.Equal(t, int64(1), stats.MemberCount, "got incorrect member count")
|
||||
require.Equal(t, int64(0), stats.PinnedPostCount, "got incorrect pinned post count")
|
||||
require.Equal(t, int64(0), stats.FilesCount, "got incorrect file count")
|
||||
|
||||
th.CreatePinnedPostWithClient(th.Client, channel)
|
||||
stats, _, err = client.GetChannelStats(channel.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), stats.PinnedPostCount, "should have returned 1 pinned post count")
|
||||
|
||||
// create a post with a file
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
th.CreatePostInChannelWithFiles(channel, fileResp.FileInfos...)
|
||||
// make sure the file count channel stats is updated
|
||||
stats, _, err = client.GetChannelStats(channel.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), stats.FilesCount, "should have returned 1 file count")
|
||||
|
||||
_, resp, err := client.GetChannelStats("junk", "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user