From 5c29d4f64935d0516e9d72d1d8cc734bcf295a87 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Tue, 8 Mar 2016 12:27:27 -0500 Subject: Deleting posts with files now renames the file so that public links to those files no longer work --- api/post.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index e6560a8e8..cd78b16f0 100644 --- a/api/post.go +++ b/api/post.go @@ -1094,6 +1094,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { message.Add("post", post.ToJson()) PublishAndForget(message) + DeletePostFilesAndForget(c.Session.TeamId, post) result := make(map[string]string) result["id"] = postId @@ -1101,6 +1102,23 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { } } +func DeletePostFilesAndForget(teamId string, post *model.Post) { + go func() { + if len(post.Filenames) == 0 { + return + } + + prefix := "teams/" + teamId + "/channels/" + post.ChannelId + "/users/" + post.UserId + "/" + for _, filename := range post.Filenames { + splitUrl := strings.Split(filename, "/") + oldPath := prefix + splitUrl[len(splitUrl)-2] + "/" + splitUrl[len(splitUrl)-1] + newPath := prefix + splitUrl[len(splitUrl)-2] + "/deleted_" + splitUrl[len(splitUrl)-1] + moveFile(oldPath, newPath) + } + + }() +} + func getPostsBefore(c *Context, w http.ResponseWriter, r *http.Request) { getPostsBeforeOrAfter(c, w, r, true) } -- cgit v1.2.3-1-g7c22