MM-15162: Changes for LDAP groups removals. (#10701)
* MM-15162: Changes for LDAP groups removals phase. * MM-15162: Adds missing translation. * MM-15162: Fixes tests. * MM-15162: Removes some confusing branching. * MM-15162: Make permission less restrictive. * MM-15162: Moves counting to the DB tier. * MM-15162: Moves CountGroupsByTeam into own store method. * MM-15162: Adds count to tests. * MM-15162: Fix for wrong cast type. * MM-15162: Fix for possible null SchemeGuest column. * MM-15162: Fixes bug whereby permissions error didn't return. * MM-15162: Changes for LDAP groups removals phase. * MM-15162: Adds missing translation. * MM-15162: Fixes tests. * MM-15162: Removes some confusing branching. * MM-15162: Make permission less restrictive. * MM-15162: Moves counting to the DB tier. * MM-15162: Moves CountGroupsByTeam into own store method. * MM-15162: Adds count to tests. * MM-15162: Fix for wrong cast type. * MM-15162: Fix for possible null SchemeGuest column. * MM-15162: Fixes bug whereby permissions error didn't return. * MM-15162: Adds missing translation blocking enterprise build. * MM-15162: Update to group commands.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
74c7c46a7d
Коммит
480fffd3cc
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -150,7 +151,14 @@ func TestLinkGroupTeam(t *testing.T) {
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
groupTeam, response := th.SystemAdminClient.LinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
||||
_, response = th.Client.LinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
||||
assert.NotNil(t, response.Error)
|
||||
|
||||
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||
th.Client.Logout()
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
groupTeam, response := th.Client.LinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
|
||||
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
||||
assert.NotNil(t, groupTeam)
|
||||
}
|
||||
@@ -181,8 +189,17 @@ func TestLinkGroupChannel(t *testing.T) {
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
_, response = th.SystemAdminClient.LinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
||||
groupTeam, response := th.Client.LinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
||||
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
||||
assert.NotNil(t, groupTeam)
|
||||
|
||||
_, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
require.Nil(t, response.Error)
|
||||
th.Client.Logout()
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
_, response = th.Client.LinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
||||
assert.NotNil(t, response.Error)
|
||||
}
|
||||
|
||||
func TestUnlinkGroupTeam(t *testing.T) {
|
||||
@@ -218,7 +235,14 @@ func TestUnlinkGroupTeam(t *testing.T) {
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
response = th.SystemAdminClient.UnlinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
||||
response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
||||
assert.NotNil(t, response.Error)
|
||||
|
||||
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||
th.Client.Logout()
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam)
|
||||
CheckOKStatus(t, response)
|
||||
}
|
||||
|
||||
@@ -255,8 +279,21 @@ func TestUnlinkGroupChannel(t *testing.T) {
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
response = th.SystemAdminClient.UnlinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
||||
CheckOKStatus(t, response)
|
||||
_, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
require.Nil(t, response.Error)
|
||||
th.Client.Logout()
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
||||
assert.NotNil(t, response.Error)
|
||||
|
||||
_, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "channel_admin channel_user")
|
||||
require.Nil(t, response.Error)
|
||||
th.Client.Logout()
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel)
|
||||
assert.Nil(t, response.Error)
|
||||
}
|
||||
|
||||
func TestGetGroupTeam(t *testing.T) {
|
||||
@@ -661,24 +698,88 @@ func TestGetGroupsByTeam(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, response := th.SystemAdminClient.GetGroupsByTeam("asdfasdf", 0, 60)
|
||||
opts := model.GroupSearchOpts{
|
||||
PageOpts: &model.PageOpts{
|
||||
Page: 0,
|
||||
PerPage: 60,
|
||||
},
|
||||
}
|
||||
|
||||
_, _, response := th.SystemAdminClient.GetGroupsByTeam("asdfasdf", opts)
|
||||
CheckBadRequestStatus(t, response)
|
||||
|
||||
th.App.SetLicense(nil)
|
||||
|
||||
_, response = th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, 0, 60)
|
||||
_, _, response = th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, opts)
|
||||
CheckNotImplementedStatus(t, response)
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
_, response = th.Client.GetGroupsByTeam(th.BasicTeam.Id, 0, 60)
|
||||
_, _, response = th.Client.GetGroupsByTeam(th.BasicTeam.Id, opts)
|
||||
CheckForbiddenStatus(t, response)
|
||||
|
||||
groups, response := th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, 0, 60)
|
||||
groups, _, response := th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.ElementsMatch(t, []*model.Group{group}, groups)
|
||||
|
||||
groups, response = th.SystemAdminClient.GetGroupsByTeam(model.NewId(), 0, 60)
|
||||
groups, _, response = th.SystemAdminClient.GetGroupsByTeam(model.NewId(), opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.Empty(t, groups)
|
||||
}
|
||||
|
||||
func TestGetGroups(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
group, err := th.App.CreateGroup(&model.Group{
|
||||
DisplayName: "dn-foo_" + id,
|
||||
Name: "name" + id,
|
||||
Source: model.GroupSourceLdap,
|
||||
Description: "description_" + id,
|
||||
RemoteId: model.NewId(),
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
opts := model.GroupSearchOpts{
|
||||
PageOpts: &model.PageOpts{
|
||||
Page: 0,
|
||||
PerPage: 60,
|
||||
},
|
||||
}
|
||||
|
||||
th.App.SetLicense(nil)
|
||||
|
||||
_, response := th.SystemAdminClient.GetGroups(opts)
|
||||
CheckNotImplementedStatus(t, response)
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense("ldap"))
|
||||
|
||||
groups, response := th.SystemAdminClient.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
assert.ElementsMatch(t, []*model.Group{group, th.Group}, groups)
|
||||
assert.Nil(t, groups[0].MemberCount)
|
||||
|
||||
opts.IncludeMemberCount = true
|
||||
groups, _ = th.SystemAdminClient.GetGroups(opts)
|
||||
assert.NotNil(t, groups[0].MemberCount)
|
||||
opts.IncludeMemberCount = false
|
||||
|
||||
opts.Q = "-fOo"
|
||||
groups, _ = th.SystemAdminClient.GetGroups(opts)
|
||||
assert.Len(t, groups, 1)
|
||||
opts.Q = ""
|
||||
|
||||
_, response = th.SystemAdminClient.UpdateTeamMemberRoles(th.BasicTeam.Id, th.BasicUser.Id, "")
|
||||
require.Nil(t, response.Error)
|
||||
|
||||
opts.NotAssociatedToTeam = th.BasicTeam.Id
|
||||
_, response = th.Client.GetGroups(opts)
|
||||
CheckForbiddenStatus(t, response)
|
||||
|
||||
_, response = th.SystemAdminClient.UpdateTeamMemberRoles(th.BasicTeam.Id, th.BasicUser.Id, "team_user")
|
||||
require.Nil(t, response.Error)
|
||||
|
||||
_, response = th.Client.GetGroups(opts)
|
||||
assert.Nil(t, response.Error)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user