Endpoint for APIv4: GET /team/{team_id}/channels (#5681)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
3559fb7959
Коммит
8731465957
@@ -18,6 +18,8 @@ func InitChannel() {
|
||||
BaseRoutes.Channels.Handle("", ApiSessionRequired(createChannel)).Methods("POST")
|
||||
BaseRoutes.Channels.Handle("/direct", ApiSessionRequired(createDirectChannel)).Methods("POST")
|
||||
|
||||
BaseRoutes.Team.Handle("/channels", ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET")
|
||||
|
||||
BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET")
|
||||
BaseRoutes.ChannelByName.Handle("", ApiSessionRequired(getChannelByName)).Methods("GET")
|
||||
BaseRoutes.ChannelByNameForTeamName.Handle("", ApiSessionRequired(getChannelByNameForTeamName)).Methods("GET")
|
||||
@@ -115,6 +117,26 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS)
|
||||
return
|
||||
}
|
||||
|
||||
if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(channels.ToJson()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId().RequireChannelName()
|
||||
if c.Err != nil {
|
||||
|
||||
@@ -254,6 +254,86 @@ func TestGetChannel(t *testing.T) {
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestGetPublicChannelsForTeam(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
team := th.BasicTeam
|
||||
publicChannel1 := th.BasicChannel
|
||||
publicChannel2 := th.BasicChannel2
|
||||
|
||||
channels, resp := Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(*channels) != 4 {
|
||||
t.Fatal("wrong length")
|
||||
}
|
||||
|
||||
for i, c := range *channels {
|
||||
if c.Type != model.CHANNEL_OPEN {
|
||||
t.Fatal("should include open channel only")
|
||||
}
|
||||
|
||||
// only check the created 2 public channels
|
||||
if i < 2 && !(c.DisplayName == publicChannel1.DisplayName || c.DisplayName == publicChannel2.DisplayName) {
|
||||
t.Logf("channel %v: %v", i, c.DisplayName)
|
||||
t.Fatal("should match public channel display name only")
|
||||
}
|
||||
}
|
||||
|
||||
privateChannel := th.CreatePrivateChannel()
|
||||
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(*channels) != 4 {
|
||||
t.Fatal("wrong length")
|
||||
}
|
||||
|
||||
for _, c := range *channels {
|
||||
if c.Type != model.CHANNEL_OPEN {
|
||||
t.Fatal("should not include private channel")
|
||||
}
|
||||
|
||||
if c.DisplayName == privateChannel.DisplayName {
|
||||
t.Fatal("should not match private channel display name")
|
||||
}
|
||||
}
|
||||
|
||||
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(*channels) != 1 {
|
||||
t.Fatal("should be one channel per page")
|
||||
}
|
||||
|
||||
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 1, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(*channels) != 1 {
|
||||
t.Fatal("should be one channel per page")
|
||||
}
|
||||
|
||||
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 10000, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(*channels) != 0 {
|
||||
t.Fatal("should be no channel")
|
||||
}
|
||||
|
||||
_, resp = Client.GetPublicChannelsForTeam("junk", 0, 100, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetPublicChannelsForTeam(model.NewId(), 0, 100, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
user := th.CreateUser()
|
||||
Client.Login(user.Email, user.Password)
|
||||
_, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetPublicChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestGetChannelByName(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user