MM-23596: Ability to list private channels for team (#14925)

Summary:
store, app, api and go driver support for listing private channels

Ticket Link:
https://mattermost.atlassian.net/browse/MM-23596
Этот коммит содержится в:
Ashish Bhate
2020-07-06 12:34:29 +05:30
коммит произвёл GitHub
родитель a4fc0fcfb7
Коммит af8b914c6c
15 изменённых файлов: 315 добавлений и 0 удалений

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

@@ -27,6 +27,7 @@ func (api *API) InitChannel() {
api.BaseRoutes.ChannelsForTeam.Handle("", api.ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/deleted", api.ApiSessionRequired(getDeletedChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/private", api.ApiSessionRequired(getPrivateChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/ids", api.ApiSessionRequired(getPublicChannelsByIdsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/search", api.ApiSessionRequiredDisableWhenBusy(searchChannelsForTeam)).Methods("POST")
api.BaseRoutes.ChannelsForTeam.Handle("/search_archived", api.ApiSessionRequiredDisableWhenBusy(searchArchivedChannelsForTeam)).Methods("POST")
@@ -763,6 +764,32 @@ func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Reques
w.Write([]byte(channels.ToJson()))
}
func getPrivateChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {
return
}
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
channels, err := c.App.GetPrivateChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage)
if err != nil {
c.Err = err
return
}
err = c.App.FillInChannelsProps(channels)
if err != nil {
c.Err = err
return
}
w.Write([]byte(channels.ToJson()))
}
func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {

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

@@ -24,6 +24,7 @@ func (api *API) InitChannelLocal() {
api.BaseRoutes.ChannelsForTeam.Handle("", api.ApiLocal(getPublicChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/deleted", api.ApiLocal(getDeletedChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelsForTeam.Handle("/private", api.ApiLocal(getPrivateChannelsForTeam)).Methods("GET")
api.BaseRoutes.ChannelByName.Handle("", api.ApiLocal(getChannelByName)).Methods("GET")
api.BaseRoutes.ChannelByNameForTeamName.Handle("", api.ApiLocal(getChannelByNameForTeamName)).Methods("GET")

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

@@ -735,6 +735,42 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
require.Len(t, channels, 1, "should be one channel per page")
}
func TestGetPrivateChannelsForTeam(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
team := th.BasicTeam
// normal user
_, resp := th.Client.GetPrivateChannelsForTeam(team.Id, 0, 100, "")
CheckForbiddenStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
channels, resp := c.GetPrivateChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
// th.BasicPrivateChannel and th.BasicPrivateChannel2
require.Len(t, channels, 2, "wrong number of private channels")
for _, c := range channels {
// check all channels included are private
require.Equal(t, model.CHANNEL_PRIVATE, c.Type, "should include private channels only")
}
channels, resp = c.GetPrivateChannelsForTeam(team.Id, 0, 1, "")
CheckNoError(t, resp)
require.Len(t, channels, 1, "should be one channel per page")
channels, resp = c.GetPrivateChannelsForTeam(team.Id, 1, 1, "")
CheckNoError(t, resp)
require.Len(t, channels, 1, "should be one channel per page")
channels, resp = c.GetPrivateChannelsForTeam(team.Id, 10000, 100, "")
CheckNoError(t, resp)
require.Empty(t, channels, "should be no channel")
_, resp = c.GetPrivateChannelsForTeam("junk", 0, 100, "")
CheckBadRequestStatus(t, resp)
})
}
func TestGetPublicChannelsForTeam(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()