summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-10-27 11:04:23 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-27 12:46:31 -0400
commit61da22ea32a71015191e94665171e9703bd39211 (patch)
tree44c236004bade907e5c437f9911a1a090203bf65 /api/channel.go
parent887d205b1fbb3188331a324ba59b7ec187a2d772 (diff)
downloadchat-61da22ea32a71015191e94665171e9703bd39211.tar.gz
chat-61da22ea32a71015191e94665171e9703bd39211.tar.bz2
chat-61da22ea32a71015191e94665171e9703bd39211.zip
Added Channel.Purpose on the server
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/api/channel.go b/api/channel.go
index 10b6e1d0e..44be1cf97 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -23,6 +23,7 @@ func InitChannel(r *mux.Router) {
sr.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST")
sr.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST")
sr.Handle("/update_header", ApiUserRequired(updateChannelHeader)).Methods("POST")
+ sr.Handle("/update_purpose", ApiUserRequired(updateChannelPurpose)).Methods("POST")
sr.Handle("/update_notify_props", ApiUserRequired(updateNotifyProps)).Methods("POST")
sr.Handle("/{id:[A-Za-z0-9]+}/", ApiUserRequiredActivity(getChannel, false)).Methods("GET")
sr.Handle("/{id:[A-Za-z0-9]+}/extra_info", ApiUserRequired(getChannelExtraInfo)).Methods("GET")
@@ -210,6 +211,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
oldChannel.Header = channel.Header
+ oldChannel.Purpose = channel.Purpose
if len(channel.DisplayName) > 0 {
oldChannel.DisplayName = channel.DisplayName
@@ -277,6 +279,49 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
+ props := model.MapFromJson(r.Body)
+ channelId := props["channel_id"]
+ if len(channelId) != 26 {
+ c.SetInvalidParam("updateChannelPurpose", "channel_id")
+ return
+ }
+
+ channelPurpose := props["channel_purpose"]
+ if len(channelPurpose) > 1024 {
+ c.SetInvalidParam("updateChannelPurpose", "channel_purpose")
+ return
+ }
+
+ sc := Srv.Store.Channel().Get(channelId)
+ cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
+
+ if cresult := <-sc; cresult.Err != nil {
+ c.Err = cresult.Err
+ return
+ } else if cmcresult := <-cmc; cmcresult.Err != nil {
+ c.Err = cmcresult.Err
+ return
+ } else {
+ channel := cresult.Data.(*model.Channel)
+ // Don't need to do anything channel member, just wanted to confirm it exists
+
+ if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelPurpose") {
+ return
+ }
+
+ channel.Purpose = channelPurpose
+
+ if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
+ c.Err = ucresult.Err
+ return
+ } else {
+ c.LogAudit("name=" + channel.Name)
+ w.Write([]byte(channel.ToJson()))
+ }
+ }
+}
+
func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team