diff options
Diffstat (limited to 'api/post.go')
-rw-r--r-- | api/post.go | 82 |
1 files changed, 7 insertions, 75 deletions
diff --git a/api/post.go b/api/post.go index 5363fdf79..0379f6af5 100644 --- a/api/post.go +++ b/api/post.go @@ -25,7 +25,6 @@ func InitPost(r *mux.Router) { sr := r.PathPrefix("/channels/{id:[A-Za-z0-9]+}").Subrouter() sr.Handle("/create", ApiUserRequired(createPost)).Methods("POST") - sr.Handle("/valet_create", ApiUserRequired(createValetPost)).Methods("POST") sr.Handle("/update", ApiUserRequired(updatePost)).Methods("POST") sr.Handle("/posts/{offset:[0-9]+}/{limit:[0-9]+}", ApiUserRequiredActivity(getPosts, false)).Methods("GET") sr.Handle("/posts/{time:[0-9]+}", ApiUserRequiredActivity(getPostsSince, false)).Methods("GET") @@ -60,75 +59,6 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { } } -func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) { - tchan := Srv.Store.Team().Get(c.Session.TeamId) - - post := model.PostFromJson(r.Body) - if post == nil { - c.SetInvalidParam("createValetPost", "post") - return - } - - cchan := Srv.Store.Channel().CheckOpenChannelPermissions(c.Session.TeamId, post.ChannelId) - - // Any one with access to the team can post as valet to any open channel - if !c.HasPermissionsToChannel(cchan, "createValetPost") { - return - } - - // Make sure this team has the valet feature enabled - if tResult := <-tchan; tResult.Err != nil { - c.Err = model.NewAppError("createValetPost", "Could not find the team for this session, team_id="+c.Session.TeamId, "") - return - } else { - if !tResult.Data.(*model.Team).AllowValet { - c.Err = model.NewAppError("createValetPost", "The valet feature is currently turned off. Please contact your team administrator for details.", "") - c.Err.StatusCode = http.StatusNotImplemented - return - } - } - - if rp, err := CreateValetPost(c, post); err != nil { - c.Err = err - - if strings.Contains(c.Err.Message, "parameter") { - c.Err.StatusCode = http.StatusBadRequest - } - - return - } else { - w.Write([]byte(rp.ToJson())) - } -} - -func CreateValetPost(c *Context, post *model.Post) (*model.Post, *model.AppError) { - post.Hashtags, _ = model.ParseHashtags(post.Message) - - post.Filenames = []string{} // no files allowed in valet posts yet - - if result := <-Srv.Store.User().GetByUsername(c.Session.TeamId, "valet"); result.Err != nil { - // if the bot doesn't exist, create it - if tresult := <-Srv.Store.Team().Get(c.Session.TeamId); tresult.Err != nil { - return nil, tresult.Err - } else { - post.UserId = (CreateValet(c, tresult.Data.(*model.Team))).Id - } - } else { - post.UserId = result.Data.(*model.User).Id - } - - var rpost *model.Post - if result := <-Srv.Store.Post().Save(post); result.Err != nil { - return nil, result.Err - } else { - rpost = result.Data.(*model.Post) - } - - fireAndForgetNotifications(rpost, c.Session.TeamId, c.GetSiteURL()) - - return rpost, nil -} - func CreatePost(c *Context, post *model.Post, doUpdateLastViewed bool) (*model.Post, *model.AppError) { var pchan store.StoreChannel if len(post.RootId) > 0 { @@ -230,7 +160,7 @@ func fireAndForgetNotifications(post *model.Post, teamId, siteURL string) { channel = result.Data.(*model.Channel) if channel.Type == model.CHANNEL_DIRECT { bodyText = "You have one new message." - subjectText = "New Private Message" + subjectText = "New Direct Message" } else { bodyText = "You have one new mention." subjectText = "New Mention" @@ -353,7 +283,7 @@ func fireAndForgetNotifications(post *model.Post, teamId, siteURL string) { } } - for id, _ := range toEmailMap { + for id := range toEmailMap { fireAndForgetMentionUpdate(post.ChannelId, id) } } @@ -378,7 +308,8 @@ func fireAndForgetNotifications(post *model.Post, teamId, siteURL string) { location, _ := time.LoadLocation("UTC") tm := time.Unix(post.CreateAt/1000, 0).In(location) - subjectPage := NewServerTemplatePage("post_subject", siteURL) + subjectPage := NewServerTemplatePage("post_subject") + subjectPage.Props["SiteURL"] = siteURL subjectPage.Props["TeamDisplayName"] = teamDisplayName subjectPage.Props["SubjectText"] = subjectText subjectPage.Props["Month"] = tm.Month().String()[:3] @@ -396,7 +327,8 @@ func fireAndForgetNotifications(post *model.Post, teamId, siteURL string) { continue } - bodyPage := NewServerTemplatePage("post_body", siteURL) + bodyPage := NewServerTemplatePage("post_body") + bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["Nickname"] = profileMap[id].FirstName bodyPage.Props["TeamDisplayName"] = teamDisplayName bodyPage.Props["ChannelName"] = channelName @@ -716,7 +648,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if post.UserId != c.Session.UserId && !strings.Contains(c.Session.Roles, model.ROLE_ADMIN) { + if post.UserId != c.Session.UserId && !model.IsInRole(c.Session.Roles, model.ROLE_TEAM_ADMIN) { c.Err = model.NewAppError("deletePost", "You do not have the appropriate permissions", "") c.Err.StatusCode = http.StatusForbidden return |