[MM-46692] Channel group member count (#21270)

* tools updates

* Revert "tools updates"

This reverts commit 6293297b55803c5a263e200ebd80192899666ae9.

* adding channel member count to groups request

* fixing models

* adding a new test

* removing unused var

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.ht.home>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.fritz.box>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.fritz.box>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ben Cooke
2022-11-22 11:31:04 -05:00
коммит произвёл GitHub
родитель afc2dcebe1
Коммит 76f7872a50
6 изменённых файлов: 153 добавлений и 47 удалений

Просмотреть файл

@@ -950,12 +950,13 @@ func getGroupsAssociatedToChannelsByTeam(c *Context, w http.ResponseWriter, r *h
}
func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
var teamID, NotAssociatedToChannelID, ChannelIDForMemberCount string
permissionErr := requireLicense(c)
if permissionErr != nil {
c.Err = permissionErr
return
}
var teamID, channelID string
source := c.Params.GroupSource
@@ -964,7 +965,11 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
}
if id := c.Params.NotAssociatedToChannel; model.IsValidId(id) {
channelID = id
NotAssociatedToChannelID = id
}
if id := c.Params.IncludeChannelMemberCount; model.IsValidId(id) {
ChannelIDForMemberCount = id
}
// If they specify the group_source as custom when the feature is disabled, throw an error
@@ -979,6 +984,8 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
source = model.GroupSourceLdap
}
includeTimezones := r.URL.Query().Get("include_timezones") == "true"
opts := model.GroupSearchOpts{
Q: c.Params.Q,
IncludeMemberCount: c.Params.IncludeMemberCount,
@@ -986,6 +993,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
FilterParentTeamPermitted: c.Params.FilterParentTeamPermitted,
Source: source,
FilterHasMember: c.Params.FilterHasMember,
IncludeTimezones: includeTimezones,
}
if teamID != "" {
@@ -998,8 +1006,8 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
opts.NotAssociatedToTeam = teamID
}
if channelID != "" {
channel, appErr := c.App.GetChannel(c.AppContext, channelID)
if NotAssociatedToChannelID != "" {
channel, appErr := c.App.GetChannel(c.AppContext, NotAssociatedToChannelID)
if appErr != nil {
c.Err = appErr
return
@@ -1010,11 +1018,30 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
permission = model.PermissionManagePublicChannelMembers
}
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelID, permission) {
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), NotAssociatedToChannelID, permission) {
c.SetPermissionError(permission)
return
}
opts.NotAssociatedToChannel = channelID
opts.NotAssociatedToChannel = NotAssociatedToChannelID
}
if ChannelIDForMemberCount != "" {
channel, appErr := c.App.GetChannel(c.AppContext, ChannelIDForMemberCount)
if appErr != nil {
c.Err = appErr
return
}
var permission *model.Permission
if channel.Type == model.ChannelTypePrivate {
permission = model.PermissionManagePrivateChannelMembers
} else {
permission = model.PermissionManagePublicChannelMembers
}
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), ChannelIDForMemberCount, permission) {
c.SetPermissionError(permission)
return
}
opts.IncludeChannelMemberCount = ChannelIDForMemberCount
}
sinceString := r.URL.Query().Get("since")

Просмотреть файл

@@ -1291,6 +1291,28 @@ func TestGetGroups(t *testing.T) {
assert.Len(t, groups, 1)
assert.Equal(t, groups[0].Id, group2.Id)
// Test IncludeChannelMemberCount url param is working
opts.IncludeChannelMemberCount = th.BasicChannel.Id
opts.IncludeTimezones = true
opts.Q = "-fOo"
opts.IncludeMemberCount = true
groups, _, _ = th.SystemAdminClient.GetGroups(opts)
assert.Equal(t, *groups[0].MemberCount, int(0))
assert.Equal(t, *groups[0].ChannelMemberCount, int(0))
_, appErr = th.App.UpsertGroupMember(group2.Id, th.BasicUser.Id)
assert.Nil(t, appErr)
groups, _, _ = th.SystemAdminClient.GetGroups(opts)
assert.NotNil(t, groups[0].MemberCount)
assert.Equal(t, *groups[0].ChannelMemberCount, int(1))
opts.IncludeChannelMemberCount = ""
opts.IncludeTimezones = false
opts.Q = ""
opts.IncludeMemberCount = false
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.EnableCustomGroups = false
})