diff options
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/api4/post.go b/api4/post.go index ea23e098b..eaa910502 100644 --- a/api4/post.go +++ b/api4/post.go @@ -42,9 +42,9 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { post.UserId = c.Session.UserId hasPermission := false - if app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) { + if c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) { hasPermission = true - } else if channel, err := app.GetChannel(post.ChannelId); err == nil { + } else if channel, err := c.App.GetChannel(post.ChannelId); err == nil { // Temporary permission check method until advanced permissions, please do not copy if channel.Type == model.CHANNEL_OPEN && app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_POST_PUBLIC) { hasPermission = true @@ -60,13 +60,13 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { post.CreateAt = 0 } - rp, err := app.CreatePostAsUser(post) + rp, err := c.App.CreatePostAsUser(post) if err != nil { c.Err = err return } - app.SetStatusOnline(c.Session.UserId, c.Session.Id, false) + c.App.SetStatusOnline(c.Session.UserId, c.Session.Id, false) w.WriteHeader(http.StatusCreated) w.Write([]byte(rp.ToJson())) @@ -93,7 +93,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { } } - if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -103,31 +103,31 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { etag := "" if since > 0 { - list, err = app.GetPostsSince(c.Params.ChannelId, since) + list, err = c.App.GetPostsSince(c.Params.ChannelId, since) } else if len(afterPost) > 0 { - etag = app.GetPostsEtag(c.Params.ChannelId) + etag = c.App.GetPostsEtag(c.Params.ChannelId) if HandleEtag(etag, "Get Posts After", w, r) { return } - list, err = app.GetPostsAfterPost(c.Params.ChannelId, afterPost, c.Params.Page, c.Params.PerPage) + list, err = c.App.GetPostsAfterPost(c.Params.ChannelId, afterPost, c.Params.Page, c.Params.PerPage) } else if len(beforePost) > 0 { - etag = app.GetPostsEtag(c.Params.ChannelId) + etag = c.App.GetPostsEtag(c.Params.ChannelId) if HandleEtag(etag, "Get Posts Before", w, r) { return } - list, err = app.GetPostsBeforePost(c.Params.ChannelId, beforePost, c.Params.Page, c.Params.PerPage) + list, err = c.App.GetPostsBeforePost(c.Params.ChannelId, beforePost, c.Params.Page, c.Params.PerPage) } else { - etag = app.GetPostsEtag(c.Params.ChannelId) + etag = c.App.GetPostsEtag(c.Params.ChannelId) if HandleEtag(etag, "Get Posts", w, r) { return } - list, err = app.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage) + list, err = c.App.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage) } if err != nil { @@ -159,11 +159,11 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request) var err *model.AppError if len(channelId) > 0 { - posts, err = app.GetFlaggedPostsForChannel(c.Params.UserId, channelId, c.Params.Page, c.Params.PerPage) + posts, err = c.App.GetFlaggedPostsForChannel(c.Params.UserId, channelId, c.Params.Page, c.Params.PerPage) } else if len(teamId) > 0 { - posts, err = app.GetFlaggedPostsForTeam(c.Params.UserId, teamId, c.Params.Page, c.Params.PerPage) + posts, err = c.App.GetFlaggedPostsForTeam(c.Params.UserId, teamId, c.Params.Page, c.Params.PerPage) } else { - posts, err = app.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage) + posts, err = c.App.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage) } if err != nil { @@ -182,18 +182,18 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) { var post *model.Post var err *model.AppError - if post, err = app.GetSinglePost(c.Params.PostId); err != nil { + if post, err = c.App.GetSinglePost(c.Params.PostId); err != nil { c.Err = err return } var channel *model.Channel - if channel, err = app.GetChannel(post.ChannelId); err != nil { + if channel, err = c.App.GetChannel(post.ChannelId); err != nil { c.Err = err return } - if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { if channel.Type == model.CHANNEL_OPEN { if !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL) @@ -219,12 +219,12 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_DELETE_OTHERS_POSTS) { + if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_DELETE_OTHERS_POSTS) { c.SetPermissionError(model.PERMISSION_DELETE_OTHERS_POSTS) return } - if _, err := app.DeletePost(c.Params.PostId); err != nil { + if _, err := c.App.DeletePost(c.Params.PostId); err != nil { c.Err = err return } @@ -240,7 +240,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) { var list *model.PostList var err *model.AppError - if list, err = app.GetPostThread(c.Params.PostId); err != nil { + if list, err = c.App.GetPostThread(c.Params.PostId); err != nil { c.Err = err return } @@ -254,12 +254,12 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) { } var channel *model.Channel - if channel, err = app.GetChannel(post.ChannelId); err != nil { + if channel, err = c.App.GetChannel(post.ChannelId); err != nil { c.Err = err return } - if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { if channel.Type == model.CHANNEL_OPEN { if !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL) @@ -299,7 +299,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { isOrSearch, _ := props["is_or_search"].(bool) - posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch) + posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch) if err != nil { c.Err = err return @@ -322,19 +322,19 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { c.SetPermissionError(model.PERMISSION_EDIT_POST) return } - if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) { + if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) { c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS) return } post.Id = c.Params.PostId - rpost, err := app.UpdatePost(post, false) + rpost, err := c.App.UpdatePost(post, false) if err != nil { c.Err = err return @@ -356,17 +356,17 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { c.SetPermissionError(model.PERMISSION_EDIT_POST) return } - if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) { + if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) { c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS) return } - patchedPost, err := app.PatchPost(c.Params.PostId, post) + patchedPost, err := c.App.PatchPost(c.Params.PostId, post) if err != nil { c.Err = err return @@ -381,7 +381,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn return } - if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -390,7 +390,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn patch.IsPinned = new(bool) *patch.IsPinned = isPinned - _, err := app.PatchPost(c.Params.PostId, patch) + _, err := c.App.PatchPost(c.Params.PostId, patch) if err != nil { c.Err = err return @@ -413,12 +413,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if infos, err := app.GetFileInfosForPost(c.Params.PostId, false); err != nil { + if infos, err := c.App.GetFileInfosForPost(c.Params.PostId, false); err != nil { c.Err = err return } else if HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) { @@ -436,12 +436,12 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if err := app.DoPostAction(c.Params.PostId, c.Params.ActionId, c.Session.UserId); err != nil { + if err := c.App.DoPostAction(c.Params.PostId, c.Params.ActionId, c.Session.UserId); err != nil { c.Err = err return } |