From 609d4f43d9eef504d852fbf02af5473b0d1424c8 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 2 Feb 2017 09:04:36 -0500 Subject: Implement POST /channels endpoint for APIv4 (#5241) --- api/channel.go | 31 +------------------------------ api/channel_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 32 deletions(-) (limited to 'api') diff --git a/api/channel.go b/api/channel.go index c5ec36d4b..33e083f14 100644 --- a/api/channel.go +++ b/api/channel.go @@ -6,7 +6,6 @@ package api import ( "net/http" "strconv" - "strings" l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" @@ -48,9 +47,7 @@ func InitChannel() { } func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { - channel := model.ChannelFromJson(r.Body) - if channel == nil { c.SetInvalidParam("createChannel", "channel") return @@ -60,16 +57,6 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { channel.TeamId = c.TeamId } - if channel.Type == model.CHANNEL_DIRECT { - c.Err = model.NewLocAppError("createDirectChannel", "api.channel.create_channel.direct_channel.app_error", nil, "") - return - } - - if strings.Index(channel.Name, "__") > 0 { - c.Err = model.NewLocAppError("createDirectChannel", "api.channel.create_channel.invalid_character.app_error", nil, "") - return - } - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_PUBLIC_CHANNEL) { c.SetPermissionError(model.PERMISSION_CREATE_PUBLIC_CHANNEL) return @@ -80,23 +67,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if channel.TeamId == c.TeamId { - - // Get total number of channels on current team - if count, err := app.GetNumberOfChannelsOnTeam(channel.TeamId); err != nil { - c.Err = model.NewLocAppError("createChannel", "api.channel.get_channels.error", nil, err.Error()) - return - } else { - if int64(count+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam { - c.Err = model.NewLocAppError("createChannel", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *utils.Cfg.TeamSettings.MaxChannelsPerTeam}, "") - return - } - } - } - - channel.CreatorId = c.Session.UserId - - if sc, err := app.CreateChannel(channel, true); err != nil { + if sc, err := app.CreateChannelWithUser(channel, c.Session.UserId); err != nil { c.Err = err return } else { diff --git a/api/channel_test.go b/api/channel_test.go index 450c5556e..6e6883047 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -55,7 +55,7 @@ func TestCreateChannel(t *testing.T) { rchannel.Data.(*model.Channel).Id = "" if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err != nil { - if err.Message != "A channel with that URL already exists" { + if err.Id != "store.sql_channel.save_channel.exists.app_error" { t.Fatal(err) } } @@ -1768,7 +1768,9 @@ func TestAutocompleteChannels(t *testing.T) { channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) channel3 := &model.Channel{DisplayName: "BadChannelC", Name: "c" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: model.NewId()} - channel3 = th.SystemAdminClient.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel) + if _, err := th.SystemAdminClient.CreateChannel(channel3); err == nil { + t.Fatal("channel must have valid team id") + } channel4 := &model.Channel{DisplayName: "BadChannelD", Name: "d" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} channel4 = Client.Must(Client.CreateChannel(channel4)).Data.(*model.Channel) -- cgit v1.2.3-1-g7c22