diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-01-31 07:59:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-31 07:59:36 -0500 |
commit | 7431050b427af88c5e5358bf086176d7a680149b (patch) | |
tree | d75e8bd406086509e032be9b65cb42681393cd92 /api4/team.go | |
parent | 450c0b3ccb091a3f84f35aca0319ba358ffd5633 (diff) | |
download | chat-7431050b427af88c5e5358bf086176d7a680149b.tar.gz chat-7431050b427af88c5e5358bf086176d7a680149b.tar.bz2 chat-7431050b427af88c5e5358bf086176d7a680149b.zip |
Implement POST /teams endpoint (#5220)
Diffstat (limited to 'api4/team.go')
-rw-r--r-- | api4/team.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/api4/team.go b/api4/team.go new file mode 100644 index 000000000..6365ff6de --- /dev/null +++ b/api4/team.go @@ -0,0 +1,42 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api4 + +import ( + "net/http" + + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/app" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func InitTeam() { + l4g.Debug(utils.T("api.team.init.debug")) + + BaseRoutes.Teams.Handle("", ApiSessionRequired(createTeam)).Methods("POST") + +} + +func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { + team := model.TeamFromJson(r.Body) + if team == nil { + c.SetInvalidParam("team") + return + } + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_CREATE_TEAM) { + c.Err = model.NewAppError("createTeam", "api.team.is_team_creation_allowed.disabled.app_error", nil, "", http.StatusForbidden) + return + } + + rteam, err := app.CreateTeamWithUser(team, c.Session.UserId) + if err != nil { + c.Err = err + return + } + + w.WriteHeader(http.StatusCreated) + w.Write([]byte(rteam.ToJson())) +} |