MM-25073/MM-25074: local mode for getGroupsByChannel and getGroupsByTeam (#14668)

* local mode for getGroupsByChannel

* local mode for getGroupsByTeam
Этот коммит содержится в:
Ashish Bhate
2020-06-01 15:31:05 +05:30
коммит произвёл GitHub
родитель 2af00f73c0
Коммит 8d4da8b968
3 изменённых файлов: 65 добавлений и 37 удалений

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

@@ -287,12 +287,15 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app.
api.BaseRoutes.License = api.BaseRoutes.ApiRoot.PathPrefix("/license").Subrouter()
api.BaseRoutes.Groups = api.BaseRoutes.ApiRoot.PathPrefix("/groups").Subrouter()
api.InitTeamLocal()
api.InitChannelLocal()
api.InitLicenseLocal()
api.InitConfigLocal()
api.InitCommandLocal()
api.InitPluginLocal()
api.InitGroupLocal()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))

9
api4/group_local.go Обычный файл
Просмотреть файл

@@ -0,0 +1,9 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
func (api *API) InitGroupLocal() {
api.BaseRoutes.Channels.Handle("/{channel_id:[A-Za-z0-9]+}/groups", api.ApiLocal(getGroupsByChannel)).Methods("GET")
api.BaseRoutes.Teams.Handle("/{team_id:[A-Za-z0-9]+}/groups", api.ApiLocal(getGroupsByTeam)).Methods("GET")
}

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

@@ -673,42 +673,50 @@ func TestGetGroupsByChannel(t *testing.T) {
},
}
_, _, response := th.SystemAdminClient.GetGroupsByChannel("asdfasdf", opts)
CheckBadRequestStatus(t, response)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, _, response := client.GetGroupsByChannel("asdfasdf", opts)
CheckBadRequestStatus(t, response)
})
th.App.SetLicense(nil)
_, _, response = th.SystemAdminClient.GetGroupsByChannel(th.BasicChannel.Id, opts)
CheckNotImplementedStatus(t, response)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, _, response := client.GetGroupsByChannel(th.BasicChannel.Id, opts)
CheckNotImplementedStatus(t, response)
})
th.App.SetLicense(model.NewTestLicense("ldap"))
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
_, _, response = th.Client.GetGroupsByChannel(privateChannel.Id, opts)
_, _, response := th.Client.GetGroupsByChannel(privateChannel.Id, opts)
CheckForbiddenStatus(t, response)
groups, _, response := th.SystemAdminClient.GetGroupsByChannel(th.BasicChannel.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.False(t, *groups[0].SchemeAdmin)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
groups, _, response := client.GetGroupsByChannel(th.BasicChannel.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.False(t, *groups[0].SchemeAdmin)
})
// set syncable to true
groupSyncable.SchemeAdmin = true
_, err = th.App.UpdateGroupSyncable(groupSyncable)
require.Nil(t, err)
// ensure that SchemeAdmin field is updated
groups, _, response = th.SystemAdminClient.GetGroupsByChannel(th.BasicChannel.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.True(t, *groups[0].SchemeAdmin)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
groups, _, response := client.GetGroupsByChannel(th.BasicChannel.Id, opts)
assert.Nil(t, response.Error)
// ensure that SchemeAdmin field is updated
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.True(t, *groups[0].SchemeAdmin)
groups, _, response = th.SystemAdminClient.GetGroupsByChannel(model.NewId(), opts)
assert.Equal(t, "store.sql_channel.get.existing.app_error", response.Error.Id)
assert.Empty(t, groups)
groups, _, response = client.GetGroupsByChannel(model.NewId(), opts)
assert.Equal(t, "store.sql_channel.get.existing.app_error", response.Error.Id)
assert.Empty(t, groups)
})
}
func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) {
@@ -814,37 +822,45 @@ func TestGetGroupsByTeam(t *testing.T) {
},
}
_, _, response := th.SystemAdminClient.GetGroupsByTeam("asdfasdf", opts)
CheckBadRequestStatus(t, response)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, _, response := client.GetGroupsByTeam("asdfasdf", opts)
CheckBadRequestStatus(t, response)
})
th.App.SetLicense(nil)
_, _, response = th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, opts)
CheckNotImplementedStatus(t, response)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, _, response := client.GetGroupsByTeam(th.BasicTeam.Id, opts)
CheckNotImplementedStatus(t, response)
})
th.App.SetLicense(model.NewTestLicense("ldap"))
groups, _, response := th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.False(t, *groups[0].SchemeAdmin)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
groups, _, response := client.GetGroupsByTeam(th.BasicTeam.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(false)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.False(t, *groups[0].SchemeAdmin)
})
// set syncable to true
groupSyncable.SchemeAdmin = true
_, err = th.App.UpdateGroupSyncable(groupSyncable)
require.Nil(t, err)
// ensure that SchemeAdmin field is updated
groups, _, response = th.SystemAdminClient.GetGroupsByTeam(th.BasicTeam.Id, opts)
assert.Nil(t, response.Error)
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.True(t, *groups[0].SchemeAdmin)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
groups, _, response := client.GetGroupsByTeam(th.BasicTeam.Id, opts)
assert.Nil(t, response.Error)
// ensure that SchemeAdmin field is updated
assert.ElementsMatch(t, []*model.GroupWithSchemeAdmin{{Group: *group, SchemeAdmin: model.NewBool(true)}}, groups)
require.NotNil(t, groups[0].SchemeAdmin)
require.True(t, *groups[0].SchemeAdmin)
groups, _, response = th.SystemAdminClient.GetGroupsByTeam(model.NewId(), opts)
assert.Nil(t, response.Error)
assert.Empty(t, groups)
groups, _, response = client.GetGroupsByTeam(model.NewId(), opts)
assert.Nil(t, response.Error)
assert.Empty(t, groups)
})
}
func TestGetGroups(t *testing.T) {