diff --git a/api4/api.go b/api4/api.go index 4acb5525f5..1d06cecf1f 100644 --- a/api4/api.go +++ b/api4/api.go @@ -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)) diff --git a/api4/group_local.go b/api4/group_local.go new file mode 100644 index 0000000000..03ab55c490 --- /dev/null +++ b/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") +} diff --git a/api4/group_test.go b/api4/group_test.go index e87312ff46..ca1f457fb4 100644 --- a/api4/group_test.go +++ b/api4/group_test.go @@ -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) {