Implement POST /channels endpoint for APIv4 (#5241)

Этот коммит содержится в:
Joram Wilander
2017-02-02 09:04:36 -05:00
коммит произвёл GitHub
родитель 2ac4f36587
Коммит 609d4f43d9
10 изменённых файлов: 309 добавлений и 36 удалений

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

@@ -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