add ability to delete posts
This commit is contained in:
@ -8,7 +8,7 @@ local util = require("util")
|
||||
local models = require("models")
|
||||
local Posts = models.Posts
|
||||
local Threads = models.Threads
|
||||
|
||||
local PostHistory = models.PostHistory
|
||||
|
||||
app:get("single_post", "/:post_id", function(self)
|
||||
local query = constants.FULL_POSTS_QUERY .. "WHERE posts.id = ?"
|
||||
@ -22,6 +22,33 @@ app:get("single_post", "/:post_id", function(self)
|
||||
return {render = "post.single-post"}
|
||||
end)
|
||||
|
||||
app:post("delete_post", "/:post_id/delete", function(self)
|
||||
local user = util.get_logged_in_user(self)
|
||||
if not user then
|
||||
return {redirect_to = self:url_for"all_topics"}
|
||||
end
|
||||
print("id is " .. self.params.post_id)
|
||||
local post = Posts:find({id = self.params.post_id})
|
||||
if not post then
|
||||
return {redirect_to = self:url_for"all_topics"}
|
||||
end
|
||||
|
||||
local thread = Threads:find({id = post.thread_id})
|
||||
if user:is_mod() then
|
||||
post:delete()
|
||||
util.inject_infobox(self, "Post deleted.")
|
||||
return {redirect_to = self:url_for("thread", {slug = thread.slug})}
|
||||
end
|
||||
|
||||
if post.user_id ~= user.id then
|
||||
return {redirect_to = self:url_for"all_topics"}
|
||||
end
|
||||
|
||||
post:delete()
|
||||
util.inject_infobox(self, "Post deleted.")
|
||||
return {redirect_to = self:url_for("thread", {slug = thread.slug})}
|
||||
end)
|
||||
|
||||
app:get("edit_post", "/:post_id/edit", function(self)
|
||||
local user = util.get_logged_in_user(self)
|
||||
if not user then
|
||||
@ -74,4 +101,4 @@ app:post("edit_post", "/:post_id/edit", function(self)
|
||||
return {redirect_to = link}
|
||||
end)
|
||||
|
||||
return app
|
||||
return app
|
||||
|
Reference in New Issue
Block a user