MM-25040: Restrict associated groups to channels when team is group-constrained. (#14619)
* MM-25040: Only return team-associated groups if the team is group-constrained. MM-25040: Prevents associating a group to a channel if the team doesn't have the group first. * MM-25040: Fix lints. * MM-25040: Still add the groupteam if the team is not group-constrained. * MM-25040: Wraps groupteam upsert in else branch for efficiency. * MM-25040: Removes unnecessary page iteration. * MM-25040: Fix typo. * MM-25040: Moves filtering to SQL. * MM-25040: Updates tests, check pagination. * MM-25040: Fix lint error. * MM-25040: Adds some more group store tests. * MM-25040: Fix for wrong test parameter.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c9cdeba1a7
Коммит
c529d5190a
@@ -717,9 +717,10 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
opts := model.GroupSearchOpts{
|
||||
Q: c.Params.Q,
|
||||
IncludeMemberCount: c.Params.IncludeMemberCount,
|
||||
FilterAllowReference: c.Params.FilterAllowReference,
|
||||
Q: c.Params.Q,
|
||||
IncludeMemberCount: c.Params.IncludeMemberCount,
|
||||
FilterAllowReference: c.Params.FilterAllowReference,
|
||||
FilterParentTeamPermitted: c.Params.FilterParentTeamPermitted,
|
||||
}
|
||||
|
||||
if teamID != "" {
|
||||
|
||||
@@ -1007,3 +1007,86 @@ func TestGetGroupsByUserId(t *testing.T) {
|
||||
assert.ElementsMatch(t, []*model.Group{group1, group2}, groups)
|
||||
|
||||
}
|
||||
|
||||
func TestGetGroupsGroupConstrainedParentTeam(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
var groups []*model.Group
|
||||
for i := 0; i < 4; i++ {
|
||||
id := model.NewId()
|
||||
group, err := th.App.CreateGroup(&model.Group{
|
||||
DisplayName: fmt.Sprintf("dn-foo_%d", i),
|
||||
Name: model.NewString("name" + id),
|
||||
Source: model.GroupSourceLdap,
|
||||
Description: "description_" + id,
|
||||
RemoteId: model.NewId(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
groups = append(groups, group)
|
||||
}
|
||||
|
||||
team := th.CreateTeam()
|
||||
|
||||
id := model.NewId()
|
||||
channel := &model.Channel{
|
||||
DisplayName: "dn_" + id,
|
||||
Name: "name" + id,
|
||||
Type: model.CHANNEL_PRIVATE,
|
||||
TeamId: team.Id,
|
||||
GroupConstrained: model.NewBool(true),
|
||||
}
|
||||
channel, err := th.App.CreateChannel(channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
// normal result of groups are returned if the team is not group-constrained
|
||||
apiGroups, response := th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id})
|
||||
require.Nil(t, response.Error)
|
||||
require.Contains(t, apiGroups, groups[0])
|
||||
require.Contains(t, apiGroups, groups[1])
|
||||
require.Contains(t, apiGroups, groups[2])
|
||||
|
||||
team.GroupConstrained = model.NewBool(true)
|
||||
team, err = th.App.UpdateTeam(team)
|
||||
require.Nil(t, err)
|
||||
|
||||
// team is group-constrained but has no associated groups
|
||||
apiGroups, response = th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true})
|
||||
require.Nil(t, response.Error)
|
||||
require.Len(t, apiGroups, 0)
|
||||
|
||||
for _, group := range []*model.Group{groups[0], groups[2], groups[3]} {
|
||||
_, err = th.App.UpsertGroupSyncable(model.NewGroupTeam(group.Id, team.Id, false))
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// set of the teams groups are returned
|
||||
apiGroups, response = th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true})
|
||||
require.Nil(t, response.Error)
|
||||
require.Contains(t, apiGroups, groups[0])
|
||||
require.NotContains(t, apiGroups, groups[1])
|
||||
require.Contains(t, apiGroups, groups[2])
|
||||
|
||||
// paged results function as expected
|
||||
apiGroups, response = th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true, PageOpts: &model.PageOpts{PerPage: 2, Page: 0}})
|
||||
require.Nil(t, response.Error)
|
||||
require.Len(t, apiGroups, 2)
|
||||
require.Equal(t, apiGroups[0].Id, groups[0].Id)
|
||||
require.Equal(t, apiGroups[1].Id, groups[2].Id)
|
||||
|
||||
apiGroups, response = th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id, FilterParentTeamPermitted: true, PageOpts: &model.PageOpts{PerPage: 2, Page: 1}})
|
||||
require.Nil(t, response.Error)
|
||||
require.Len(t, apiGroups, 1)
|
||||
require.Equal(t, apiGroups[0].Id, groups[3].Id)
|
||||
|
||||
_, err = th.App.UpsertGroupSyncable(model.NewGroupChannel(groups[0].Id, channel.Id, false))
|
||||
require.Nil(t, err)
|
||||
|
||||
// as usual it doesn't return groups already associated to the channel
|
||||
apiGroups, response = th.SystemAdminClient.GetGroups(model.GroupSearchOpts{NotAssociatedToChannel: channel.Id})
|
||||
require.Nil(t, response.Error)
|
||||
require.NotContains(t, apiGroups, groups[0])
|
||||
require.Contains(t, apiGroups, groups[2])
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user