summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-02 09:04:36 -0500
committerGitHub <noreply@github.com>2017-02-02 09:04:36 -0500
commit609d4f43d9eef504d852fbf02af5473b0d1424c8 (patch)
tree63fe24f08d5364501d3afed7c44b6739719d86e3 /app
parent2ac4f36587b8b217dcfd53e67c650c8ad27c75df (diff)
downloadchat-609d4f43d9eef504d852fbf02af5473b0d1424c8.tar.gz
chat-609d4f43d9eef504d852fbf02af5473b0d1424c8.tar.bz2
chat-609d4f43d9eef504d852fbf02af5473b0d1424c8.zip
Implement POST /channels endpoint for APIv4 (#5241)
Diffstat (limited to 'app')
-rw-r--r--app/channel.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 818e241b7..aba65143b 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -6,6 +6,7 @@ package app
import (
"fmt"
"net/http"
+ "strings"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
@@ -129,6 +130,38 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m
return err
}
+func CreateChannelWithUser(channel *model.Channel, userId string) (*model.Channel, *model.AppError) {
+ if channel.Type == model.CHANNEL_DIRECT {
+ return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.direct_channel.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if strings.Index(channel.Name, "__") > 0 {
+ return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.invalid_character.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(channel.TeamId) == 0 {
+ return nil, model.NewAppError("CreateChannelWithUser", "app.channel.create_channel.no_team_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ // Get total number of channels on current team
+ if count, err := GetNumberOfChannelsOnTeam(channel.TeamId); err != nil {
+ return nil, err
+ } else {
+ if int64(count+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
+ return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *utils.Cfg.TeamSettings.MaxChannelsPerTeam}, "", http.StatusBadRequest)
+ }
+ }
+
+ channel.CreatorId = userId
+
+ rchannel, err := CreateChannel(channel, true)
+ if err != nil {
+ return nil, err
+ }
+
+ return rchannel, nil
+}
+
func CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
return nil, result.Err