summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-03-08 12:10:31 -0800
committerCorey Hulen <corey@hulen.com>2016-03-08 12:10:31 -0800
commita1ec47eb780f6d244d1d3d50e6078f907e8b7fd7 (patch)
tree4c46ed31fff46c4b1adc0b29c3c90157348920d9 /api/post.go
parentcbf84c8beaa0896daaf82ecdb63f236da4d64c0e (diff)
parent5c29d4f64935d0516e9d72d1d8cc734bcf295a87 (diff)
downloadchat-a1ec47eb780f6d244d1d3d50e6078f907e8b7fd7.tar.gz
chat-a1ec47eb780f6d244d1d3d50e6078f907e8b7fd7.tar.bz2
chat-a1ec47eb780f6d244d1d3d50e6078f907e8b7fd7.zip
Merge pull request #2388 from mattermost/plt-1789
PLT-1789 Deleting posts with files now renames the file so that public links t…
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go18
1 files changed, 18 insertions, 0 deletions
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)
}