MM-49486: Option to exclude file count in channel stats (#22096)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3522419e89
Коммит
58fda05349
@@ -627,6 +627,9 @@ func getChannelUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
excludeFilesCount := r.URL.Query().Get("exclude_files_count")
|
||||||
|
excludeFilesCountBool, _ := strconv.ParseBool(excludeFilesCount)
|
||||||
|
|
||||||
c.RequireChannelId()
|
c.RequireChannelId()
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return
|
return
|
||||||
@@ -655,10 +658,13 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filesCount, err := c.App.GetChannelFileCount(c.AppContext, c.Params.ChannelId)
|
filesCount := int64(-1)
|
||||||
if err != nil {
|
if !excludeFilesCountBool {
|
||||||
c.Err = err
|
filesCount, err = c.App.GetChannelFileCount(c.AppContext, c.Params.ChannelId)
|
||||||
return
|
if err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stats := model.ChannelStats{
|
stats := model.ChannelStats{
|
||||||
|
|||||||
@@ -2543,7 +2543,7 @@ func TestGetChannelStats(t *testing.T) {
|
|||||||
client := th.Client
|
client := th.Client
|
||||||
channel := th.CreatePrivateChannel()
|
channel := th.CreatePrivateChannel()
|
||||||
|
|
||||||
stats, _, err := client.GetChannelStats(channel.Id, "")
|
stats, _, err := client.GetChannelStats(channel.Id, "", false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, channel.Id, stats.ChannelId, "couldn't get extra info")
|
require.Equal(t, channel.Id, stats.ChannelId, "couldn't get extra info")
|
||||||
@@ -2552,7 +2552,7 @@ func TestGetChannelStats(t *testing.T) {
|
|||||||
require.Equal(t, int64(0), stats.FilesCount, "got incorrect file count")
|
require.Equal(t, int64(0), stats.FilesCount, "got incorrect file count")
|
||||||
|
|
||||||
th.CreatePinnedPostWithClient(th.Client, channel)
|
th.CreatePinnedPostWithClient(th.Client, channel)
|
||||||
stats, _, err = client.GetChannelStats(channel.Id, "")
|
stats, _, err = client.GetChannelStats(channel.Id, "", false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, int64(1), stats.PinnedPostCount, "should have returned 1 pinned post count")
|
require.Equal(t, int64(1), stats.PinnedPostCount, "should have returned 1 pinned post count")
|
||||||
|
|
||||||
@@ -2563,30 +2563,35 @@ func TestGetChannelStats(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
th.CreatePostInChannelWithFiles(channel, fileResp.FileInfos...)
|
th.CreatePostInChannelWithFiles(channel, fileResp.FileInfos...)
|
||||||
// make sure the file count channel stats is updated
|
// make sure the file count channel stats is updated
|
||||||
stats, _, err = client.GetChannelStats(channel.Id, "")
|
stats, _, err = client.GetChannelStats(channel.Id, "", false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, int64(1), stats.FilesCount, "should have returned 1 file count")
|
require.Equal(t, int64(1), stats.FilesCount, "should have returned 1 file count")
|
||||||
|
|
||||||
_, resp, err := client.GetChannelStats("junk", "")
|
// exclude file counts
|
||||||
|
stats, _, err = client.GetChannelStats(channel.Id, "", true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(-1), stats.FilesCount, "should have returned -1 file count for exclude_files_count=true")
|
||||||
|
|
||||||
|
_, resp, err := client.GetChannelStats("junk", "", false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
_, resp, err = client.GetChannelStats(model.NewId(), "")
|
_, resp, err = client.GetChannelStats(model.NewId(), "", false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
client.Logout()
|
client.Logout()
|
||||||
_, resp, err = client.GetChannelStats(channel.Id, "")
|
_, resp, err = client.GetChannelStats(channel.Id, "", false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
th.LoginBasic2()
|
th.LoginBasic2()
|
||||||
|
|
||||||
_, resp, err = client.GetChannelStats(channel.Id, "")
|
_, resp, err = client.GetChannelStats(channel.Id, "", false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
_, _, err = th.SystemAdminClient.GetChannelStats(channel.Id, "")
|
_, _, err = th.SystemAdminClient.GetChannelStats(channel.Id, "", false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3032,8 +3032,9 @@ func (c *Client4) GetChannel(channelId, etag string) (*Channel, *Response, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelStats returns statistics for a channel.
|
// GetChannelStats returns statistics for a channel.
|
||||||
func (c *Client4) GetChannelStats(channelId string, etag string) (*ChannelStats, *Response, error) {
|
func (c *Client4) GetChannelStats(channelId string, etag string, excludeFilesCount bool) (*ChannelStats, *Response, error) {
|
||||||
r, err := c.DoAPIGet(c.channelRoute(channelId)+"/stats", etag)
|
route := c.channelRoute(channelId) + fmt.Sprintf("/stats?exclude_files_count=%v", excludeFilesCount)
|
||||||
|
r, err := c.DoAPIGet(route, etag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, BuildResponse(r), err
|
return nil, BuildResponse(r), err
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user