func join(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelId := params["channel_id"] channelName := params["channel_name"] var channel *model.Channel var err *model.AppError if channelId != "" { channel, err = app.GetChannel(channelId) } else if channelName != "" { channel, err = app.GetChannelByName(channelName, c.TeamId) } else { c.SetInvalidParam("join", "channel_id, channel_name") return } if err != nil { c.Err = err return } if channel.Type == model.CHANNEL_OPEN { if !HasPermissionToTeamContext(c, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { return } } if err = app.JoinChannel(channel, c.Session.UserId); err != nil { c.Err = err return } w.Write([]byte(channel.ToJson())) }
func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) postId := params["post_id"] if len(postId) != 26 { c.SetInvalidParam("getPermalinkTmp", "postId") return } if result := <-app.Srv.Store.Post().Get(postId); result.Err != nil { c.Err = result.Err return } else { list := result.Data.(*model.PostList) if len(list.Order) != 1 { c.Err = model.NewLocAppError("getPermalinkTmp", "api.post_get_post_by_id.get.app_error", nil, "") return } post := list.Posts[list.Order[0]] var channel *model.Channel var err *model.AppError if channel, err = app.GetChannel(post.ChannelId); err != nil { c.Err = err return } if !HasPermissionToTeamContext(c, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { return } if err = app.JoinChannel(channel, c.Session.UserId); err != nil { c.Err = err return } if HandleEtag(list.Etag(), "Get Permalink TMP", w, r) { return } w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag()) w.Write([]byte(list.ToJson())) } }